Added logging, changed some directory structure

This commit is contained in:
2018-01-13 21:33:40 -05:00
parent f079a5f067
commit 8e72ffb917
73656 changed files with 35284 additions and 53718 deletions

View 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

View 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.

View File

@@ -0,0 +1,71 @@
# reduce-function-call [![Build Status](https://travis-ci.org/MoOx/reduce-function-call.png)](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)

View 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)
}

View File

@@ -0,0 +1,5 @@
test
.gitignore
.travis.yml
Makefile
example.js

View File

@@ -0,0 +1,21 @@
(MIT)
Copyright (c) 2013 Julian Gruber <julian@juliangruber.com>
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.

View File

@@ -0,0 +1,91 @@
# balanced-match
Match balanced string pairs, like `{` and `}` or `<b>` and `</b>`. Supports regular expressions as well!
[![build status](https://secure.travis-ci.org/juliangruber/balanced-match.svg)](http://travis-ci.org/juliangruber/balanced-match)
[![downloads](https://img.shields.io/npm/dm/balanced-match.svg)](https://www.npmjs.org/package/balanced-match)
[![testling badge](https://ci.testling.com/juliangruber/balanced-match.png)](https://ci.testling.com/juliangruber/balanced-match)
## Example
Get the first matching pair of braces:
```js
var balanced = require('balanced-match');
console.log(balanced('{', '}', 'pre{in{nested}}post'));
console.log(balanced('{', '}', 'pre{first}between{second}post'));
console.log(balanced(/\s+\{\s+/, /\s+\}\s+/, 'pre { in{nest} } post'));
```
The matches are:
```bash
$ node example.js
{ start: 3, end: 14, pre: 'pre', body: 'in{nested}', post: 'post' }
{ start: 3,
end: 9,
pre: 'pre',
body: 'first',
post: 'between{second}post' }
{ start: 3, end: 17, pre: 'pre', body: 'in{nest}', post: 'post' }
```
## API
### var m = balanced(a, b, str)
For the first non-nested matching pair of `a` and `b` in `str`, return an
object with those keys:
* **start** the index of the first match of `a`
* **end** the index of the matching `b`
* **pre** the preamble, `a` and `b` not included
* **body** the match, `a` and `b` not included
* **post** the postscript, `a` and `b` not included
If there's no match, `undefined` will be returned.
If the `str` contains more `a` than `b` / there are unmatched pairs, the first match that was closed will be used. For example, `{{a}` will match `['{', 'a', '']` and `{a}}` will match `['', 'a', '}']`.
### var r = balanced.range(a, b, str)
For the first non-nested matching pair of `a` and `b` in `str`, return an
array with indexes: `[ <a index>, <b index> ]`.
If there's no match, `undefined` will be returned.
If the `str` contains more `a` than `b` / there are unmatched pairs, the first match that was closed will be used. For example, `{{a}` will match `[ 1, 3 ]` and `{a}}` will match `[0, 2]`.
## Installation
With [npm](https://npmjs.org) do:
```bash
npm install balanced-match
```
## License
(MIT)
Copyright (c) 2013 Julian Gruber &lt;julian@juliangruber.com&gt;
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.

View File

@@ -0,0 +1,58 @@
module.exports = balanced;
function balanced(a, b, str) {
if (a instanceof RegExp) a = maybeMatch(a, str);
if (b instanceof RegExp) b = maybeMatch(b, str);
var r = range(a, b, str);
return r && {
start: r[0],
end: r[1],
pre: str.slice(0, r[0]),
body: str.slice(r[0] + a.length, r[1]),
post: str.slice(r[1] + b.length)
};
}
function maybeMatch(reg, str) {
var m = str.match(reg);
return m ? m[0] : null;
}
balanced.range = range;
function range(a, b, str) {
var begs, beg, left, right, result;
var ai = str.indexOf(a);
var bi = str.indexOf(b, ai + 1);
var i = ai;
if (ai >= 0 && bi > 0) {
begs = [];
left = str.length;
while (i >= 0 && !result) {
if (i == ai) {
begs.push(i);
ai = str.indexOf(a, i + 1);
} else if (begs.length == 1) {
result = [ begs.pop(), bi ];
} else {
beg = begs.pop();
if (beg < left) {
left = beg;
right = bi;
}
bi = str.indexOf(b, i + 1);
}
i = ai < bi && ai >= 0 ? ai : bi;
}
if (begs.length) {
result = [ left, right ];
}
}
return result;
}

View File

@@ -0,0 +1,78 @@
{
"_args": [
[
"balanced-match@0.4.2",
"C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project"
]
],
"_from": "balanced-match@0.4.2",
"_id": "balanced-match@0.4.2",
"_inBundle": false,
"_integrity": "sha1-yz8+PHMtwPAe5wtAPzAuYddwmDg=",
"_location": "/react-scripts/reduce-function-call/balanced-match",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "balanced-match@0.4.2",
"name": "balanced-match",
"escapedName": "balanced-match",
"rawSpec": "0.4.2",
"saveSpec": null,
"fetchSpec": "0.4.2"
},
"_requiredBy": [
"/react-scripts/reduce-function-call"
],
"_resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-0.4.2.tgz",
"_spec": "0.4.2",
"_where": "C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project",
"author": {
"name": "Julian Gruber",
"email": "mail@juliangruber.com",
"url": "http://juliangruber.com"
},
"bugs": {
"url": "https://github.com/juliangruber/balanced-match/issues"
},
"dependencies": {},
"description": "Match balanced character pairs, like \"{\" and \"}\"",
"devDependencies": {
"tape": "^4.6.0"
},
"homepage": "https://github.com/juliangruber/balanced-match",
"keywords": [
"match",
"regexp",
"test",
"balanced",
"parse"
],
"license": "MIT",
"main": "index.js",
"name": "balanced-match",
"repository": {
"type": "git",
"url": "git://github.com/juliangruber/balanced-match.git"
},
"scripts": {
"test": "make test"
},
"testling": {
"files": "test/*.js",
"browsers": [
"ie/8..latest",
"firefox/20..latest",
"firefox/nightly",
"chrome/25..latest",
"chrome/canary",
"opera/12..latest",
"opera/next",
"safari/5.1..latest",
"ipad/6.0..latest",
"iphone/6.0..latest",
"android-browser/4.2..latest"
]
},
"version": "0.4.2"
}

View File

@@ -0,0 +1,77 @@
{
"_args": [
[
"reduce-function-call@1.0.2",
"C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project"
]
],
"_from": "reduce-function-call@1.0.2",
"_id": "reduce-function-call@1.0.2",
"_inBundle": false,
"_integrity": "sha1-WiAL+S4ON3UXUv5FsKszD9S2vpk=",
"_location": "/react-scripts/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": [
"/react-scripts/reduce-css-calc"
],
"_resolved": "https://registry.npmjs.org/reduce-function-call/-/reduce-function-call-1.0.2.tgz",
"_spec": "1.0.2",
"_where": "C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project",
"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"
}