pico-lambda
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -1,1 +0,1 @@ | ||
const l = Object.getOwnPropertyNames(Array.prototype).reduce((l, m) => { l[m] = (['concat', 'every', 'filter', 'find', 'findIndex', 'includes', 'join', 'map', 'reduce', 'reduceRight', 'slice', 'some'].includes(m)) ? (f,...p) => (a) => a[m](f,...p) : (['sort', 'copyWithin', 'fill'].includes(m)) ? (...p) => a => [...a][m](...p) : (['toLocaleString', 'indexOf', 'lastIndexOf'].includes(m)) ? (...p) => a => a[m](...p) : (['push', 'splice'].includes(m)) ? (...p) => a => { var t = [...a]; t[m](...p); return t } : (['toString', 'entries', 'keys'].includes(m)) ? a => a[m]() : l[m]; return l; }, { pop: a => a.slice(0, -1), shift: a => a.slice(1), unshift: p => a => [p,...a], reverse: a => [...a].reverse(), compose: (...s) => i => s.reduceRight((v, f) => f(v), i), pipe: (...s) => i => s.reduce((v, f) => f(v), i) }); if (typeof window !== 'undefined') window.PicoLambda = l; else module.exports = l; | ||
const l = Object.getOwnPropertyNames(Array.prototype).reduce((l, m) => { l[m] = (['concat', 'every', 'filter', 'find', 'findIndex', 'includes', 'join', 'map', 'reduce', 'reduceRight', 'slice', 'some'].includes(m)) ? (f,...p) => (a) => a[m](f,...p) : (['sort', 'copyWithin', 'fill'].includes(m)) ? (...p) => a => [...a][m](...p) : (['toLocaleString', 'indexOf', 'lastIndexOf'].includes(m)) ? (...p) => a => a[m](...p) : (['push', 'splice'].includes(m)) ? (...p) => a => { var t = [...a]; t[m](...p); return t; } : (['toString', 'entries', 'keys'].includes(m)) ? a => a[m]() : l[m]; return l; }, { pop: a => a.slice(0, -1), shift: a => a.slice(1), unshift: p => a => [p,...a], reverse: a => [...a].reverse(), compose: (...s) => i => s.reduceRight((v, f) => f(v), i), pipe: (...s) => i => s.reduce((v, f) => f(v), i) }); if (typeof window !== 'undefined') window.PicoLambda = l; else module.exports = l; |
{ | ||
"name": "pico-lambda", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "native functional js", | ||
@@ -10,6 +10,6 @@ "main": "dist/pico-lambda.js", | ||
"build": "npm run clean ; node build.js src/index.js dist/pico-lambda.js", | ||
"test": "standard src/index.js | snazzy && jasmine test/test.js", | ||
"test": "semistandard src/index.js | snazzy && jasmine test/test.js", | ||
"test:chrome": "DEBUG=testee:* testee test/jasmine.html --browsers chrome", | ||
"test:remote": "DEBUG=testee:* testee src/unit.html -c ./testee.remote.json", | ||
"lint": "standard src/index.js --fix | snazzy", | ||
"lint": "semistandard src/index.js --fix | snazzy", | ||
"watch": "nodemon --exec 'jasmine' test/test.js", | ||
@@ -43,23 +43,15 @@ "docs": "jsdoc src/index.js README.md -t node_modules/jaguarjs-jsdoc -d docs" | ||
"devDependencies": { | ||
"condense-whitespace": "1.0.0", | ||
"docdown": "^0.7.2", | ||
"faucet": "0.0.1", | ||
"install": "^0.8.4", | ||
"jaguarjs-jsdoc": "^1.0.2", | ||
"jasmine": "2.5.3", | ||
"jasmine-node": "1.14.5", | ||
"jasmine-spec-reporter": "3.2.0", | ||
"jsdoc": "^3.4.3", | ||
"minifier": "0.8.0", | ||
"newline-remove": "1.0.2", | ||
"nodemon": "1.11.0", | ||
"npm": "^4.1.1", | ||
"jasmine": "2.5.3", | ||
"jasmine-node": "1.14.5", | ||
"jasmine-spec-reporter": "3.2.0", | ||
"semistandard": "^9.2.1", | ||
"snazzy": "6.0.0", | ||
"standard": "8.6.0", | ||
"strip-comments": "0.4.4", | ||
"tape": "4.6.3", | ||
"testee": "0.3.0", | ||
"testee-client": "0.3.4", | ||
"testling": "1.7.1" | ||
"testee-client": "0.3.4" | ||
} | ||
} |
@@ -19,2 +19,12 @@ <h1 align="center">pico-lambda</h1> | ||
</a> | ||
<!-- Downloads --> | ||
<a href="https://npmjs.org/package/pico-lambda"> | ||
<img src="https://img.shields.io/npm/dm/pico-lambda.svg?style=flat-square" | ||
alt="Downloads" /> | ||
</a> | ||
<!-- Semi Standard --> | ||
<a href="https://github.com/Flet/semistandard"> | ||
<img src="https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg?style=flat-square" | ||
alt="semistandard" /> | ||
</a> | ||
</div> | ||
@@ -62,2 +72,3 @@ | ||
### compose :: `((e -> f), ..., (b -> c), (a -> b)) -> a -> f` | ||
Evaluates the provided functions, right to left, passing the return value | ||
@@ -67,6 +78,15 @@ of each function to the next in line. | ||
The output of the final function, in this case `(e->f)`, is returned. | ||
```js | ||
compose( | ||
map(x => x + 1), | ||
map(x => x + 1), | ||
map(x => x + 1) | ||
)([0]) // => 3 | ||
``` | ||
### concat :: `[a] -> ([a], ..., [a]) -> [a]` | ||
Concatenates two arrays | ||
```js | ||
concat([4, 5])([1,2,3]) // => [1, 2, 3, 4, 5] | ||
concat([4, 5])([1,2,3]) // => [1, 2, 3, 4, 5] | ||
concat([4, 5])([1,2], [3]) // => [1, 2, 3, 4, 5] | ||
@@ -79,2 +99,7 @@ ``` | ||
```js | ||
const arr = [1, 2, 3, 4, 5] | ||
copyWithin(3, 1)(arr) // => [1, 2, 3, 2, 3] | ||
copyWithin(3, 1, 2)(arr) // => [1, 2, 3, 2, 5] | ||
``` | ||
> See [Array.copyWithin (MDN)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin) | ||
@@ -85,2 +110,6 @@ | ||
```js | ||
const iterator = entries([1, 2, 3, 4, 5]) | ||
iterator.next()) // => { value: [0, 1], done: false } | ||
``` | ||
> See [Array.entries (MDN)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries) | ||
@@ -91,2 +120,7 @@ | ||
```js | ||
const predicate = x => x < 4 | ||
every(predicate)([1, 2, 3]) // => true | ||
every(predicate)([1, 2, 3, 4, 5]) // => false | ||
``` | ||
> See [Array.every (MDN)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every) | ||
@@ -97,2 +131,7 @@ | ||
```js | ||
const arr = [1, 2, 3, 4, 5] | ||
fill(1)(arr) // => [1, 1, 1, 1, 1] | ||
fill(1, 2, 4)(arr) // => [1, 2, 1, 1, 5] | ||
``` | ||
> See [Array.fill (MDN)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill) | ||
@@ -103,2 +142,6 @@ | ||
```js | ||
const predicate = x => x < 3 | ||
filter(predicate)([1, 2, 3, 4, 5]) // => [1, 2] | ||
``` | ||
> See [Array.filter (MDN)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) | ||
@@ -109,2 +152,7 @@ | ||
```js | ||
const predicate = x => x === 3 | ||
find(predicate)([1, 2, 3]) // => 3 | ||
find(predicate)([1, 2]) // => undefined | ||
``` | ||
> See [Array.find (MDN)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find) | ||
@@ -115,2 +163,8 @@ | ||
```js | ||
const arr = [1, 2, 3, 4, 5] | ||
const findIndex = x => x === 3 | ||
find(x => x > 3)(arr) // => 3 | ||
find(x => x > 80)(arr]) // => -1 | ||
``` | ||
> See [Array.findIndex (MDN)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex) | ||
@@ -121,2 +175,10 @@ | ||
```js | ||
const animals = ['dog', 'cat', 'ferret', 'hamster'] | ||
const hasCat = includes('cat') | ||
const hasUnicorn = includes('unicorn') | ||
hasCat(animals) // true | ||
hasUnicorn(animals) // false | ||
``` | ||
> See [Array.includes (MDN)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes) | ||
@@ -128,2 +190,6 @@ | ||
```js | ||
indexOf(3)([1, 2, 3, 4, 5]) // => 2 | ||
indexOf(3, 3)([[1, 2, 3, 4, 5, 3]) // => 3 | ||
``` | ||
> See [Array.indexOf (MDN)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf) | ||
@@ -134,2 +200,5 @@ | ||
```js | ||
join('-')([1, 2, 3]) // => '1-2-3' | ||
``` | ||
> See [Array.join (MDN)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join) | ||
@@ -140,2 +209,6 @@ | ||
```js | ||
const iterator = keys([1, 2, 3, 4, 5]) | ||
iterator.next() // => { value: 0, done: false } | ||
``` | ||
> See [Array.keys (MDN)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/keys) | ||
@@ -147,2 +220,6 @@ | ||
```js | ||
lastIndexOf(1)([1, 2, 3, 1]) // => 3 | ||
lastIndexOf(1, -2)([1, 2, 3, 1]) // => 0 | ||
``` | ||
> See [Array.lastIndexOf (MDN)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf) | ||
@@ -153,2 +230,5 @@ | ||
```js | ||
map(x => x * 2)([1, 2, 3]) // => 2, 4, 6 | ||
``` | ||
> See [Array.map (MDN)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) | ||
@@ -161,2 +241,9 @@ | ||
```js | ||
const arr = [1, 2, 3, 4, 5] | ||
pipe( | ||
unshift(0), | ||
concat([6, 7, 8]) | ||
)(arr) // => [0, 1, 2, 3, 4, 5, 6, 7, 8] | ||
``` | ||
> See [Array.pipe (MDN)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pipe) | ||
@@ -167,2 +254,5 @@ | ||
```js | ||
pop([1, 2, 3, 4, 5]) // => [1, 2, 3, 4] | ||
``` | ||
> See [Array.pop (MDN)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop) | ||
@@ -173,2 +263,5 @@ | ||
```js | ||
push(5)([1, 2, 3, 4]) // => [1, 2, 3, 4, 5] | ||
``` | ||
> See [Array.push (MDN)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push) | ||
@@ -175,0 +268,0 @@ |
@@ -12,3 +12,3 @@ | ||
: (['push', 'splice'].includes(method)) | ||
? (...params) => arr => { var t = [...arr]; t[method](...params); return t } | ||
? (...params) => arr => { var t = [...arr]; t[method](...params); return t; } | ||
: (['toString', 'entries', 'keys'].includes(method)) | ||
@@ -15,0 +15,0 @@ ? arr => arr[method]() |
@@ -92,2 +92,17 @@ const { describe, it, PicoLambda } = init() | ||
describe('api: entries', () => { | ||
it('should return an interator that contains key values pair of given array', () => { | ||
const arr = [1, 2, 3, 4, 5] | ||
const iterator = entries(arr) | ||
expect(iterator.next()).toEqual({ value: [0, 1], done: false }) | ||
}) | ||
it('should not alter the original array', () => { | ||
const arr = [1, 2, 3, 4, 5] | ||
const iterator = entries(arr) | ||
iterator.next() | ||
iterator.next() | ||
expect(arr).toEqual([1, 2, 3, 4, 5]) | ||
}) | ||
}) | ||
describe('api: every', () => { | ||
@@ -134,17 +149,2 @@ it('should return false if any items do not pass predicate', () => { | ||
describe('api: entries', () => { | ||
it('should return an interator that contains key values pair of given array', () => { | ||
const arr = [1, 2, 3, 4, 5] | ||
const iterator = entries(arr) | ||
expect(iterator.next()).toEqual({ value: [0, 1], done: false }) | ||
}) | ||
it('should not alter the original array', () => { | ||
const arr = [1, 2, 3, 4, 5] | ||
const iterator = entries(arr) | ||
iterator.next() | ||
iterator.next() | ||
expect(arr).toEqual([1, 2, 3, 4, 5]) | ||
}) | ||
}) | ||
describe('api: filter', () => { | ||
@@ -248,2 +248,17 @@ it('should return items that pass the predicate', () => { | ||
describe('api: join', () => { | ||
it('should return a string with each item separated with character passed in', () => { | ||
var arr = [1, 2, 3, 4, 5] | ||
const separateByDash = join('-') | ||
const result = separateByDash(arr) | ||
expect(result).toEqual('1-2-3-4-5') | ||
}) | ||
it('should not alter the original array', () => { | ||
var arr = [1, 2, 3, 4, 5] | ||
const separateByDash = join('-') | ||
const result = separateByDash(arr) | ||
expect(arr).toEqual([1, 2, 3, 4, 5]) | ||
}) | ||
}) | ||
describe('api: keys', () => { | ||
@@ -264,17 +279,4 @@ it('should return an iterator of keys of given array', () => { | ||
describe('api: join', () => { | ||
it('should return a string with each item separated with character passed in', () => { | ||
var arr = [1, 2, 3, 4, 5] | ||
const separateByDash = join('-') | ||
const result = separateByDash(arr) | ||
expect(result).toEqual('1-2-3-4-5') | ||
}) | ||
it('should not alter the original array', () => { | ||
var arr = [1, 2, 3, 4, 5] | ||
const separateByDash = join('-') | ||
const result = separateByDash(arr) | ||
expect(arr).toEqual([1, 2, 3, 4, 5]) | ||
}) | ||
}) | ||
describe('api: lastIndexOf', () => { | ||
@@ -369,3 +371,2 @@ it('should find the index of the last occurrence of an element', () => { | ||
/*////////////// Maybe ///////////*/ | ||
describe('api: reverse', () => { | ||
@@ -510,4 +511,2 @@ it('should return array reversed', () => { | ||
/*/////////////// end maybe //////////*/ | ||
describe('api: compose', () => { | ||
@@ -514,0 +513,0 @@ const is = a => b => { |
@@ -9,6 +9,2 @@ { | ||
"browsers": [{ | ||
"os": "win", | ||
"browser": "ie", | ||
"version": 11.0 | ||
}, { | ||
"os": "ios", | ||
@@ -15,0 +11,0 @@ "device": "iPad Mini", |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
49485
12
19
310
1
80
620
1