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 98a4aed

Browse files
Expand pico-lambda
to include string and core. We're preparing to separate each into it's own project and module. Also there's a helper script (called china-plate), that we'll eventually pull out too, that helps ensure we're committing with the correct credentials.
1 parent 287b9ac commit 98a4aed

File tree

10 files changed

+541
-26
lines changed

10 files changed

+541
-26
lines changed

‎chinaPlate/china-plate.1.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[
2+
{
3+
"name": "Brendan O'Brien",
4+
"username": "ChanEilFhios",
5+
"email": "bobrien@gmail.com"
6+
},
7+
{
8+
"name": "Ronn Ross",
9+
"username": "ronnross",
10+
"email": "ronn.ross@gmail.com"
11+
},
12+
{
13+
"name": "Matt McFarland",
14+
"username": "MattMcFarland",
15+
"email": "contact@mattmcfarland.com"
16+
},
17+
{
18+
"name": "DCPDEV",
19+
"username": "DCPDEV",
20+
"email": "dcpdev@kroger.com"
21+
},
22+
{
23+
"name": "Please Delete Me",
24+
"username": "IJustCannotGoOn",
25+
"email": "nihilist@everythingsucks.com"
26+
}
27+
]

‎chinaPlate/china-plate.js

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
const fs = require('fs')
2+
let config = require('./china-plate.json')
3+
const { prompt, Separator } = require('inquirer')
4+
const exec = require('./exec')
5+
const { push, map } = require('../src/parray')
6+
const { curry, pipe } = require('../src/pcore')
7+
8+
const logData = (param) => {console.log(param); return param}
9+
10+
const buildUserSelection = selectFn => user => ({name: user.name, value: () => selectFn(user)})
11+
const buildUserPrompt = curry((message, extraOptions, userFunction, users) =>
12+
({
13+
type: "list",
14+
name: "user",
15+
pageSize: 10,
16+
message,
17+
choices: pipe(
18+
map(buildUserSelection(userFunction)),
19+
push(new Separator()),
20+
push(...extraOptions)
21+
)(users)
22+
})
23+
)
24+
const buildChangePrompt = buildUserPrompt("Please select who's committing",
25+
[{ name: "Add Person...", value: addPrompt },
26+
{ name: "Delete Person...", value: deletePrompt }],
27+
changeUser)
28+
const buildDeletePrompt = buildUserPrompt("select a user to DELETE",
29+
[{ name: "Return...", value: changePrompt }],
30+
deleteUser)
31+
32+
const addUserPrompt = [
33+
{
34+
type: "input",
35+
name: "name",
36+
message: "User's name",
37+
},
38+
{
39+
type: "input",
40+
name: "username",
41+
message: "Git username",
42+
},
43+
{
44+
type: "input",
45+
name: "email",
46+
message: "git email address",
47+
}
48+
]
49+
50+
function deletePrompt() {
51+
prompt(buildDeletePrompt(config))
52+
.then((answers) => {
53+
if (answers && typeof answers.user === "function") {
54+
answers.user()
55+
}
56+
})
57+
}
58+
59+
function changePrompt() {
60+
prompt(buildChangePrompt(config))
61+
.then((answers) => {
62+
if (answers && typeof answers.user === "function") {
63+
answers.user()
64+
}
65+
})
66+
}
67+
68+
function addPrompt() {
69+
prompt(addUserPrompt)
70+
.then((answers) => {
71+
addUser(answers)
72+
})
73+
}
74+
75+
// const createAddUser = config => user => pipe(push(user), writeFile)
76+
77+
function addUser(user) {
78+
config = pipe(
79+
push(user),
80+
writeFile
81+
)(config)
82+
83+
changePrompt()
84+
}
85+
86+
function changeUser({ username, email }) {
87+
exec('git', ["config", `user.name "${username}"`])
88+
exec('git', ["config", `user.email "${email}"`])
89+
}
90+
91+
function deleteUser(user) {
92+
config = config.filter(u => u.username !== user.username)
93+
writeFile(config)
94+
95+
changePrompt()
96+
}
97+
98+
function writeFile(objToWrite) {
99+
fs.writeFile("china-plate.json", JSON.stringify(objToWrite, null, 2), function (err) {
100+
if (err) {
101+
return console.log(err);
102+
}
103+
104+
console.log("The file was saved!");
105+
})
106+
107+
return objToWrite
108+
}
109+
110+
changePrompt()

‎chinaPlate/china-plate.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[
2+
{
3+
"name": "Brendan O'Brien",
4+
"username": "ChanEilFhios",
5+
"email": "bobrien@gmail.com"
6+
},
7+
{
8+
"name": "Ronn Ross",
9+
"username": "ronnross",
10+
"email": "ronn.ross@gmail.com"
11+
},
12+
{
13+
"name": "Matt McFarland",
14+
"username": "MattMcFarland",
15+
"email": "contact@mattmcfarland.com"
16+
},
17+
{
18+
"name": "DCPDEV",
19+
"username": "DCPDEV",
20+
"email": "dcpdev@kroger.com"
21+
},
22+
{
23+
"name": "Please Delete Me",
24+
"username": "IJustCannotGoOn",
25+
"email": "nihilist@everythingsucks.com"
26+
}
27+
]

