This repository has been archived by the owner on Apr 10, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit cf1677c
Showing
9 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = tab | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[{package.json,*.yml}] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*.sw[a-p] | ||
/node_modules/ | ||
npm-debug.log | ||
/coverage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
instrumentation: | ||
excludes: | ||
- test.js | ||
- test/**/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
language: node_js | ||
|
||
script: | ||
- node_modules/.bin/istanbul cover node_modules/.bin/_mocha -- --compilers coffee:coffee-script/register | ||
- cat coverage/lcov.info | node_modules/.bin/coveralls | ||
node_js: | ||
- "0.10" | ||
- "0.11" | ||
- "0.12" | ||
- "iojs" | ||
os: | ||
- linux | ||
- osx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 Josh Junon | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# simple-swizzle [![Travis-CI.org Build Status](https://img.shields.io/travis/Qix-/node-simple-swizzle.svg?style=flat-square)](https://travis-ci.org/Qix-/node-simple-swizzle) [![Coveralls.io Coverage Rating](https://img.shields.io/coveralls/Qix-/node-simple-swizzle.svg?style=flat-square)](https://coveralls.io/r/Qix-/node-simple-swizzle) | ||
|
||
> [Swizzle](https://en.wikipedia.org/wiki/Swizzling_(computer_graphics)) your function arguments; pass in mixed arrays/values and get a clean array | ||
## Usage | ||
|
||
```js | ||
var swizzle = require('simple-swizzle'); | ||
|
||
function myFunc() { | ||
var args = swizzle(arguments); | ||
// ... | ||
return args; | ||
} | ||
|
||
myFunc(1, [2, 3], 4); // [1, 2, 3, 4] | ||
myFunc(1, 2, 3, 4); // [1, 2, 3, 4] | ||
myFunc([1, 2, 3, 4]); // [1, 2, 3, 4] | ||
``` | ||
|
||
## License | ||
Licensed under the [MIT License](http://opensource.org/licenses/MIT). | ||
You can find a copy of it in [LICENSE](LICENSE). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
|
||
var concat = Array.prototype.concat; | ||
var slice = Array.prototype.slice; | ||
|
||
module.exports = function swizzle(args) { | ||
var results = []; | ||
|
||
for (var i = 0, len = args.length; i < len; i++) { | ||
var arg = args[i]; | ||
|
||
// https://jsperf.com/hasownproperty-vs-in-vs-undefined/12 | ||
if (typeof arg.length !== 'undefined') { | ||
// http://jsperf.com/javascript-array-concat-vs-push/98 | ||
results = concat.call(results, slice.call(arg)); | ||
} else { | ||
results.push(arg); | ||
} | ||
} | ||
|
||
return results; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "simple-swizzle", | ||
"description": "Simply swizzle your arguments", | ||
"version": "0.1.0", | ||
"author": "Qix (http://github.com/qix-)", | ||
"keywords": [ | ||
"argument", | ||
"arguments", | ||
"swizzle", | ||
"swizzling", | ||
"parameter", | ||
"parameters", | ||
"mixed", | ||
"array" | ||
], | ||
"license": "MIT", | ||
"scripts": { | ||
"pretest": "xo", | ||
"test": "mocha --compilers coffee:coffee-script/register" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"repository": "qix-/node-simple-swizzle", | ||
"devDependencies": { | ||
"coffee-script": "^1.9.3", | ||
"coveralls": "^2.11.2", | ||
"istanbul": "^0.3.17", | ||
"mocha": "^2.2.5", | ||
"should": "^7.0.1", | ||
"xo": "^0.7.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
should = require 'should' | ||
swizzle = require '../' | ||
|
||
Error.stackTraceLimit = Infinity | ||
|
||
swizMyself = -> swizzle arguments | ||
|
||
it 'should swizzle single values', -> | ||
(swizMyself 1, 2, 3, 4).should.deepEqual [1, 2, 3, 4] | ||
(swizMyself 1, 2, 3, 4).should.not.deepEqual [1, 2, 4] | ||
swizMyself().should.deepEqual [] | ||
|
||
it 'should swizzle a single array', -> | ||
(swizMyself [1, 2, 3, 4]).should.deepEqual [1, 2, 3, 4] | ||
|
||
it 'should swizzle interleaved values/arrays', -> | ||
(swizMyself 1, 2, [3, 4]).should.deepEqual [1, 2, 3, 4] | ||
(swizMyself [1, 2], [3, 4]).should.deepEqual [1, 2, 3, 4] | ||
(swizMyself [1, 2, 3], 4).should.deepEqual [1, 2, 3, 4] | ||
(swizMyself [1], [2], [3], [4]).should.deepEqual [1, 2, 3, 4] | ||
|
||
it 'should swizzle pseudo-arrays', -> | ||
(swizMyself 1, 2, {length: 2, 0: 3, 1: 4}).should.deepEqual [1, 2, 3, 4] | ||
(swizMyself {length: 1, 0: 1}, 2, 3, {length: 1, 0: 4}).should.deepEqual [1, 2, 3, 4] |