Skip to content

Commit 5ce4a86

Browse files
author
susantaChak
committed
commit1: all package updated and remove unwanted package babel packages changed and code pattern update and security issue fixes
1 parent 13cf611 commit 5ce4a86

12 files changed

+115
-134
lines changed

.babelrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["@babel/preset-env"]
3+
}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ build/Release
2828
node_modules
2929

3030
lib
31+
package-lock.json

Makefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ build: js
99
test: build
1010
$(MOCHA_CMD) lib/**/__tests__/*-test.js --require ./lib/test-init.js
1111

12-
js: $(LIB_JS) lib/bin/json-sass
12+
js: $(LIB_JS) lib/bin/json2scss
1313

1414
$(LIB_JS): lib/%.js: src/%.js
15-
mkdir -p $(dir $@) && $(BABEL_CMD) $< -o $@ --experimental
15+
mkdir -p $(dir $@) && $(BABEL_CMD) $< -o $@
1616

17-
lib/bin/json-sass:
18-
mkdir -p $(dir $@) && $(BABEL_CMD) src/bin/json-sass -o $@ --experimental
17+
lib/bin/json2scss:
18+
mkdir -p $(dir $@) && $(BABEL_CMD) src/bin/json2scss -o $@
1919

2020
clean:
2121
rm -rf lib/

README.md

+31-50
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,68 @@
1-
# json-sass
1+
# json2sass
22

33
Streamy module that transforms a JSON stream into scss syntax Sass.
44

5-
json-sass converts JSON objects into Sass maps, which are supported in Ruby Sass 3.3 and libsass 2.0.
5+
json2sass converts JSON objects into Sass maps, which are supported in Ruby Sass 3.3 and libsass 2.0.
66

77
```
8-
npm install json-sass
8+
npm install --save-dev json2sass
99
```
1010

1111
## Why?
1212

13-
So you can share values between your scripts and stylesheets without having to use something like [SassyJSON](https://github.com/HugoGiraudel/SassyJSON), which doesn't work with libsass.
13+
Firstly, you can share values between your scripts and stylesheets without having to use something like [SassyJSON](https://github.com/HugoGiraudel/SassyJSON), which doesn't work with libsass.
14+
This package it's not build from Scratch by me. But Thanks to [Andrew Clark](https://github.com/acdlite) .
15+
But jsonSass package isn't maintained from last 5+ years. As we use this package with all the vernabilities , we thought we would fix the issues and make it better.
1416

1517
## Examples
1618

1719
Example source file `theme.json`:
1820
```
1921
{
20-
"string": "I am a string",
21-
"boolean": true,
22-
"number": 1.23,
23-
"array": [1, 2, 3],
24-
"object": {
25-
"foo": "bar"
22+
"font-primary": "'Roboto'",
23+
"colors": {
24+
"primary": "#FFF200",
25+
"secondary": "#007BFF",
26+
"grey": "#ADADAD",
27+
"dark-grey": "#6F6F6F",
28+
"success": "#388E3C",
29+
"error": "#EF5350",
30+
"text-black": "#333333"
2631
}
27-
"null": null
2832
}
2933
3034
```
3135

32-
From the command-line:
33-
34-
```
35-
$ json-sass -i theme.json -o theme.scss -p "\$theme: "
36-
```
37-
3836
Output `theme.scss`:
3937

4038
```scss
41-
$theme: (
42-
string: I am a string,
43-
boolean: true,
44-
number: 1.23,
45-
array: (1, 2, 3),
46-
object: (
47-
foo: bar
48-
),
49-
null: null
39+
$variable:(
40+
font-primary: 'Muli',
41+
colors: (
42+
primary: #FFF200,
43+
secondary: #007BFF,
44+
grey: #ADADAD,
45+
dark-grey: #6F6F6F,
46+
success: #388E3C,
47+
error: #EF5350,
48+
text-black: #333333
49+
)
5050
);
5151
```
5252

53-
Or you can use the Node API:
53+
you can use the Node fs Module:
5454

5555
``` javascript
5656
var fs = require('fs');
57-
var jsonSass = require('json-sass');
57+
var jsonSass = require('json-to-sass');
5858

5959
fs.createReadStream('theme.json')
6060
.pipe(jsonSass({
61-
prefix: '$theme: ',
61+
prefix: '$variable: ',
6262
}))
6363
.pipe(fs.createWriteStream('theme.scss'));
6464
```
6565

66-
Or with gulp using [vinyl-source-stream](https://github.com/hughsk/vinyl-source-stream):
67-
68-
```javascript
69-
var gulp = require('gulp');
70-
var jsonSass = require('json-sass');
71-
var source = require('vinyl-source-stream');
72-
var rename = require('gulp-rename');
73-
74-
gulp.task('theme', function() {
75-
return fs.createReadStream('theme.json')
76-
.pipe(jsonSass({
77-
prefix: '$theme: ',
78-
}))
79-
.pipe(source('theme.json'))
80-
.pipe(rename('theme.scss'))
81-
.pipe(gulp.dest('./'));
82-
});
83-
```
84-
8566
You can also transform normal JavaScript values using the exposed utility function:
8667

8768
```javascript
@@ -103,6 +84,6 @@ Convert a normal JavaScript value to its string representation in Sass. Ignores
10384

10485
## License
10586

106-
MIT
87+
ISC
10788

108-
[Andrew Clark](http://twitter.com/acdlite)
89+
[AS Developers](https://github.com/AS-Devs)

package.json

+23-16
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,36 @@
11
{
2-
"name": "json-sass",
3-
"version": "1.3.5",
4-
"description": "Transform JSON into scss syntax Sass.",
5-
"main": "lib/jsonSass.js",
6-
"bin": "lib/bin/json-sass",
2+
"name": "json2scss-map",
3+
"version": "1.0.0",
4+
"description": "Covert JSON into scss map. Utility Tool for those who want there theme colors and font can be modified from json , but also use all the scss feature using scss varibles.",
5+
"main": "lib/json2scss.js",
6+
"bin": "lib/bin/json2scss",
77
"scripts": {
88
"test": "make test",
9-
"prepublish": "npm test"
9+
"prepare": "npm test"
1010
},
1111
"keywords": [
1212
"sass",
13-
"JSON"
13+
"JSON",
14+
"scss",
15+
"next",
16+
"dart-scss"
1417
],
15-
"author": "Andrew Clark <[email protected]>",
18+
"author": "AS Developers <[email protected]>",
19+
"repository": {
20+
"type": "git",
21+
"url": "https://github.com/AS-Devs/json2scss-map.git"
22+
},
1623
"license": "ISC",
1724
"dependencies": {
18-
"babel": "~4.1.0",
19-
"lodash": "~2.4.1",
20-
"lodash-node": "~2.4.1",
21-
"minimist": "~1.1.0",
22-
"object-assign": "~2.0.0",
23-
"through2": "~0.6.3"
25+
"lodash": "^4.17.15",
26+
"minimist": "^1.2.5",
27+
"through2": "^4.0.2"
2428
},
2529
"devDependencies": {
26-
"chai": "~1.9.2",
27-
"mocha": "~2.0.1"
30+
"@babel/cli": "^7.10.4",
31+
"@babel/core": "^7.10.4",
32+
"@babel/preset-env": "^7.10.4",
33+
"chai": "^4.2.0",
34+
"mocha": "^8.0.1"
2835
}
2936
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
import { expect } from 'chai';
4-
import jsToSassString from '../jsToSassString';
4+
import json2scssMap from '../json2scssMap';
55

66
function Foo() {
77
this.toString = function() {
@@ -11,34 +11,34 @@ function Foo() {
1111

1212
var foo = new Foo();
1313

14-
describe('JS to Sass', function() {
14+
describe('JSON to SCSS Map', function() {
1515
it('should handle strings', function() {
16-
expect(jsToSassString('foo')).to.equal('foo');
16+
expect(json2scssMap('foo')).to.equal('foo');
1717
});
1818

1919
it('should handle booleans', function() {
20-
expect(jsToSassString(true)).to.equal('true');
21-
expect(jsToSassString(false)).to.equal('false');
20+
expect(json2scssMap(true)).to.equal('true');
21+
expect(json2scssMap(false)).to.equal('false');
2222
});
2323

2424
it('should handle null', function() {
25-
expect(jsToSassString(null)).to.equal('null');
25+
expect(json2scssMap(null)).to.equal('null');
2626
});
2727

2828
it('should ignore undefined', function() {
29-
expect(jsToSassString(undefined)).to.be.undefined;
29+
expect(json2scssMap(undefined)).to.be.undefined;
3030
});
3131

3232
it('should ignore functions', function() {
33-
expect(jsToSassString(function() {})).to.be.undefined;
33+
expect(json2scssMap(function() {})).to.be.undefined;
3434
});
3535

3636
it ('should use value of `.toString()` for non-plain objects', function() {
37-
expect(jsToSassString(foo)).to.equal('bar');
37+
expect(json2scssMap(foo)).to.equal('bar');
3838
});
3939

4040
it('should convert arrays to lists', function() {
41-
expect(jsToSassString([1, 2, 3])).to.equal('(1, 2, 3)');
41+
expect(json2scssMap([1, 2, 3])).to.equal('(1, 2, 3)');
4242
});
4343

4444
it('should convert objects to maps, with indentation', function() {
@@ -49,6 +49,6 @@ describe('JS to Sass', function() {
4949
},
5050
};
5151

52-
expect(jsToSassString(obj)).to.equal('(\n foo: bar,\n bar: (\n baz: foo\n )\n)')
52+
expect(json2scssMap(obj)).to.equal('(\n foo: bar,\n bar: (\n baz: foo\n )\n)')
5353
})
5454
});

src/bin/json-sass src/bin/json2scss

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
'use strict';
44

5-
let jsonSass = require('../jsonSass');
5+
let json2scss = require('../json2scss');
66
let fs = require('fs');
77
let path = require('path');
88
let minimist = require('minimist');
@@ -19,7 +19,7 @@ let argv = minimist(process.argv.slice(2), {
1919
default: { i: '-', o: '-' }
2020
});
2121

22-
if (argv.help) return showHelp(0);
22+
if (argv.help) showHelp(0);
2323

2424
let input;
2525
if (argv.infile === '-') {
@@ -47,7 +47,7 @@ let opts = {};
4747
if (argv.prefix) opts.prefix = argv.prefix;
4848
if (argv.suffix) opts.suffix = argv.suffix;
4949

50-
input.pipe(jsonSass(opts)).pipe(output);
50+
input.pipe(json2scss(opts)).pipe(output);
5151

5252
function showHelp(code) {
5353
let r = fs.createReadStream(path.join(__dirname, '../../usage.txt'));

src/json2scss.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
3+
import json2scssMap from './json2scssMap';
4+
import through2 from 'through2';
5+
6+
let DEFAULTS = {
7+
prefix: '',
8+
suffix: ';',
9+
};
10+
11+
function json2scss(options) {
12+
let optionsGen = Object.assign({}, DEFAULTS, options);
13+
return through2(function(chunk, enc, callback) {
14+
let jsValue = JSON.parse(chunk);
15+
let sassString = json2scssMap(jsValue);
16+
sassString = optionsGen.prefix + sassString + optionsGen.suffix;
17+
this.push(sassString);
18+
callback();
19+
});
20+
}
21+
22+
module.exports = json2scss;
23+
export default json2scss;
24+
export { json2scssMap as convertJs };
+12-22
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use strict';
22

3-
import isPlainObject from 'lodash-node/modern/objects/isPlainObject';
3+
import { isPlainObject, isUndefined, isNull } from 'lodash';
44
let { isArray } = Array;
55

6-
function jsToSassString(value) {
6+
function json2scssMap(value) {
77

8-
function _jsToSassString(value, initialIndentLevel = 0) {
8+
function _json2scssMap(value, initialIndentLevel = 0) {
99
let indentLevel = initialIndentLevel;
1010

1111
switch (typeof value) {
@@ -25,9 +25,9 @@ function jsToSassString(value) {
2525
sassKeyValPairs = Object.keys(jsObj)
2626
.reduce((result, key) => {
2727
let jsVal = jsObj[key];
28-
let sassVal = _jsToSassString(jsVal, indentLevel);
28+
let sassVal = _json2scssMap(jsVal, indentLevel);
2929

30-
if (isNotUndefined(sassVal)) {
30+
if (!isUndefined(sassVal)) {
3131
result.push(`${key}: ${sassVal}`);
3232
}
3333

@@ -39,10 +39,10 @@ function jsToSassString(value) {
3939
return result;
4040
}
4141
else if (isArray(value)) {
42-
let sassVals = [
43-
for (v of value) if (isNotUndefined(v))
44-
_jsToSassString(v, indentLevel)
45-
];
42+
let sassVals = value.filter(v => {
43+
if(!isUndefined(v)) return _json2scssMap(v, indentLevel)
44+
})
45+
4646

4747
return '(' + sassVals.join(', ') + ')';
4848
}
@@ -53,19 +53,9 @@ function jsToSassString(value) {
5353
}
5454
}
5555

56-
return _jsToSassString(value);
56+
return _json2scssMap(value);
5757
}
5858

59-
function indentsToSpaces(indentCount) {
60-
return Array(indentCount + 1).join(' ');
61-
}
62-
63-
function isNull(value) {
64-
return value === null;
65-
}
66-
67-
function isNotUndefined(value) {
68-
return typeof value !== 'undefined';
69-
}
59+
const indentsToSpaces = (indentCount) => Array(indentCount + 1).join(' ');
7060

71-
export default jsToSassString;
61+
export default json2scssMap;

0 commit comments

Comments
 (0)