Comparing version 1.1.2 to 1.2.0
@@ -5,2 +5,9 @@ # Changelog | ||
## [1.2.0](https://github.com/body-builder/jsass/compare/v1.1.2...v1.2.0) (2019-12-04) | ||
### Features | ||
* **jsFunctionsToSass:** Automatic parameter resolution for Sass functions ([#5](https://github.com/body-builder/jsass/issues/5)) ([c4f61a2](https://github.com/body-builder/jsass/commit/c4f61a28ea3993b28a6247735fbc382bc3ad5cab)) | ||
### [1.1.2](https://github.com/body-builder/jsass/compare/v1.1.1...v1.1.2) (2019-11-15) | ||
@@ -7,0 +14,0 @@ |
@@ -17,2 +17,4 @@ "use strict"; | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
var kindOf = require('kind-of'); | ||
@@ -27,2 +29,12 @@ | ||
function () { | ||
_createClass(JSFunctionsToSass, null, [{ | ||
key: "getFunctionParams", | ||
// Credits to Jack Allan (https://stackoverflow.com/a/9924463/3111787) | ||
value: function getFunctionParams(func) { | ||
var fnStr = func.toString().replace(this.STRIP_COMMENTS, ''); | ||
var result = fnStr.slice(fnStr.indexOf('(') + 1, fnStr.indexOf(')')).match(this.PARAMETER_NAMES); | ||
return result || []; | ||
} | ||
}]); | ||
function JSFunctionsToSass() { | ||
@@ -47,5 +59,7 @@ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
/** | ||
* Parses the Sass function declaration string and returns the extracted information in an Object | ||
* @param key The Sass function declaration string (the `key` of the Sass `options.functions` object), eg: 'headings($from: 0, $to: 6)' | ||
* @returns {null|{name: string, args: string[], spreadArgs: number[]}} | ||
* Parses the Sass function signature and generates the parameter declaration block in it (only if even the parentheses are missing) | ||
* @param signature The Sass function signature string (the `key` of the Sass `options.functions` object), eg: 'headings($from: 0, $to: 6)' | ||
* @param fn | ||
* @returns {*} | ||
* @private | ||
*/ | ||
@@ -55,9 +69,41 @@ | ||
_createClass(JSFunctionsToSass, [{ | ||
key: "_createSassParameterBlock", | ||
value: function _createSassParameterBlock(signature, fn) { | ||
if (kindOf(signature) !== 'string') { | ||
throw new Error('JSFunctionsToSass - pass the Sass function signature to _createSassParameterBlock!'); | ||
} // Do not do anything if parameters are already defined (even if the parenthesis is empty - that may be a valid, intentional use-case) | ||
if (signature.indexOf('(') > -1 && signature.indexOf(')') > -1) { | ||
return signature; | ||
} | ||
var js_fn_params = this.constructor.getFunctionParams(fn); | ||
var sass_params; | ||
if (js_fn_params.length) { | ||
sass_params = js_fn_params.map(function (item) { | ||
return "$".concat(item); | ||
}).join(', '); | ||
} else { | ||
sass_params = '$arguments...'; | ||
} | ||
return "".concat(signature, "(").concat(sass_params, ")"); | ||
} | ||
/** | ||
* Parses the Sass function signature and returns the extracted information in an Object | ||
* @param signature The Sass function signature string (the `key` of the Sass `options.functions` object), eg: 'headings($from: 0, $to: 6)' | ||
* @returns {null|{name: string, args: string[], spreadArgs: number[]}} | ||
* @private | ||
*/ | ||
}, { | ||
key: "_getSassFunctionData", | ||
value: function _getSassFunctionData(key) { | ||
var matches = key.replace(')', '').split('('); // The name of the Sass function | ||
value: function _getSassFunctionData(signature) { | ||
var matches = signature.replace(')', '').split('('); // The name of the Sass function | ||
var name = matches[0]; // The list of the arguments | ||
var name = matches[0]; // The list of the parameters | ||
var args = matches[1].split(','); // The indexes of the arguments, which accepts spread content. This is important, as we also | ||
var args = matches[1].split(','); // The indexes of the parameters, which accepts spread content. This is important, as we also | ||
@@ -68,12 +114,7 @@ var spreadArgs = []; | ||
}); | ||
if (name) { | ||
return { | ||
name: name, | ||
args: args, | ||
spreadArgs: spreadArgs | ||
}; | ||
} else { | ||
return null; | ||
} | ||
return { | ||
name: name, | ||
args: args, | ||
spreadArgs: spreadArgs | ||
}; | ||
} | ||
@@ -93,5 +134,14 @@ /** | ||
} | ||
/** | ||
* @param signature The Sass function signature (the `key` of the Sass `options.functions` object), eg: 'headings($from: 0, $to: 6)' | ||
* @param fn The Javascript function to be called (the `value` of the Sass `options.functions` object) | ||
* @param args The Array of the arguments which has been applied to `fn` by Sass. These are the Sass type arguments | ||
* @param options Option overrides for the current JSFunctionsToSass instance | ||
* @returns {*} | ||
* @private | ||
*/ | ||
}, { | ||
key: "_wrapFunction", | ||
value: function _wrapFunction(sass_decl, fn) { | ||
value: function _wrapFunction(signature, fn) { | ||
var _this = this; | ||
@@ -102,6 +152,2 @@ | ||
if (kindOf(sass_decl) !== 'string') { | ||
throw new Error('JSFunctionsToSass - pass the Sass function declaration to wrapFunction!'); | ||
} | ||
if (kindOf(fn) !== 'function') { | ||
@@ -117,3 +163,3 @@ throw new Error('JSFunctionsToSass - pass a function to wrapFunction!'); | ||
var sassFunctionData = this._getSassFunctionData(sass_decl); // Sass' asynchronous `render()` provides an additional callback as the last argument, to which we can asynchronously pass the result of the function when it’s complete. | ||
var sassFunctionData = this._getSassFunctionData(signature); // Sass' asynchronous `render()` provides an additional callback as the last argument, to which we can asynchronously pass the result of the function when it’s complete. | ||
// We need to separate this callback from the Sass-type arguments. (`node-sass` provides a `CallbackBridge' type in synchronous mode, which we also need to separate from the Sass-type arguments.) | ||
@@ -134,3 +180,3 @@ | ||
sassTypeArgs.forEach(function (sassTypeArg, index) { | ||
var jsTypeArg = _this._sassVarsToJS._convert(sassTypeArg, options); // If the Sass function expects the data to be spread for the current argument, we spread the arguments also for the JS function. | ||
var jsTypeArg = _this._sassVarsToJS._convert(sassTypeArg, options); // If the Sass function expects the arguments to be spread for the current parameter, we spread the arguments also for the JS function. | ||
@@ -170,2 +216,9 @@ | ||
} | ||
/** | ||
* Processes the Object passed in Sass's `options.functions`. This is the main method, which will be called with the instance's `convert()` method. | ||
* @param obj The `functions` property of the Sass options, which contains the function signatures (see the Sass documentation in https://sass-lang.com/documentation/js-api#functions) | ||
* @param options Option overrides for the current JSFunctionsToSass instance | ||
* @private | ||
*/ | ||
}, { | ||
@@ -185,2 +238,4 @@ key: "_wrapObject", | ||
var signature = _this2._createSassParameterBlock(key, fn); | ||
if (kindOf(fn) !== 'function') { | ||
@@ -190,3 +245,3 @@ throw new Error('JSFunctionsToSass - pass a function to wrapObject!'); | ||
newObj[key] = function () { | ||
newObj[signature] = function () { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
@@ -196,3 +251,3 @@ args[_key] = arguments[_key]; | ||
return _this2._wrapFunction(key, fn, args, options); | ||
return _this2._wrapFunction(signature, fn, args, options); | ||
}; | ||
@@ -207,2 +262,6 @@ }); | ||
_defineProperty(JSFunctionsToSass, "STRIP_COMMENTS", /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm); | ||
_defineProperty(JSFunctionsToSass, "PARAMETER_NAMES", /([^\s,]+)/g); | ||
module.exports = JSFunctionsToSass; |
@@ -183,4 +183,4 @@ "use strict"; | ||
* Accepts two syntaxes: | ||
* - 3 parameters: key, value, [options] | ||
* - 2 parameters: { key: value }, [options] | ||
* - 3 arguments: key, value, [options] | ||
* - 2 arguments: { key: value }, [options] | ||
* | ||
@@ -187,0 +187,0 @@ * @param values |
{ | ||
"name": "jsass", | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"description": "Share functions and variables between JS and Sass", | ||
@@ -15,6 +15,7 @@ "homepage": "https://github.com/body-builder/jsass#readme", | ||
"scripts": { | ||
"peers": "npx npm-install-peers", | ||
"watch": "npx babel src --watch --out-dir dist", | ||
"build": "npx babel src --out-dir dist", | ||
"jasmine": "babel-node ./jasmine.run.js", | ||
"eslint": "eslint 'src/**/*.js'", | ||
"eslint": "eslint \"src/**/*.js\"", | ||
"test": "npm run eslint && npm run jasmine", | ||
@@ -37,2 +38,5 @@ "release": "standard-version --sign", | ||
], | ||
"engines": { | ||
"node": ">= 8.0.0" | ||
}, | ||
"dependencies": { | ||
@@ -43,14 +47,16 @@ "color-string": "^1.5.3", | ||
"peerDependencies": { | ||
"node-sass": "3 || 4" | ||
"node-sass": "^4.5.3", | ||
"sass": "^1.22.5" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.6.4", | ||
"@babel/core": "^7.6.4", | ||
"@babel/node": "^7.6.3", | ||
"@babel/plugin-transform-modules-commonjs": "^7.6.0", | ||
"@babel/preset-env": "^7.6.3", | ||
"@babel/cli": "^7.7.0", | ||
"@babel/core": "^7.7.2", | ||
"@babel/node": "^7.7.0", | ||
"@babel/plugin-proposal-class-properties": "^7.7.0", | ||
"@babel/plugin-transform-modules-commonjs": "^7.7.0", | ||
"@babel/preset-env": "^7.7.1", | ||
"babel-eslint": "^10.0.3", | ||
"css-loader": "^3.2.0", | ||
"eslint": "^6.5.1", | ||
"eslint-plugin-jasmine": "^2.10.1", | ||
"eslint": "^6.6.0", | ||
"eslint-plugin-jasmine": "^4.1.0", | ||
"eslint-plugin-prettier": "^3.1.1", | ||
@@ -61,5 +67,3 @@ "html-webpack-plugin": "^3.2.0", | ||
"lodash": "^4.17.15", | ||
"node-sass": "^4.12.0", | ||
"prettier": "^1.18.2", | ||
"sass": "^1.23.1", | ||
"sass-extract": "^2.1.0", | ||
@@ -71,5 +75,5 @@ "sass-extract-loader": "^1.1.0", | ||
"webpack": "^4.41.2", | ||
"webpack-cli": "^3.3.9", | ||
"webpack-dev-server": "^3.8.2" | ||
"webpack-cli": "^3.3.10", | ||
"webpack-dev-server": "^3.9.0" | ||
} | ||
} |
123
README.md
@@ -32,10 +32,103 @@ # jSass | ||
Since node-sass v3.0.0, the `functions` option makes it possible to pass an Object of JS functions that may be invoked by the sass files being compiled (check `node-sass` docs [here](https://github.com/sass/node-sass#functions--v300---experimental) for more information). | ||
Since Node Sass v3.0.0, and Dart Sass v1.0.0-beta.5.1 the `functions` option makes it possible to pass an Object of JS functions that may be invoked by the sass files being compiled (check [Node Sass docs](https://github.com/sass/node-sass#functions--v300---experimental) or [Dart Sass docs](https://sass-lang.com/documentation/js-api#functions) for more information). | ||
This gives the developers unlimited possibilities for processing Sass data during build-time, but since the connected JS functions receive their parameters and must return their return values in node-sass's own data types, this makes a bit more difficult to just use this feature *out-of-the-box*. | ||
This gives the developers unlimited possibilities for processing Sass data during build-time, but since the connected JS functions receive their parameters and must return their return values in Sass's own data types, this makes a bit more difficult to just use this feature *out-of-the-box*. | ||
This package contains a class (JSFunctionsToSass), which acts like a middleware between node-sass and the connected JS function. It converts the received node-sass type arguments to their JS equivalents, and applies them as pure JavaScript types to the connected JS function. When the function returned what it has to be, JSFunctionsToSass converts the returned JS value back to its node-sass equivalent, and passes back to node-sass. So simple. | ||
This package contains a class (JSFunctionsToSass), which acts like a middleware between Sass and the connected JS function. It converts the received Sass type arguments to their JS equivalents, and applies them as pure JavaScript types to the connected JS function. When the function returned what it has to be, JSFunctionsToSass converts the returned JS value back to its Sass equivalent, and passes back to Sass. So simple. | ||
Both **sync** and **async** functions are supported. | ||
#### Easy syntax | ||
JSFunctionsToSass makes it possible to automatically define the parameters of the Sass function. | ||
If the Sass function signature (the _keys_ of the Sass `options.functions` object) doesn't have a parameter block, it tries to get the parameter names of the JS function, and define the same parameter names also in the Sass function. If we cannot get the parameter names of the given JS function (most probably it doesn't have explicitly declared parameters), we add a single spread parameter for the Sass function (`$arguments...`), making it possible to wrap JS functions which use eg. `arguments` in their body. | ||
This functionality is limited only to Sass function signatures **without a parameter block** (parentheses immediately after the function's name). Sass functions _having_ defined parameters remain untouched, and the same applies if explicitly zero parameters are defined (when the parameter block is empty). | ||
**Note:** `JSFunctionsToSass` cannot detect (and therefore define) the _default values_ of the function parameters. If Sass throws error because of a missing (but only optional) argument, you can fall back anytime to the original Sass signature syntax. | ||
The automatic parameter resolution is completely optional and can be used in parallel with the original syntax. | ||
##### Default syntax | ||
```js | ||
const path = require('path'); | ||
const sass = require('node-sass'); | ||
const { JSFunctionsToSass } = require('jsass/dist/node'); | ||
const jsFunctionsToSass = new JSFunctionsToSass(); | ||
sass.render({ | ||
file: path.resolve('styles.scss'), | ||
functions: jsFunctionsToSass.convert({ | ||
// Explicitly defined Sass parameter names | ||
'str-replace($string, $search, $replace: "")': function str_replace(string, search, replace) { | ||
if (typeof string !== 'string') { | ||
throw new Error('str-replace needs `$string` to be typeof string!'); | ||
} | ||
return string.replace(new RegExp(search, 'g'), replace); | ||
} | ||
}) | ||
}, (err, result) => { | ||
if (err) { | ||
throw new Error(err); | ||
} | ||
console.log(result.css.toString()); | ||
}); | ||
``` | ||
##### Easier syntax | ||
```js | ||
const path = require('path'); | ||
const sass = require('node-sass'); | ||
const { JSFunctionsToSass } = require('jsass/dist/node'); | ||
const jsFunctionsToSass = new JSFunctionsToSass(); | ||
sass.render({ | ||
file: path.resolve('styles.scss'), | ||
functions: jsFunctionsToSass.convert({ | ||
// Sass parameter names resolved from the JS function | ||
str_replace: function str_replace(string, search, replace) { | ||
if (typeof string !== 'string') { | ||
throw new Error('str-replace needs `$string` to be typeof string!'); | ||
} | ||
return string.replace(new RegExp(search, 'g'), replace); | ||
} | ||
}) | ||
}, (err, result) => { | ||
if (err) { | ||
throw new Error(err); | ||
} | ||
console.log(result.css.toString()); | ||
}); | ||
``` | ||
##### Syntax sugar | ||
```js | ||
const path = require('path'); | ||
const sass = require('node-sass'); | ||
const { JSFunctionsToSass } = require('jsass/dist/node'); | ||
const jsFunctionsToSass = new JSFunctionsToSass(); | ||
const str_replace = require('./str_replace'); | ||
sass.render({ | ||
file: path.resolve('styles.scss'), | ||
functions: jsFunctionsToSass.convert({ | ||
// Passing only a JS function reference | ||
str_replace | ||
}) | ||
}, (err, result) => { | ||
if (err) { | ||
throw new Error(err); | ||
} | ||
console.log(result.css.toString()); | ||
}); | ||
``` | ||
#### Examples | ||
@@ -56,3 +149,3 @@ ##### Implementing missing in Sass `str-replace` function | ||
functions: jsFunctionsToSass.convert({ | ||
'str-replace($string, $search, $replace: "")': function (string, search, replace) { | ||
'str-replace': function (string, search, replace) { | ||
if (typeof string !== 'string') { | ||
@@ -99,4 +192,5 @@ throw new Error('str-replace needs `$string` to be typeof string!'); | ||
const path = require('path'); | ||
const sass = require('sass'); // Now we are using `dart-sass` | ||
const { JSFunctionsToSass } = require('jsass/dist/node'); | ||
const jsFunctionsToSass = new JSFunctionsToSass(); | ||
const jsFunctionsToSass = new JSFunctionsToSass({ implementation: sass }); | ||
@@ -109,3 +203,2 @@ const _ = require('lodash'); | ||
sass.render({ | ||
implementation: require('sass'), // Now we are using `dart-sass` | ||
file: path.resolve(__dirname, './map-get-super.scss'), | ||
@@ -116,2 +209,6 @@ functions: jsFunctionsToSass.convert({ | ||
}, (err, result) => { | ||
if (err) { | ||
throw new Error(err); | ||
} | ||
console.log(result.css.toString()); | ||
@@ -147,3 +244,3 @@ }); | ||
##### It works also with spread arguments | ||
##### It works also with arbitrary (spread) arguments | ||
@@ -167,2 +264,6 @@ ```js | ||
}, (err, result) => { | ||
if (err) { | ||
throw new Error(err); | ||
} | ||
console.log(result.css.toString()); | ||
@@ -197,3 +298,3 @@ }); | ||
### Share JS variables with Sass | ||
Node-sass accepts a `data` option as the source code to compile (check `node-sass` docs [here](https://github.com/sass/node-sass#data)). This also makes it possible to pass for example Node.js variables to your Sass files. However, `data` must be a string, containing syntactically valid raw Sass code. jSass helps you to stringify any general JavaScript types to their equivalent Sass variable type to raw Sass format. It supports both SCSS and SASS (indented) syntax as output type. | ||
Sass accepts a `data` option as the source code to compile (check [Node Sass docs here](https://github.com/sass/node-sass#data) or [Dart Sass docs here](https://sass-lang.com/documentation/js-api#data)). This also makes it possible to pass for example Node.js variables to your Sass files. However, `data` must be a string, containing syntactically valid raw Sass code. jSass helps you to stringify any general JavaScript types to their equivalent Sass variable type to raw Sass format. It supports both SCSS and SASS (indented) syntax as output type. | ||
@@ -246,3 +347,3 @@ #### Example | ||
Use it in `node-sass`: | ||
Use it in Sass: | ||
```js | ||
@@ -289,2 +390,6 @@ const fs = require('fs'); | ||
}, (err, result) => { | ||
if (err) { | ||
throw new Error(err); | ||
} | ||
console.log(result.css.toString()); | ||
@@ -291,0 +396,0 @@ }); |
@@ -6,2 +6,13 @@ const kindOf = require('kind-of'); | ||
class JSFunctionsToSass { | ||
// Credits to Jack Allan (https://stackoverflow.com/a/9924463/3111787) | ||
static STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm; | ||
static PARAMETER_NAMES = /([^\s,]+)/g; | ||
static getFunctionParams(func) { | ||
const fnStr = func.toString().replace(this.STRIP_COMMENTS, ''); | ||
const result = fnStr.slice(fnStr.indexOf('(') + 1, fnStr.indexOf(')')).match(this.PARAMETER_NAMES); | ||
return result || []; | ||
} | ||
constructor(options = {}) { | ||
@@ -23,8 +34,38 @@ this._default_options = { | ||
/** | ||
* Parses the Sass function declaration string and returns the extracted information in an Object | ||
* @param key The Sass function declaration string (the `key` of the Sass `options.functions` object), eg: 'headings($from: 0, $to: 6)' | ||
* Parses the Sass function signature and generates the parameter declaration block in it (only if even the parentheses are missing) | ||
* @param signature The Sass function signature string (the `key` of the Sass `options.functions` object), eg: 'headings($from: 0, $to: 6)' | ||
* @param fn | ||
* @returns {*} | ||
* @private | ||
*/ | ||
_createSassParameterBlock(signature, fn) { | ||
if (kindOf(signature) !== 'string') { | ||
throw new Error('JSFunctionsToSass - pass the Sass function signature to _createSassParameterBlock!'); | ||
} | ||
// Do not do anything if parameters are already defined (even if the parenthesis is empty - that may be a valid, intentional use-case) | ||
if (signature.indexOf('(') > -1 && signature.indexOf(')') > -1) { | ||
return signature; | ||
} | ||
const js_fn_params = this.constructor.getFunctionParams(fn); | ||
let sass_params; | ||
if (js_fn_params.length) { | ||
sass_params = js_fn_params.map((item) => `$${item}`).join(', '); | ||
} else { | ||
sass_params = '$arguments...'; | ||
} | ||
return `${signature}(${sass_params})`; | ||
} | ||
/** | ||
* Parses the Sass function signature and returns the extracted information in an Object | ||
* @param signature The Sass function signature string (the `key` of the Sass `options.functions` object), eg: 'headings($from: 0, $to: 6)' | ||
* @returns {null|{name: string, args: string[], spreadArgs: number[]}} | ||
* @private | ||
*/ | ||
_getSassFunctionData(key) { | ||
const matches = key.replace(')', '').split('('); | ||
_getSassFunctionData(signature) { | ||
const matches = signature.replace(')', '').split('('); | ||
@@ -34,18 +75,14 @@ // The name of the Sass function | ||
// The list of the arguments | ||
// The list of the parameters | ||
const args = matches[1].split(','); | ||
// The indexes of the arguments, which accepts spread content. This is important, as we also | ||
// The indexes of the parameters, which accepts spread content. This is important, as we also | ||
const spreadArgs = []; | ||
args.forEach((arg, index) => arg.endsWith('...') && spreadArgs.push(index)); | ||
if (name) { | ||
return { | ||
name, | ||
args, | ||
spreadArgs | ||
}; | ||
} else { | ||
return null; | ||
} | ||
return { | ||
name, | ||
args, | ||
spreadArgs | ||
}; | ||
} | ||
@@ -64,7 +101,11 @@ | ||
_wrapFunction(sass_decl, fn, args = [], options) { | ||
if (kindOf(sass_decl) !== 'string') { | ||
throw new Error('JSFunctionsToSass - pass the Sass function declaration to wrapFunction!'); | ||
} | ||
/** | ||
* @param signature The Sass function signature (the `key` of the Sass `options.functions` object), eg: 'headings($from: 0, $to: 6)' | ||
* @param fn The Javascript function to be called (the `value` of the Sass `options.functions` object) | ||
* @param args The Array of the arguments which has been applied to `fn` by Sass. These are the Sass type arguments | ||
* @param options Option overrides for the current JSFunctionsToSass instance | ||
* @returns {*} | ||
* @private | ||
*/ | ||
_wrapFunction(signature, fn, args = [], options) { | ||
if (kindOf(fn) !== 'function') { | ||
@@ -80,3 +121,3 @@ throw new Error('JSFunctionsToSass - pass a function to wrapFunction!'); | ||
const sassFunctionData = this._getSassFunctionData(sass_decl); | ||
const sassFunctionData = this._getSassFunctionData(signature); | ||
@@ -99,3 +140,3 @@ // Sass' asynchronous `render()` provides an additional callback as the last argument, to which we can asynchronously pass the result of the function when it’s complete. | ||
// If the Sass function expects the data to be spread for the current argument, we spread the arguments also for the JS function. | ||
// If the Sass function expects the arguments to be spread for the current parameter, we spread the arguments also for the JS function. | ||
if (kindOf(jsTypeArg) === 'array' && sassFunctionData.spreadArgs.indexOf(index) !== -1) { | ||
@@ -132,2 +173,8 @@ jsTypeArgs.push(...jsTypeArg); | ||
/** | ||
* Processes the Object passed in Sass's `options.functions`. This is the main method, which will be called with the instance's `convert()` method. | ||
* @param obj The `functions` property of the Sass options, which contains the function signatures (see the Sass documentation in https://sass-lang.com/documentation/js-api#functions) | ||
* @param options Option overrides for the current JSFunctionsToSass instance | ||
* @private | ||
*/ | ||
_wrapObject(obj, options) { | ||
@@ -145,2 +192,4 @@ if (kindOf(obj) !== 'object') { | ||
const signature = this._createSassParameterBlock(key, fn); | ||
if (kindOf(fn) !== 'function') { | ||
@@ -150,3 +199,3 @@ throw new Error('JSFunctionsToSass - pass a function to wrapObject!'); | ||
newObj[key] = (...args) => this._wrapFunction(key, fn, args, options); | ||
newObj[signature] = (...args) => this._wrapFunction(signature, fn, args, options); | ||
}); | ||
@@ -153,0 +202,0 @@ |
@@ -135,4 +135,4 @@ const kindOf = require('kind-of'); | ||
* Accepts two syntaxes: | ||
* - 3 parameters: key, value, [options] | ||
* - 2 parameters: { key: value }, [options] | ||
* - 3 arguments: key, value, [options] | ||
* - 2 arguments: { key: value }, [options] | ||
* | ||
@@ -139,0 +139,0 @@ * @param values |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
89637
24
1717
464
4