diff options
| author | ruki <waruqi@gmail.com> | 2018-11-08 00:38:48 +0800 |
|---|---|---|
| committer | ruki <waruqi@gmail.com> | 2018-11-07 21:53:09 +0800 |
| commit | 26105034da4fcce7ac883c899d781f016559310d (patch) | |
| tree | c459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/reduce-function-call | |
| parent | 2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff) | |
| download | xmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip | |
switch to vuepress
Diffstat (limited to 'node_modules/reduce-function-call')
| -rwxr-xr-x | node_modules/reduce-function-call/CHANGELOG.md | 12 | ||||
| -rwxr-xr-x | node_modules/reduce-function-call/LICENSE | 20 | ||||
| -rwxr-xr-x | node_modules/reduce-function-call/README.md | 71 | ||||
| -rwxr-xr-x | node_modules/reduce-function-call/index.js | 74 | ||||
| -rwxr-xr-x | node_modules/reduce-function-call/package.json | 43 |
5 files changed, 220 insertions, 0 deletions
diff --git a/node_modules/reduce-function-call/CHANGELOG.md b/node_modules/reduce-function-call/CHANGELOG.md new file mode 100755 index 00000000..aa2e88b0 --- /dev/null +++ b/node_modules/reduce-function-call/CHANGELOG.md @@ -0,0 +1,12 @@ +# 1.0.2 - 2016-11-28 + +- Bump `balanced-match` dependency version +([postcss-cssnext/#327](https://github.com/MoOx/postcss-cssnext/issues/327) - @wtgtybhertgeghgtwtg). + +# 1.0.1 - 2014-08-06 + +* Fix issue with regex and nested call + +# 1.0.0 - 2014-08-06 + +First release diff --git a/node_modules/reduce-function-call/LICENSE b/node_modules/reduce-function-call/LICENSE new file mode 100755 index 00000000..9abe4f54 --- /dev/null +++ b/node_modules/reduce-function-call/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2014 "MoOx" Maxime Thirouin + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/reduce-function-call/README.md b/node_modules/reduce-function-call/README.md new file mode 100755 index 00000000..cc3dac9a --- /dev/null +++ b/node_modules/reduce-function-call/README.md @@ -0,0 +1,71 @@ +# reduce-function-call [](https://travis-ci.org/MoOx/reduce-function-call) + +> Reduce function calls in a string, using a callback + +## Installation + +```bash +npm install reduce-function-call +``` + +## Usage + +```js +var reduceFunctionCall = require("reduce-function-call") + +reduceFunctionCall("foo(1)", "foo", function(body) { + // body === "1" + return parseInt(body, 10) + 1 +}) +// "2" + +var nothingOrUpper = function(body, functionIdentifier) { + // ignore empty value + if (body === "") { + return functionIdentifier + "()" + } + + return body.toUpperCase() +} + +reduceFunctionCall("bar()", "bar", nothingOrUpper) +// "bar()" + +reduceFunctionCall("upper(baz)", "upper", nothingOrUpper) +// "BAZ" + +reduceFunctionCall("math(math(2 + 2) * 4 + math(2 + 2)) and other things", "math", function(body, functionIdentifier, call) { + try { + return eval(body) + } + catch (e) { + return call + } +}) +// "20 and other things" + +reduceFunctionCall("sha bla blah() blaa bla() abla() aabla() blaaa()", /\b([a-z]?bla[a-z]?)\(/, function(body, functionIdentifier) { + if (functionIdentifier === "bla") { + return "ABRACADABRA" + } + return functionIdentifier.replace("bla", "!") +} +// "sha bla !h blaa ABRACADABRA a! aabla() blaaa()" +``` + +See [unit tests](test/index.js) for others examples. + +## Contributing + +Work on a branch, install dev-dependencies, respect coding style & run tests before submitting a bug fix or a feature. + +```bash +git clone https://github.com/MoOx/reduce-function-call.git +git checkout -b patch-1 +npm install +npm test +``` + +## [Changelog](CHANGELOG.md) + +## [License](LICENSE-MIT) diff --git a/node_modules/reduce-function-call/index.js b/node_modules/reduce-function-call/index.js new file mode 100755 index 00000000..c20effaa --- /dev/null +++ b/node_modules/reduce-function-call/index.js @@ -0,0 +1,74 @@ +/* + * Module dependencies + */ +var balanced = require("balanced-match") + +/** + * Expose `reduceFunctionCall` + * + * @type {Function} + */ +module.exports = reduceFunctionCall + +/** + * Walkthrough all expressions, evaluate them and insert them into the declaration + * + * @param {Array} expressions + * @param {Object} declaration + */ + +function reduceFunctionCall(string, functionRE, callback) { + var call = string + return getFunctionCalls(string, functionRE).reduce(function(string, obj) { + return string.replace(obj.functionIdentifier + "(" + obj.matches.body + ")", evalFunctionCall(obj.matches.body, obj.functionIdentifier, callback, call, functionRE)) + }, string) +} + +/** + * Parses expressions in a value + * + * @param {String} value + * @returns {Array} + * @api private + */ + +function getFunctionCalls(call, functionRE) { + var expressions = [] + + var fnRE = typeof functionRE === "string" ? new RegExp("\\b(" + functionRE + ")\\(") : functionRE + do { + var searchMatch = fnRE.exec(call) + if (!searchMatch) { + return expressions + } + if (searchMatch[1] === undefined) { + throw new Error("Missing the first couple of parenthesis to get the function identifier in " + functionRE) + } + var fn = searchMatch[1] + var startIndex = searchMatch.index + var matches = balanced("(", ")", call.substring(startIndex)) + + if (!matches || matches.start !== searchMatch[0].length - 1) { + throw new SyntaxError(fn + "(): missing closing ')' in the value '" + call + "'") + } + + expressions.push({matches: matches, functionIdentifier: fn}) + call = matches.post + } + while (fnRE.test(call)) + + return expressions +} + +/** + * Evaluates an expression + * + * @param {String} expression + * @returns {String} + * @api private + */ + +function evalFunctionCall (string, functionIdentifier, callback, call, functionRE) { + // allow recursivity + return callback(reduceFunctionCall(string, functionRE, callback), functionIdentifier, call) +} diff --git a/node_modules/reduce-function-call/package.json b/node_modules/reduce-function-call/package.json new file mode 100755 index 00000000..22564ff0 --- /dev/null +++ b/node_modules/reduce-function-call/package.json @@ -0,0 +1,43 @@ +{ + "name": "reduce-function-call", + "version": "1.0.2", + "description": "Reduce function calls in a string, using a callback", + "keywords": [ + "string", + "reduce", + "replacement", + "function", + "call", + "eval", + "interpret" + ], + "author": "MoOx", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/MoOx/reduce-function-call.git" + }, + "files": [ + "CHANGELOG.md", + "LICENSE", + "README.md", + "index.js" + ], + "dependencies": { + "balanced-match": "^0.4.2" + }, + "devDependencies": { + "jscs": "^2.0.0", + "jshint": "^2.8.0", + "jshint-stylish": "^2.0.1", + "npmpub": "^3.1.0", + "tap-colorize": "^1.2.0", + "tape": "^4.0.3" + }, + "scripts": { + "jscs": "jscs *.js **/*.js", + "jshint": "jshint . --exclude node_modules --reporter node_modules/jshint-stylish/index.js", + "test": "npm run jscs && npm run jshint && tape test | tap-colorize", + "release": "npmpub" + } +} |
