├── .gitignore ├── LICENSE ├── README.md ├── index.js ├── package.json └── test └── to-array.test.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.log 3 | *.err -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Raynos. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # to-array 2 | 3 | Turn an array like into an array. Designed for browser support in older browsers. 4 | 5 | ## Example 6 | 7 | ``` js 8 | var toArray = require("to-array") 9 | , elems = document.links 10 | 11 | var array = toArray(elems) 12 | ``` 13 | Can also return an array from a specific index 14 | 15 | ```js 16 | (function () { 17 | toArray(arguments, 2) // [3, 4] 18 | })(1, 2, 3, 4) 19 | ``` 20 | 21 | ## Installation 22 | 23 | `npm install to-array` 24 | 25 | ## Contributors 26 | 27 | - Raynos 28 | - [Olivier Scherrer](http://github.com/podefr) 29 | 30 | ## MIT Licenced 31 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | module.exports = toArray 2 | 3 | function toArray(list, index) { 4 | var array = [] 5 | 6 | index = index || 0 7 | 8 | for (var i = index || 0; i < list.length; i++) { 9 | array[i - index] = list[i] 10 | } 11 | 12 | return array 13 | } 14 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "to-array", 3 | "version": "0.1.5", 4 | "description": "Turn an array like into an array", 5 | "keywords": [], 6 | "author": "Raynos ", 7 | "repository": "git://github.com/Raynos/to-array.git", 8 | "main": "index", 9 | "homepage": "https://github.com/Raynos/to-array", 10 | "contributors": [ 11 | { 12 | "name": "Jake Verbaten", 13 | "name": "Olivier Scherrer " 14 | } 15 | ], 16 | "bugs": { 17 | "url": "https://github.com/Raynos/to-array/issues", 18 | "email": "raynos2@gmail.com" 19 | }, 20 | "dependencies": {}, 21 | "devDependencies": { 22 | "tap": "~0.3.1" 23 | }, 24 | "licenses": [ 25 | { 26 | "type": "MIT", 27 | "url": "http://github.com/Raynos/to-array/raw/master/LICENSE" 28 | } 29 | ], 30 | "scripts": { 31 | "test": "tap --stderr --tap test/*" 32 | }, 33 | "component": { 34 | "scripts": { 35 | "to-array/index.js": "index.js" 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /test/to-array.test.js: -------------------------------------------------------------------------------- 1 | var test = require("tap").test 2 | , sut = require("../index") 3 | 4 | test("to-array", function (t) { 5 | (function () { 6 | 7 | t.same(sut(arguments), [0, 1, 2, 3], "transforms array-like array into an array") 8 | t.same(sut(arguments, 2), [2, 3], "transforms into an array from specified index") 9 | 10 | })(0, 1, 2, 3) 11 | 12 | t.end() 13 | }) 14 | --------------------------------------------------------------------------------