├── .editorconfig
├── .eslintrc.json
├── .gitattributes
├── .gitignore
├── .travis.yml
├── .verb.md
├── LICENSE
├── README.md
├── bower.json
├── index.js
├── package.json
└── test.js
/.editorconfig:
--------------------------------------------------------------------------------
1 | # http://editorconfig.org/
2 | root = true
3 |
4 | [*]
5 | charset = utf-8
6 | end_of_line = lf
7 | indent_size = 2
8 | indent_style = space
9 | insert_final_newline = true
10 | trim_trailing_whitespace = true
11 |
12 | [{**/{actual,fixtures,expected,templates}/**,*.md}]
13 | trim_trailing_whitespace = false
14 | insert_final_newline = false
15 |
--------------------------------------------------------------------------------
/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "browser": false,
4 | "es6": true,
5 | "node": true,
6 | "mocha": true
7 | },
8 |
9 | "globals": {
10 | "document": false,
11 | "navigator": false,
12 | "window": false
13 | },
14 |
15 | "rules": {
16 | "accessor-pairs": 2,
17 | "arrow-spacing": [2, { "before": true, "after": true }],
18 | "block-spacing": [2, "always"],
19 | "brace-style": [2, "1tbs", { "allowSingleLine": true }],
20 | "comma-dangle": [2, "never"],
21 | "comma-spacing": [2, { "before": false, "after": true }],
22 | "comma-style": [2, "last"],
23 | "constructor-super": 2,
24 | "curly": [2, "multi-line"],
25 | "dot-location": [2, "property"],
26 | "eol-last": 2,
27 | "eqeqeq": [2, "allow-null"],
28 | "generator-star-spacing": [2, { "before": true, "after": true }],
29 | "handle-callback-err": [2, "^(err|error)$" ],
30 | "indent": [2, 2, { "SwitchCase": 1 }],
31 | "key-spacing": [2, { "beforeColon": false, "afterColon": true }],
32 | "keyword-spacing": [2, { "before": true, "after": true }],
33 | "new-cap": [2, { "newIsCap": true, "capIsNew": false }],
34 | "new-parens": 2,
35 | "no-array-constructor": 2,
36 | "no-caller": 2,
37 | "no-class-assign": 2,
38 | "no-cond-assign": 2,
39 | "no-const-assign": 2,
40 | "no-control-regex": 2,
41 | "no-debugger": 2,
42 | "no-delete-var": 2,
43 | "no-dupe-args": 2,
44 | "no-dupe-class-members": 2,
45 | "no-dupe-keys": 2,
46 | "no-duplicate-case": 2,
47 | "no-empty-character-class": 2,
48 | "no-eval": 2,
49 | "no-ex-assign": 2,
50 | "no-extend-native": 2,
51 | "no-extra-bind": 2,
52 | "no-extra-boolean-cast": 2,
53 | "no-extra-parens": [2, "functions"],
54 | "no-fallthrough": 2,
55 | "no-floating-decimal": 2,
56 | "no-func-assign": 2,
57 | "no-implied-eval": 2,
58 | "no-inner-declarations": [2, "functions"],
59 | "no-invalid-regexp": 2,
60 | "no-irregular-whitespace": 2,
61 | "no-iterator": 2,
62 | "no-label-var": 2,
63 | "no-labels": 2,
64 | "no-lone-blocks": 2,
65 | "no-mixed-spaces-and-tabs": 2,
66 | "no-multi-spaces": 2,
67 | "no-multi-str": 2,
68 | "no-multiple-empty-lines": [2, { "max": 1 }],
69 | "no-native-reassign": 0,
70 | "no-negated-in-lhs": 2,
71 | "no-new": 2,
72 | "no-new-func": 2,
73 | "no-new-object": 2,
74 | "no-new-require": 2,
75 | "no-new-wrappers": 2,
76 | "no-obj-calls": 2,
77 | "no-octal": 2,
78 | "no-octal-escape": 2,
79 | "no-proto": 0,
80 | "no-redeclare": 2,
81 | "no-regex-spaces": 2,
82 | "no-return-assign": 2,
83 | "no-self-compare": 2,
84 | "no-sequences": 2,
85 | "no-shadow-restricted-names": 2,
86 | "no-spaced-func": 2,
87 | "no-sparse-arrays": 2,
88 | "no-this-before-super": 2,
89 | "no-throw-literal": 2,
90 | "no-trailing-spaces": 0,
91 | "no-undef": 2,
92 | "no-undef-init": 2,
93 | "no-unexpected-multiline": 2,
94 | "no-unneeded-ternary": [2, { "defaultAssignment": false }],
95 | "no-unreachable": 2,
96 | "no-unused-vars": [2, { "vars": "all", "args": "none" }],
97 | "no-useless-call": 0,
98 | "no-with": 2,
99 | "one-var": [0, { "initialized": "never" }],
100 | "operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }],
101 | "padded-blocks": [0, "never"],
102 | "quotes": [2, "single", "avoid-escape"],
103 | "radix": 2,
104 | "semi": [2, "always"],
105 | "semi-spacing": [2, { "before": false, "after": true }],
106 | "space-before-blocks": [2, "always"],
107 | "space-before-function-paren": [2, "never"],
108 | "space-in-parens": [2, "never"],
109 | "space-infix-ops": 2,
110 | "space-unary-ops": [2, { "words": true, "nonwords": false }],
111 | "spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }],
112 | "use-isnan": 2,
113 | "valid-typeof": 2,
114 | "wrap-iife": [2, "any"],
115 | "yoda": [2, "never"]
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Enforce Unix newlines
2 | * text eol=lf
3 |
4 | # binaries
5 | *.ai binary
6 | *.psd binary
7 | *.jpg binary
8 | *.gif binary
9 | *.png binary
10 | *.jpeg binary
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # always ignore files
2 | *.DS_Store
3 | .idea
4 | *.sublime-*
5 |
6 | # test related, or directories generated by tests
7 | test/actual
8 | actual
9 | coverage
10 | .nyc*
11 |
12 | # npm
13 | node_modules
14 | npm-debug.log
15 |
16 | # yarn
17 | yarn.lock
18 | yarn-error.log
19 |
20 | # misc
21 | _gh_pages
22 | _draft
23 | _drafts
24 | bower_components
25 | vendor
26 | temp
27 | tmp
28 | TODO.md
29 | package-lock.json
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: false
2 | os:
3 | - linux
4 | - osx
5 | language: node_js
6 | node_js:
7 | - node
8 | - iojs
9 | - '9'
10 | - '8'
11 | - '7'
12 | - '6'
13 | - '5'
14 | - '4'
15 | - '0.12'
16 | - '0.10'
17 | git:
18 | depth: 10
19 |
--------------------------------------------------------------------------------
/.verb.md:
--------------------------------------------------------------------------------
1 | This function is used instead of `Array#slice` to support node lists in IE < 9 and to ensure dense arrays are returned. This is also faster than native slice in some cases.
2 |
3 | ## Usage
4 |
5 | ```js
6 | var slice = require('array-slice');
7 | var arr = ['a', 'b', 'd', 'e', 'f', 'g', 'h', 'i', 'j'];
8 |
9 | slice(arr, 3, 6);
10 | //=> ['e', 'f', 'g']
11 | ```
12 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014-2017, Jon Schlinkert.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # array-slice [](https://www.npmjs.com/package/array-slice) [](https://npmjs.org/package/array-slice) [](https://npmjs.org/package/array-slice) [](https://travis-ci.org/jonschlinkert/array-slice)
2 |
3 | > Array-slice method. Slices `array` from the `start` index up to, but not including, the `end` index.
4 |
5 | Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
6 |
7 | ## Install
8 |
9 | Install with [npm](https://www.npmjs.com/):
10 |
11 | ```sh
12 | $ npm install --save array-slice
13 | ```
14 |
15 | This function is used instead of `Array#slice` to support node lists in IE < 9 and to ensure dense arrays are returned. This is also faster than native slice in some cases.
16 |
17 | ## Usage
18 |
19 | ```js
20 | var slice = require('array-slice');
21 | var arr = ['a', 'b', 'd', 'e', 'f', 'g', 'h', 'i', 'j'];
22 |
23 | slice(arr, 3, 6);
24 | //=> ['e', 'f', 'g']
25 | ```
26 |
27 | ## About
28 |
29 |
30 | Contributing
31 |
32 | Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
33 |
34 |
35 |
36 |
37 | Running Tests
38 |
39 | Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
40 |
41 | ```sh
42 | $ npm install && npm test
43 | ```
44 |
45 |
46 |
47 |
48 | Building docs
49 |
50 | _(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
51 |
52 | To generate the readme, run the following command:
53 |
54 | ```sh
55 | $ npm install -g verbose/verb#dev verb-generate-readme && verb
56 | ```
57 |
58 |
59 |
60 | ### Related projects
61 |
62 | You might also be interested in these projects:
63 |
64 | * [arr-flatten](https://www.npmjs.com/package/arr-flatten): Recursively flatten an array or arrays. | [homepage](https://github.com/jonschlinkert/arr-flatten "Recursively flatten an array or arrays.")
65 | * [array-unique](https://www.npmjs.com/package/array-unique): Remove duplicate values from an array. Fastest ES5 implementation. | [homepage](https://github.com/jonschlinkert/array-unique "Remove duplicate values from an array. Fastest ES5 implementation.")
66 | * [array-xor](https://www.npmjs.com/package/array-xor): Returns the symmetric difference (exclusive-or) of an array of elements (elements that are present in… [more](https://github.com/jonschlinkert/array-xor) | [homepage](https://github.com/jonschlinkert/array-xor "Returns the symmetric difference (exclusive-or) of an array of elements (elements that are present in all given arrays and not in their intersections).")
67 |
68 | ### Author
69 |
70 | **Jon Schlinkert**
71 |
72 | * [github/jonschlinkert](https://github.com/jonschlinkert)
73 | * [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
74 |
75 | ### License
76 |
77 | Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
78 | Released under the [MIT License](LICENSE).
79 |
80 | ***
81 |
82 | _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on November 30, 2017._
--------------------------------------------------------------------------------
/bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "array-slice",
3 | "description": "Array-slice method. Slices `array` from the `start` index up to, but not including, the `end` index.",
4 | "version": "1.0.0",
5 | "homepage": "https://github.com/jonschlinkert/array-slice",
6 | "authors": [
7 | "Jon Schlinkert"
8 | ],
9 | "repository": "jonschlinkert/array-slice",
10 | "bugs": {
11 | "url": "https://github.com/jonschlinkert/array-slice/issues"
12 | },
13 | "license": "MIT",
14 | "files": [
15 | "index.js"
16 | ],
17 | "main": [
18 | "index.js"
19 | ],
20 | "devDependencies": {
21 | "gulp-format-md": "^0.1.11",
22 | "mocha": "^3.2.0"
23 | },
24 | "keywords": [
25 | "array",
26 | "javascript",
27 | "js",
28 | "slice",
29 | "util",
30 | "utils"
31 | ],
32 | "ignore": [
33 | "actual",
34 | "bower_components",
35 | "fixtures",
36 | "node_modules",
37 | "temp",
38 | "test",
39 | "test.js",
40 | "tmp"
41 | ]
42 | }
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | /*!
2 | * array-slice
3 | *
4 | * Copyright (c) 2014-2017, Jon Schlinkert.
5 | * Released under the MIT License.
6 | */
7 |
8 | 'use strict';
9 |
10 | module.exports = function slice(arr, start, end) {
11 | var len = arr.length;
12 | var range = [];
13 |
14 | start = idx(len, start);
15 | end = idx(len, end, len);
16 |
17 | while (start < end) {
18 | range.push(arr[start++]);
19 | }
20 | return range;
21 | };
22 |
23 | function idx(len, pos, end) {
24 | if (pos == null) {
25 | pos = end || 0;
26 | } else if (pos < 0) {
27 | pos = Math.max(len + pos, 0);
28 | } else {
29 | pos = Math.min(pos, len);
30 | }
31 |
32 | return pos;
33 | }
34 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "array-slice",
3 | "description": "Array-slice method. Slices `array` from the `start` index up to, but not including, the `end` index.",
4 | "version": "1.1.0",
5 | "homepage": "https://github.com/jonschlinkert/array-slice",
6 | "author": "Jon Schlinkert (https://github.com/jonschlinkert)",
7 | "repository": "jonschlinkert/array-slice",
8 | "bugs": {
9 | "url": "https://github.com/jonschlinkert/array-slice/issues"
10 | },
11 | "license": "MIT",
12 | "files": [
13 | "index.js"
14 | ],
15 | "main": "index.js",
16 | "engines": {
17 | "node": ">=0.10.0"
18 | },
19 | "scripts": {
20 | "test": "mocha"
21 | },
22 | "devDependencies": {
23 | "gulp-format-md": "^1.0.0",
24 | "mocha": "^3.5.3"
25 | },
26 | "keywords": [
27 | "array",
28 | "javascript",
29 | "js",
30 | "slice",
31 | "util",
32 | "utils"
33 | ],
34 | "verb": {
35 | "toc": false,
36 | "layout": "default",
37 | "tasks": [
38 | "readme"
39 | ],
40 | "plugins": [
41 | "gulp-format-md"
42 | ],
43 | "related": {
44 | "list": [
45 | "arr-flatten",
46 | "array-unique",
47 | "array-xor"
48 | ]
49 | },
50 | "lint": {
51 | "reflinks": true
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/test.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | /*!
4 | * array-slice
5 | *
6 | * Copyright (c) 2014-2015, 2017, Jon Schlinkert.
7 | * Released under the MIT License.
8 | */
9 |
10 | require('mocha');
11 | var assert = require('assert');
12 | var slice = require('./');
13 |
14 | describe('array-slice:', function() {
15 | it('should return the specified range.', function() {
16 | var arr = ['a', 'b', 'd', 'e', 'f', 'g', 'h', 'i', 'j'];
17 | assert.deepEqual(slice(arr, 3, 6), ['e', 'f', 'g']);
18 | assert.deepEqual(slice(arr, 1), ['b', 'd', 'e', 'f', 'g', 'h', 'i', 'j']);
19 | assert.deepEqual(slice(arr, -1), ['j']);
20 | });
21 |
22 | it('should not mutate the array', function() {
23 | var arr = ['a', 'b', 'd', 'e', 'f', 'g', 'h', 'i', 'j'];
24 | slice(arr, 3, 6);
25 | assert.deepEqual(arr, ['a', 'b', 'd', 'e', 'f', 'g', 'h', 'i', 'j']);
26 | });
27 | });
28 |
--------------------------------------------------------------------------------