Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 00b0ef7

Browse files
committed
Refactor to single file
1 parent 321338c commit 00b0ef7

File tree

10 files changed

+49
-45
lines changed

10 files changed

+49
-45
lines changed

‎chinaPlate/china-plate.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,10 @@
1818
"name": "DCPDEV",
1919
"username": "DCPDEV",
2020
"email": "dcpdev@kroger.com"
21+
},
22+
{
23+
"name": "Sherman Adelson",
24+
"username": "mnebuerquo",
25+
"email": "sherman.adelson@gmail.com"
2126
}
2227
]

‎package.json

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
"name": "pico-lambda",
33
"version": "1.0.4",
44
"description": "native functional js",
5-
"main": "dist/pico-lambda.js",
6-
"browser": "dist/pico-lambda.js",
5+
"main": "src/index.js",
76
"scripts": {
8-
"pr": "pr-chief",
97
"clean": "rm -rf dist ; mkdir dist ;",
10-
"build": "npm run clean ; node build.js src/index.js dist/pico-lambda.js",
11-
"build:modules": "npm run clean ; node build.js src/pcore.js dist/pcore.js; node build.js src/parray.js dist/parray.js; node build.js src/pstring.js dist/pstring.js",
8+
"concat": "",
9+
"build": "npm run clean ; babili src -d dist",
1210
"test": "jasmine test/*.test.js",
1311
"test:remote": "npm run lint && BUILD=$(git rev-parse --short HEAD) karma start karma.conf.js",
1412
"lint": "semistandard src/index.js test/test.js --fix | snazzy",
@@ -36,6 +34,11 @@
3634
"email": "bobrien@gmail.com",
3735
"name": "Brendan O'Brien",
3836
"url": "https://github.com/ChanEilFhios"
37+
},
38+
{
39+
"email": "sherman.adelson@gmail.com",
40+
"name": "Sherman Adelson",
41+
"url": "https://github.com/mnebuerquo"
3942
}
4043
],
4144
"repository": {
@@ -56,5 +59,8 @@
5659
"semistandard": "^9.2.1",
5760
"snazzy": "6.0.0",
5861
"strip-comments": "0.4.4"
59-
}
60-
}
62+
},
63+
"files": [
64+
"src"
65+
]
66+
}

‎src/index.js

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,32 @@
1+
const ctx = (typeof window !== 'undefined') ? window : module ? module.exports : {};
12

3+
const c = (fn, ...params) => fn.length <= params.length ? fn(...params) : (...others) => c(fn, ...params, ...others);
4+
const cp = method => (...fns) => initialValue => fns[method]((value, fn) => fn(value), initialValue);
25

3-
const lambda = Object
6+
ctx.pcore = {
7+
curry: c,
8+
compose: cp('reduceRight'),
9+
pipe: cp('reduce'),
10+
identity: a => a
11+
};
12+
13+
ctx.pstring = Object
14+
.getOwnPropertyNames(String.prototype)
15+
.reduce((lambda, method) => {
16+
lambda[method] = (~['charAt', 'charCodeAt', 'lastIndexOf', 'localeCompare', 'normalize', 'substr', 'substring', 'codePointAt', 'concat', 'endsWith', 'includes', 'indexOf', 'match', 'repeat', 'replace', 'search', 'slice', 'split', 'startsWith'].indexOf(method))
17+
? (...params) => a => a[method](...params)
18+
: (~['toString', 'trim', 'trimLeft', 'trimRight', 'valueOf', 'toLowerCase', 'toUpperCase', 'toLocaleLowerCase', 'toLocaleUpperCase'].indexOf(method))
19+
? a => a[method]()
20+
: lambda[method];
21+
return lambda;
22+
}, {});
23+
24+
ctx.parray = Object
425
.getOwnPropertyNames(Array.prototype)
526
.reduce((lambda, method) => {
627
lambda[method] = (~['concat', 'every', 'filter', 'find', 'findIndex', 'includes', 'join', 'map', 'reduce', 'reduceRight', 'slice', 'some'].indexOf(method))
7-
? (fn, ...params) => (arr) => arr[method](fn, ...params)
8-
: (~['sort', 'copyWithin', 'fill'].indexOf(method))
28+
? (fn, ...params) => arr => arr[method](fn, ...params)
29+
: (~['sort', 'copyWithin', 'fill'].indexOf(method))
930
? (...params) => arr => [...arr][method](...params)
1031
: (~['toLocaleString', 'indexOf', 'lastIndexOf'].indexOf(method))
1132
? (...params) => arr => arr[method](...params)
@@ -19,10 +40,5 @@ const lambda = Object
1940
pop: arr => arr.slice(0, -1),
2041
shift: arr => arr.slice(1),
2142
unshift: params => arr => [params, ...arr],
22-
reverse: arr => [...arr].reverse(),
23-
compose: (...fns) => initialValue => fns.reduceRight((value, fn) => fn(value), initialValue),
24-
pipe: (...fns) => initialValue => fns.reduce((value, fn) => fn(value), initialValue)
43+
reverse: arr => [...arr].reverse()
2544
});
26-
27-
if (typeof window !== 'undefined') window.PicoLambda = lambda;
28-
if (module) module.exports = lambda;

‎src/pico.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

‎src/playbook.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

‎src/pstring.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,4 @@ module.exports = Object
77
? a => a[method]()
88
: lambda[method]
99
return lambda
10-
}, {
11-
reverse: a => a.split('').reverse().join('')
12-
})
10+
}, {})

‎test/parray.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function init () {
1212
}));
1313
}
1414

15-
const PicoLambda = require('../src/parray.js');
15+
const PicoLambda = require('../src/index.js').parray;
1616
const { describe, expect, it } = global;
1717
return { PicoLambda, describe, expect, it };
1818
}

‎test/pcore.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ function init () {
1212
}));
1313
}
1414

15-
const PicoLambda = Object.assign({}, require('../src/parray'), require('../src/pcore'));
15+
const tempLambda = require('../src/index.js')
16+
17+
const PicoLambda = Object.assign({}, tempLambda.pcore, tempLambda.parray);
1618
const { describe, expect, it } = global;
1719
return { PicoLambda, describe, expect, it };
1820
}

‎test/playbook.test.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎test/pstring.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function init() {
1212
}))
1313
}
1414

15-
const PicoLambda = require('../src/pstring')
15+
const PicoLambda = require('../src/index').pstring
1616
const { describe, expect, it } = global
1717
return { PicoLambda, describe, expect, it }
1818
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /