initial
This commit is contained in:
8
node_modules/find-replace/.travis.yml
generated
vendored
Normal file
8
node_modules/find-replace/.travis.yml
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- 9
|
||||
- 8
|
||||
- 7
|
||||
- 6
|
||||
- 5
|
||||
- 4
|
21
node_modules/find-replace/LICENSE
generated
vendored
Normal file
21
node_modules/find-replace/LICENSE
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015-18 Lloyd Brookes <75pound@gmail.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.
|
42
node_modules/find-replace/README.md
generated
vendored
Normal file
42
node_modules/find-replace/README.md
generated
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
[](https://www.npmjs.org/package/find-replace)
|
||||
[](https://www.npmjs.org/package/find-replace)
|
||||
[](https://travis-ci.org/75lb/find-replace)
|
||||
[](https://david-dm.org/75lb/find-replace)
|
||||
[](https://github.com/feross/standard)
|
||||
|
||||
<a name="module_find-replace"></a>
|
||||
|
||||
## find-replace
|
||||
Find and either replace or remove items from an array.
|
||||
|
||||
**Example**
|
||||
```js
|
||||
> findReplace = require('find-replace')
|
||||
|
||||
> findReplace([ 1, 2, 3], 2, 'two')
|
||||
[ 1, 'two', 3 ]
|
||||
|
||||
> findReplace([ 1, 2, 3], 2, [ 'two', 'zwei' ])
|
||||
[ 1, [ 'two', 'zwei' ], 3 ]
|
||||
|
||||
> findReplace([ 1, 2, 3], 2, 'two', 'zwei')
|
||||
[ 1, 'two', 'zwei', 3 ]
|
||||
|
||||
> findReplace([ 1, 2, 3], 2) // no replacement, so remove
|
||||
[ 1, 3 ]
|
||||
```
|
||||
<a name="exp_module_find-replace--findReplace"></a>
|
||||
|
||||
### findReplace(array, valueTest, [...replaceWith]) ⇒ <code>array</code> ⏏
|
||||
**Kind**: Exported function
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| array | <code>array</code> | the input array |
|
||||
| valueTest | <code>valueTest</code> | a [test-value](https://github.com/75lb/test-value) query to match the value you're looking for |
|
||||
| [...replaceWith] | <code>any</code> | If specified, found values will be replaced with these values, else removed. |
|
||||
|
||||
|
||||
* * *
|
||||
|
||||
© 2015-18 Lloyd Brookes \<75pound@gmail.com\>. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown).
|
11
node_modules/find-replace/jsdoc2md/README.hbs
generated
vendored
Normal file
11
node_modules/find-replace/jsdoc2md/README.hbs
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
[](https://www.npmjs.org/package/find-replace)
|
||||
[](https://www.npmjs.org/package/find-replace)
|
||||
[](https://travis-ci.org/75lb/find-replace)
|
||||
[](https://david-dm.org/75lb/find-replace)
|
||||
[](https://github.com/feross/standard)
|
||||
|
||||
{{>main}}
|
||||
|
||||
* * *
|
||||
|
||||
© 2015-18 Lloyd Brookes \<75pound@gmail.com\>. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown).
|
62
node_modules/find-replace/lib/find-replace.js
generated
vendored
Normal file
62
node_modules/find-replace/lib/find-replace.js
generated
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
'use strict'
|
||||
const arrayify = require('array-back')
|
||||
const testValue = require('test-value')
|
||||
|
||||
/**
|
||||
* Find and either replace or remove items from an array.
|
||||
*
|
||||
* @module find-replace
|
||||
* @example
|
||||
* > findReplace = require('find-replace')
|
||||
*
|
||||
* > findReplace([ 1, 2, 3], 2, 'two')
|
||||
* [ 1, 'two', 3 ]
|
||||
*
|
||||
* > findReplace([ 1, 2, 3], 2, [ 'two', 'zwei' ])
|
||||
* [ 1, [ 'two', 'zwei' ], 3 ]
|
||||
*
|
||||
* > findReplace([ 1, 2, 3], 2, 'two', 'zwei')
|
||||
* [ 1, 'two', 'zwei', 3 ]
|
||||
*
|
||||
* > findReplace([ 1, 2, 3], 2) // no replacement, so remove
|
||||
* [ 1, 3 ]
|
||||
*/
|
||||
module.exports = findReplace
|
||||
|
||||
/**
|
||||
* @param {array} - the input array
|
||||
* @param {valueTest} - a [test-value](https://github.com/75lb/test-value) query to match the value you're looking for
|
||||
* @param [replaceWith] {...any} - If specified, found values will be replaced with these values, else removed.
|
||||
* @returns {array}
|
||||
* @alias module:find-replace
|
||||
*/
|
||||
function findReplace (array, valueTest) {
|
||||
const found = []
|
||||
const replaceWiths = arrayify(arguments)
|
||||
replaceWiths.splice(0, 2)
|
||||
|
||||
arrayify(array).forEach((value, index) => {
|
||||
let expanded = []
|
||||
replaceWiths.forEach(replaceWith => {
|
||||
if (typeof replaceWith === 'function') {
|
||||
expanded = expanded.concat(replaceWith(value))
|
||||
} else {
|
||||
expanded.push(replaceWith)
|
||||
}
|
||||
})
|
||||
|
||||
if (testValue(value, valueTest)) {
|
||||
found.push({
|
||||
index: index,
|
||||
replaceWithValue: expanded
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
found.reverse().forEach(item => {
|
||||
const spliceArgs = [ item.index, 1 ].concat(item.replaceWithValue)
|
||||
array.splice.apply(array, spliceArgs)
|
||||
})
|
||||
|
||||
return array
|
||||
}
|
67
node_modules/find-replace/package.json
generated
vendored
Normal file
67
node_modules/find-replace/package.json
generated
vendored
Normal file
@ -0,0 +1,67 @@
|
||||
{
|
||||
"_from": "find-replace@^2.0.1",
|
||||
"_id": "find-replace@2.0.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-LzDo3Fpa30FLIBsh6DCDnMN1KW2g4QKkqKmejlImgWY67dDFPX/x9Kh/op/GK522DchQXEvDi/wD48HKW49XOQ==",
|
||||
"_location": "/find-replace",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "find-replace@^2.0.1",
|
||||
"name": "find-replace",
|
||||
"escapedName": "find-replace",
|
||||
"rawSpec": "^2.0.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^2.0.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/argv-tools",
|
||||
"/command-line-args"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/find-replace/-/find-replace-2.0.1.tgz",
|
||||
"_shasum": "6d9683a7ca20f8f9aabeabad07e4e2580f528550",
|
||||
"_spec": "find-replace@^2.0.1",
|
||||
"_where": "/home/wn/workspace-node/PiAlive/node_modules/command-line-args",
|
||||
"author": {
|
||||
"name": "Lloyd Brookes",
|
||||
"email": "75pound@gmail.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/75lb/find-replace/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"array-back": "^2.0.0",
|
||||
"test-value": "^3.0.0"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Find and either replace or remove items from an array",
|
||||
"devDependencies": {
|
||||
"jsdoc-to-markdown": "^3.0.2",
|
||||
"test-runner": "^0.4.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4.0.0"
|
||||
},
|
||||
"homepage": "https://github.com/75lb/find-replace#readme",
|
||||
"keywords": [
|
||||
"find",
|
||||
"replace",
|
||||
"array",
|
||||
"remove",
|
||||
"splice"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "./lib/find-replace.js",
|
||||
"name": "find-replace",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/75lb/find-replace.git"
|
||||
},
|
||||
"scripts": {
|
||||
"docs": "jsdoc2md -t jsdoc2md/README.hbs lib/*.js > README.md; echo",
|
||||
"test": "test-runner test/*.js"
|
||||
},
|
||||
"version": "2.0.1"
|
||||
}
|
50
node_modules/find-replace/test/test.js
generated
vendored
Normal file
50
node_modules/find-replace/test/test.js
generated
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
'use strict'
|
||||
const TestRunner = require('test-runner')
|
||||
const findReplace = require('../')
|
||||
const a = require('assert')
|
||||
|
||||
const runner = new TestRunner()
|
||||
|
||||
function fixture () {
|
||||
return [ 1, 2, 3, 4, 2 ]
|
||||
}
|
||||
function argv () {
|
||||
return [ '--one', '1', '-abc', 'three' ]
|
||||
}
|
||||
|
||||
runner.test('find primitive, replace with primitive', function (t) {
|
||||
a.deepStrictEqual(
|
||||
findReplace(fixture(), 2, 'two'),
|
||||
[ 1, 'two', 3, 4, 'two' ]
|
||||
)
|
||||
})
|
||||
|
||||
runner.test('find primitive, replace with array', function (t) {
|
||||
a.deepStrictEqual(
|
||||
findReplace(fixture(), 2, [ 'two', 'zwei' ]),
|
||||
[ 1, [ 'two', 'zwei' ], 3, 4, [ 'two', 'zwei' ] ]
|
||||
)
|
||||
})
|
||||
|
||||
runner.test('find primitive, replace with several primitives', function (t) {
|
||||
a.deepStrictEqual(
|
||||
findReplace(fixture(), 2, 'two', 'zwei'),
|
||||
[ 1, 'two', 'zwei', 3, 4, 'two', 'zwei' ]
|
||||
)
|
||||
})
|
||||
|
||||
runner.test('getopt example', function (t) {
|
||||
a.deepStrictEqual(
|
||||
findReplace(argv(), /^-(\w{2,})$/, function (match) {
|
||||
return [ '-a', '-b', '-c' ]
|
||||
}),
|
||||
[ '--one', '1', '-a', '-b', '-c', 'three' ]
|
||||
)
|
||||
})
|
||||
|
||||
runner.test('getopt example 2', function (t) {
|
||||
a.deepStrictEqual(
|
||||
findReplace(argv(), /^-(\w{2,})$/, 'bread', 'milk'),
|
||||
[ '--one', '1', 'bread', 'milk', 'three' ]
|
||||
)
|
||||
})
|
Reference in New Issue
Block a user