‎chinaPlate/exec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const spawn = require('child_process').spawn
2+
module.exports = function(command, args, callback) {
3+
let result = '';
4+
const exec = spawn(command, args || [], {
5+
env: process.env,
6+
stdio: 'pipe',
7+
shell: true
8+
})
9+
exec.stdout.on('data', function(data) {
10+
result += data.toString()
11+
});
12+
exec.on('exit', code => {
13+
if (callback && typeof callback === "function") {
14+
if (code !== 0) {
15+
callback(code, null)
16+
} else {
17+
callback(null, result.trim())
18+
}
19+
} else if (code !== 0) {
20+
throw new Error('Error code: ' + code + ' for command: ' + command + ' ' + args.join(' '))
21+
}
22+
})
23+
}

‎src/parray.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
module.exports = Object
2-
.getOwnPropertyNames(Array.prototype)
3-
.reduce((lambda, method) => {
4-
lambda[method] = (~['concat', 'every', 'filter', 'find', 'findIndex', 'includes', 'join', 'map', 'reduce', 'reduceRight', 'slice', 'some'].indexOf(method))
5-
? (fn, ...params) => arr => arr[method](fn, ...params)
6-
: (~['sort', 'copyWithin', 'fill'].indexOf(method))
7-
? (...params) => arr => [...arr][method](...params)
8-
: (~['toLocaleString', 'indexOf', 'lastIndexOf'].indexOf(method))
9-
? (...params) => arr => arr[method](...params)
10-
: (~['push', 'splice'].indexOf(method))
11-
? (...params) => arr => { var t = [...arr]; t[method](...params); return t; }
12-
: (~['toString', 'entries', 'keys'].indexOf(method))
13-
? arr => arr[method]()
14-
: lambda[method]
15-
return lambda
16-
}, {
17-
pop: arr => arr.slice(0, -1),
18-
shift: arr => arr.slice(1),
19-
unshift: params => arr => [params, ...arr],
20-
reverse: arr => [...arr].reverse()
21-
})
2+
.getOwnPropertyNames(Array.prototype)
3+
.reduce((lambda, method) => {
4+
lambda[method] = (~['concat', 'every', 'filter', 'find', 'findIndex', 'includes', 'join', 'map', 'reduce', 'reduceRight', 'slice', 'some'].indexOf(method))
5+
? (fn, ...params) => arr => arr[method](fn, ...params)
6+
: (~['sort', 'copyWithin', 'fill'].indexOf(method))
7+
? (...params) => arr => [...arr][method](...params)
8+
: (~['toLocaleString', 'indexOf', 'lastIndexOf'].indexOf(method))
9+
? (...params) => arr => arr[method](...params)
10+
: (~['push', 'splice'].indexOf(method))
11+
? (...params) => arr => { var t = [...arr]; t[method](...params); return t; }
12+
: (~['toString', 'entries', 'keys'].indexOf(method))
13+
? arr => arr[method]()
14+
: lambda[method]
15+
return lambda
16+
}, {
17+
pop: arr => arr.slice(0, -1),
18+
shift: arr => arr.slice(1),
19+
unshift: params => arr => [params, ...arr],
20+
reverse: arr => [...arr].reverse()
21+
})

‎src/playbook.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const { pipe } = require('./pcore')
2+
const { reverse, join } = require('./parray')
3+
const { split } = require('./pstring')
4+
5+
module.exports = {
6+
reverseStr: pipe(split(''),
7+
reverse,
8+
join(''))
9+
}

‎src/pstring.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
module.exports = Object
2-
.getOwnPropertyNames(String.prototype)
3-
.reduce((lambda, method) => {
4-
lambda[method] = (~['charAt', 'charCodeAt', 'lastIndexOf', 'localeCompare', 'normalize', 'substr', 'substring', 'toString', 'trim', 'trimLeft', 'trimRight', 'valueOf', 'codePointAt', 'concat', 'endsWith', 'includes', 'indexOf', 'match', 'repeat', 'replace', 'search', 'slice', 'split', 'startsWith', 'toLowerCase', 'toLocaleLowerCase', 'toUpperCase', 'toLocaleUpperCase', 'padLeft', 'padRight'].indexOf(method))
5-
? (...params) => a => a[method](...params)
2+
.getOwnPropertyNames(String.prototype)
3+
.reduce((lambda, method) => {
4+
lambda[method] = (~['charAt', 'charCodeAt', 'lastIndexOf', 'localeCompare', 'normalize', 'substr', 'substring', 'codePointAt', 'concat', 'endsWith', 'includes', 'indexOf', 'match', 'repeat', 'replace', 'search', 'slice', 'split', 'startsWith'].indexOf(method))
5+
? (...params) => a => a[method](...params)
6+
: (~['toString', 'trim', 'trimLeft', 'trimRight', 'valueOf', 'toLowerCase', 'toUpperCase', 'toLocaleLowerCase', 'toLocaleUpperCase'].indexOf(method))
7+
? a => a[method]()
68
: lambda[method]
7-
}, {})
9+
return lambda
10+
}, {
11+
reverse: a => a.split('').reverse().join('')
12+
})

‎test/parray.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe('api: concat', () => {
3636
it('should not alter the original array', () => {
3737
const arrayOne = [3, 2];
3838
const addOne = PL.concat(1);
39-
(addOne(arrayOne));
39+
addOne(arrayOne);
4040
expect(arrayOne).toEqual([3, 2]);
4141
});
4242
});

‎test/playbook.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const PB = require('../src/playbook')
2+
3+
describe('api: reverse', () => {
4+
if (!PB.reverseStr) return
5+
it('should reverse the given string', () => {
6+
expect(PB.reverseStr("abcde")).toEqual("edcba")
7+
})
8+
})

0 commit comments

Comments
(0)

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