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/remove-array-items | |
| parent | 2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff) | |
| download | xmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip | |
switch to vuepress
Diffstat (limited to 'node_modules/remove-array-items')
| -rwxr-xr-x | node_modules/remove-array-items/.npmignore | 4 | ||||
| -rw-r--r-- | node_modules/remove-array-items/.travis.yml | 39 | ||||
| -rw-r--r-- | node_modules/remove-array-items/LICENSE | 21 | ||||
| -rw-r--r-- | node_modules/remove-array-items/README.md | 36 | ||||
| -rw-r--r-- | node_modules/remove-array-items/index.js | 28 | ||||
| -rw-r--r-- | node_modules/remove-array-items/package.json | 29 | ||||
| -rw-r--r-- | node_modules/remove-array-items/test/index.js | 33 |
7 files changed, 190 insertions, 0 deletions
diff --git a/node_modules/remove-array-items/.npmignore b/node_modules/remove-array-items/.npmignore new file mode 100755 index 00000000..62225b48 --- /dev/null +++ b/node_modules/remove-array-items/.npmignore @@ -0,0 +1,4 @@ +.DS_Store +*.log +node_modules +.env* diff --git a/node_modules/remove-array-items/.travis.yml b/node_modules/remove-array-items/.travis.yml new file mode 100644 index 00000000..ccc0d6ad --- /dev/null +++ b/node_modules/remove-array-items/.travis.yml @@ -0,0 +1,39 @@ +sudo: false + +language: node_js + +node_js: +- '0.10' +- '0.12' +- '1' +- '2' +- '3' +- '4' +- '5' +- '6' +- '7' + +matrix: + include: + - node_js: '0.10' + env: BROWSER_NAME=chrome BROWSER_VERSION=latest + - node_js: '0.10' + env: BROWSER_NAME=chrome BROWSER_VERSION=29 + - node_js: '0.10' + env: BROWSER_NAME=firefox BROWSER_VERSION=latest + - node_js: '0.10' + env: BROWSER_NAME=opera BROWSER_VERSION=latest + - node_js: '0.10' + env: BROWSER_NAME=safari BROWSER_VERSION=latest + - node_js: '0.10' + env: BROWSER_NAME=safari BROWSER_VERSION=7 + - node_js: '0.10' + env: BROWSER_NAME=safari BROWSER_VERSION=6 + - node_js: '0.10' + env: BROWSER_NAME=safari BROWSER_VERSION=5 + - node_js: '0.10' + env: BROWSER_NAME=ie BROWSER_VERSION=11 + - node_js: '0.10' + env: BROWSER_NAME=ie BROWSER_VERSION=10 + - node_js: '0.10' + env: BROWSER_NAME=ie BROWSER_VERSION=9
\ No newline at end of file diff --git a/node_modules/remove-array-items/LICENSE b/node_modules/remove-array-items/LICENSE new file mode 100644 index 00000000..d1c9e2fb --- /dev/null +++ b/node_modules/remove-array-items/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Mike Reinstein + +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/remove-array-items/README.md b/node_modules/remove-array-items/README.md new file mode 100644 index 00000000..99aeda3e --- /dev/null +++ b/node_modules/remove-array-items/README.md @@ -0,0 +1,36 @@ +# remove-array-items + +remove items from a javascript array without generating memory garbage. + +[](https://travis-ci.org/mreinstein/remove-array-items) + +Despite there being a number of "remove array items" in npm, I couldn't find satisfying all criteria: + +* **doesn't generate garbage** +* **performs similar or better to the native `array.splice`** +* has tests +* es3+ compatible + +so here we are. + +originally inspired by https://gamealchemist.wordpress.com/2013/05/01/lets-get-those-javascript-arrays-to-work-fast/ + +(which is a gold mine for performant, non-garbage generating array operations by the way.) + + +## api + +```javascript +removeItems(arr, startIdx, removeCount) +``` + + +## usage + +```javascript +const removeItems = require('remove-array-items') + +const arr = [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] + +removeItems(arr, 3, 4) // after running, arr === [ 1, 2, 3, 8, 9 ] +``` diff --git a/node_modules/remove-array-items/index.js b/node_modules/remove-array-items/index.js new file mode 100644 index 00000000..468daddc --- /dev/null +++ b/node_modules/remove-array-items/index.js @@ -0,0 +1,28 @@ +'use strict' + +/** + * Remove a range of items from an array + * + * @function removeItems + * @param {Array<*>} arr The target array + * @param {number} startIdx The index to begin removing from (inclusive) + * @param {number} removeCount How many items to remove + */ +module.exports = function removeItems(arr, startIdx, removeCount) +{ + var i, length = arr.length + + if (startIdx >= length || removeCount === 0) { + return + } + + removeCount = (startIdx + removeCount > length ? length - startIdx : removeCount) + + var len = length - removeCount + + for (i = startIdx; i < len; ++i) { + arr[i] = arr[i + removeCount] + } + + arr.length = len +} diff --git a/node_modules/remove-array-items/package.json b/node_modules/remove-array-items/package.json new file mode 100644 index 00000000..cd2af476 --- /dev/null +++ b/node_modules/remove-array-items/package.json @@ -0,0 +1,29 @@ +{ + "name": "remove-array-items", + "version": "1.0.0", + "description": "remove items from a javascript array without generating memory garbage", + "main": "index.js", + "scripts": { + "test": "tap ./test" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/mreinstein/remove-array-items.git" + }, + "keywords": [ + "array", + "splice", + "remove", + "nogarbage", + "gcfriendly" + ], + "author": "Mike Reinstein", + "license": "MIT", + "bugs": { + "url": "https://github.com/mreinstein/remove-array-items/issues" + }, + "homepage": "https://github.com/mreinstein/remove-array-items#readme", + "devDependencies": { + "tap": "^10.3.2" + } +} diff --git a/node_modules/remove-array-items/test/index.js b/node_modules/remove-array-items/test/index.js new file mode 100644 index 00000000..8729ec36 --- /dev/null +++ b/node_modules/remove-array-items/test/index.js @@ -0,0 +1,33 @@ +'use strict' + +var removeItems = require('../index') +var test = require('tap').test + + +test('should return if the start index is greater than or equal to the length of the array', function(t) { + var arr = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] + removeItems(arr, arr.length + 1, 5) + t.equals(arr.length, 10) + t.end() +}) + +test('should return if the remove count is 0', function(t) { + var arr = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] + removeItems(arr, 2, 0) + t.equals(arr.length, 10) + t.end() +}) + +test('should remove the number of elements specified from the array, starting from the start index', function(t) { + var arr = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] + removeItems(arr, 3, 4) + t.deepEquals(arr, [ 1, 2, 3, 8, 9, 10 ]) + t.end() +}) + +test('should remove other elements if delete count is > than the number of elements after start index', function(t) { + var arr = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] + removeItems(arr, 7, 10) + t.deepEquals(arr, [ 1, 2, 3, 4, 5, 6, 7 ]) + t.end() +}) |
