node-sass-functions-json
JSON encode and decode functions for node-sass.
Install
npm install node-sass-functions-json --save
Usage
const sass = ;const jsonFunctions = ; sass;
Module exports object with prepared functions json-encode
and json-decode
.
If you need functions as separate entities, they are available as static properties encode
and decode
.
Encode
Input:
;; body
Output:
];,")","
Decode
Input:
;; ;;
Output:
DEBUG: 1, 2, 3, 4, 5, 6, DEBUG:
API
json-encode(data, quotes)
Returns: sass.types.String
Encodes (JSON.stringify
) data
and returns Sass string.
By default, string is quoted with single quotes so that it can be easily used in standard CSS values.
-
Sass lists are transformed to arrays.
-
Sass maps are transformed to objects.
-
Sass colors are transformed to
rgba()
syntax if they have alpha value, otherwise they are transformed to hex value (and it’s shorther version if possible). -
Sass strings are transformed to strings
-
Sass numbers are transformed to numbers.
-
Sass null values and anything unresolved is transformed to null values.
data
Type: sass.types.*
Data to encode (stringify).
quotes
Type: Boolean|sass.types.Boolean
Default: true
Should output string be quoted with single quotes.
json-decode(data)
Returns: sass.types.*
Decodes (JSON.parse
) string
and returns one of available Sass types.
-
Arrays are transformed to Sass lists.
-
Objects are transformed to Sass maps.
-
Anything properly parsed with parse-color is transformed to Sass color.
-
Strings are transformed to Sass numbers with units if they can be properly parsed with parse-css-dimension, otherwise they are transformed to Sass strings.
-
Numbers are transformed to Sass numbers.
-
Null values and anything unresolved is transformed to Sass null values.
data
Type: sass.types.String|sass.types.Number|sass.types.Boolean|sass.types.Null
String to decode (parse).
Related
- node-sass-json-functions - Thanks for inspiration.
Contribution
Feel free to push your code if you agree with publishing under the MIT license.