first commit
This commit is contained in:
12
build/node_modules/reduce-function-call/CHANGELOG.md
generated
vendored
Executable file
12
build/node_modules/reduce-function-call/CHANGELOG.md
generated
vendored
Executable file
@@ -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
|
||||
20
build/node_modules/reduce-function-call/LICENSE
generated
vendored
Executable file
20
build/node_modules/reduce-function-call/LICENSE
generated
vendored
Executable file
@@ -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.
|
||||
71
build/node_modules/reduce-function-call/README.md
generated
vendored
Executable file
71
build/node_modules/reduce-function-call/README.md
generated
vendored
Executable file
@@ -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)
|
||||
74
build/node_modules/reduce-function-call/index.js
generated
vendored
Executable file
74
build/node_modules/reduce-function-call/index.js
generated
vendored
Executable file
@@ -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)
|
||||
}
|
||||
77
build/node_modules/reduce-function-call/package.json
generated
vendored
Executable file
77
build/node_modules/reduce-function-call/package.json
generated
vendored
Executable file
@@ -0,0 +1,77 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"reduce-function-call@1.0.2",
|
||||
"/Users/asciidisco/Desktop/asciidisco.com/build"
|
||||
]
|
||||
],
|
||||
"_from": "reduce-function-call@1.0.2",
|
||||
"_id": "reduce-function-call@1.0.2",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-WiAL+S4ON3UXUv5FsKszD9S2vpk=",
|
||||
"_location": "/reduce-function-call",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "reduce-function-call@1.0.2",
|
||||
"name": "reduce-function-call",
|
||||
"escapedName": "reduce-function-call",
|
||||
"rawSpec": "1.0.2",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "1.0.2"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/reduce-css-calc"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/reduce-function-call/-/reduce-function-call-1.0.2.tgz",
|
||||
"_spec": "1.0.2",
|
||||
"_where": "/Users/asciidisco/Desktop/asciidisco.com/build",
|
||||
"author": {
|
||||
"name": "MoOx"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/MoOx/reduce-function-call/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"balanced-match": "^0.4.2"
|
||||
},
|
||||
"description": "Reduce function calls in a string, using a callback",
|
||||
"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"
|
||||
},
|
||||
"files": [
|
||||
"CHANGELOG.md",
|
||||
"LICENSE",
|
||||
"README.md",
|
||||
"index.js"
|
||||
],
|
||||
"homepage": "https://github.com/MoOx/reduce-function-call#readme",
|
||||
"keywords": [
|
||||
"string",
|
||||
"reduce",
|
||||
"replacement",
|
||||
"function",
|
||||
"call",
|
||||
"eval",
|
||||
"interpret"
|
||||
],
|
||||
"license": "MIT",
|
||||
"name": "reduce-function-call",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/MoOx/reduce-function-call.git"
|
||||
},
|
||||
"scripts": {
|
||||
"jscs": "jscs *.js **/*.js",
|
||||
"jshint": "jshint . --exclude node_modules --reporter node_modules/jshint-stylish/index.js",
|
||||
"release": "npmpub",
|
||||
"test": "npm run jscs && npm run jshint && tape test | tap-colorize"
|
||||
},
|
||||
"version": "1.0.2"
|
||||
}
|
||||
Reference in New Issue
Block a user