Skip to content

Commit d241a08

Browse files
committed
feat: initial commit
0 parents  commit d241a08

File tree

8 files changed

+412
-0
lines changed

8 files changed

+412
-0
lines changed

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
node_modules/
2+
.idea/
3+
.DS_Store
4+
*npm-debug.log
5+
log/
6+
*.swp
7+
*.swo
8+
coverage/
9+
tmp/
10+
.nyc_output

.npmignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
demo/
2+
tmp/
3+
node_modules/
4+
log/
5+
spec/
6+
plato/
7+
coverage/
8+
.vagrant/
9+
.nyc_output
10+
.git

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# fauxdash
2+
3+
This is because I got tired of writing the same kinds of things over and didn't want the full lodash. It's amazing how simple some things are when you know you're running Node and don't care about 87 flavors ES/browser vendor mash-up, right?
4+
5+
Also this is probably terrible and only intended for use by my other projects. Note its total lack of documentation. That's on purpose.

package.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "fauxdash",
3+
"version": "1.0.0",
4+
"description": "I don't know it's not lodash",
5+
"main": "src/index.js",
6+
"scripts": {
7+
"pretest": "standard",
8+
"test": "./node_modules/mocha/bin/mocha spec/*.spec.js",
9+
"coverage": "nyc npm test",
10+
"release": "standard-version"
11+
},
12+
"repository": {
13+
"type": "git",
14+
"url": "git://github.com/deftly/fauxdash.git"
15+
},
16+
"author": "Alex Robson",
17+
"license": "ISC",
18+
"bugs": {
19+
"url": "https://github.com/deftly/fauxdash/issues"
20+
},
21+
"homepage": "https://github.com/deftly/fauxdash#readme",
22+
"standard": {
23+
"env": [
24+
"mocha"
25+
]
26+
},
27+
"devDependencies": {
28+
"chai": "^4.1.0",
29+
"chai-as-promised": "^7.1.1",
30+
"mocha": "^3.4.2",
31+
"mocha-lcov-reporter": "^1.3.0",
32+
"nyc": "^11.0.3",
33+
"standard": "^10.0.2",
34+
"standard-version": "^4.2.0"
35+
}
36+
}

spec/fauxdash.spec.js

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/* eslint-disable */
2+
3+
require('./setup')
4+
5+
const _ = require('../src/index')
6+
7+
describe('fauxdash', function () {
8+
describe('Array Functions', function () {
9+
it('should correctly evaluate any', function () {
10+
_.any([,,, 5]).should.equal(true)
11+
_.any([,,,, ]).should.equal(false)
12+
_.any([1,,,, ]).should.equal(true)
13+
_.any([,, 10,, ], x => x > 5).should.equal(true)
14+
_.any([,,,, 10], x => x < 5).should.equal(false)
15+
})
16+
17+
it('should correctly evaluate contains', function () {
18+
_.contains(['a', 'b', 'c', 'd'], 'b').should.equal(true)
19+
_.contains(['a', 'b', 'c', 'd'], 'e').should.equal(false)
20+
_.contains([1, 2, 3, 4, 5], 6).should.equal(false)
21+
_.contains([1, 2, 3, 4, 5], 3).should.equal(true)
22+
})
23+
24+
it('should filter correctly', function () {
25+
_.filter([,, 4,, 1]).should.eql([4, 1])
26+
_.filter(['a',,,, 'b']).should.eql(['a', 'b'])
27+
_.filter([1, 2, 3, 4, 5, 6], x => x % 2 === 0).should.eql([2, 4, 6])
28+
})
29+
30+
it('should find correctly', function () {
31+
_.find([,,, 10,,, ]).should.equal(10)
32+
_.find([9, 3, 1, 10, 4, 2, 8], x => x >= 10).should.equal(10)
33+
_.find(['cat', 'bat', 'hat', 'rat', 'mat'], x => x === 'bat').should.equal('bat')
34+
expect(_.find(['a', 'b', 'c'], x => x === 'd')).equal(undefined)
35+
})
36+
37+
it('should flatten correctly', function () {
38+
_.flatten([1, 2, 3, 4]).should.eql([1, 2, 3, 4])
39+
_.flatten([1, [2, 3], [4]]).should.eql([1, 2, 3, 4])
40+
_.flatten([1, [2, [3]], [4], [[[5, 6, 7]]]]).should.eql([1, 2, 3, 4, 5, 6, 7])
41+
})
42+
})
43+
44+
describe('Is', function () {
45+
it('should correctly identify dates', function () {
46+
_.isDate(new Date()).should.equal(true)
47+
_.isDate('01/01/2010').should.equal(false)
48+
})
49+
50+
it('should correctly identify functions', function () {
51+
_.isFunction(function () {}).should.equal(true)
52+
_.isFunction(() => {}).should.equal(true)
53+
_.isFunction(x => x).should.equal(true)
54+
_.isFunction('').should.equal(false)
55+
})
56+
57+
it('should correctly identify numbers', function () {
58+
_.isNumber(100).should.equal(true)
59+
_.isNumber(100.5).should.equal(true)
60+
_.isNumber('5').should.equal(false)
61+
})
62+
63+
it('should correctly identify objects', function () {
64+
_.isObject(new Object()).should.equal(true)
65+
_.isObject({}).should.equal(true)
66+
_.isObject(new Date()).should.equal(true)
67+
_.isObject(() => {}).should.equal(true)
68+
_.isObject('hi').should.equal(false)
69+
})
70+
71+
it('should correctly identify plain objects', function () {
72+
_.isObject(new Object()).should.equal(true)
73+
_.isObject({}).should.equal(true)
74+
_.isObject(() => {}).should.equal(true)
75+
_.isObject(5).should.equal(false)
76+
_.isObject('hi').should.equal(false)
77+
})
78+
79+
it('should correctly identify promisey objects', function () {
80+
_.isPromisey(new Promise(() => {})).should.equal(true)
81+
_.isPromisey({then: () => {}}).should.equal(true)
82+
_.isPromisey(new Object()).should.equal(false)
83+
_.isPromisey('no').should.equal(false)
84+
})
85+
86+
it('should correctly identify strings', function () {
87+
_.isString('yay').should.equal(true)
88+
_.isString(5).should.equal(false)
89+
_.isString(['a', 'b', 'c']).should.equal(false)
90+
})
91+
})
92+
93+
describe('Function tools', function () {
94+
it('should get arguments correctly', function () {
95+
_.getArguments(function (a, b, c) {}).should.eql(['a', 'b', 'c'])
96+
_.getArguments((a, b, c, d) => {}).should.eql(['a', 'b', 'c', 'd'])
97+
_.getArguments(a => {}).should.eql(['a'])
98+
})
99+
100+
it('should parse function correctly', function () {
101+
_.parseFunction(function one (a, b, c) {})
102+
.should.eql({ name: 'one', arguments: ['a', 'b', 'c'], body: undefined })
103+
})
104+
105+
it('should parse function correctly', function () {
106+
_.parseFunction((a, b) => {})
107+
.should.eql({ name: undefined, arguments: ['a', 'b'], body: undefined })
108+
})
109+
110+
it('should parse function correctly', function () {
111+
_.parseFunction(a => {})
112+
.should.eql({ name: undefined, arguments: ['a'], body: undefined })
113+
})
114+
})
115+
116+
describe('Utility functions', function () {
117+
let lifted
118+
before(function () {
119+
function asyncCall (a, cb) {
120+
if (!a) { cb(new Error('nope')) }
121+
cb(null, a)
122+
}
123+
lifted = _.lift(asyncCall)
124+
})
125+
126+
it('should trim and filter list of strings correctly', function () {
127+
_.trim([]).should.eql([])
128+
_.trim([,, '', '']).should.eql([])
129+
_.trim([,, ' ', ' ']).should.eql([])
130+
_.trim(['a ', ' b', 'c', ' d ', 'e ']).should.eql(['a', 'b', 'c', 'd', 'e'])
131+
})
132+
133+
it('should reject on failed async function', function () {
134+
return lifted(null).should.be.rejectedWith('nope')
135+
})
136+
137+
it('should resolved on successful function', function () {
138+
return lifted(100).should.eventually.equal(100)
139+
})
140+
})
141+
})

spec/setup.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const chai = require('chai')
2+
chai.use(require('chai-as-promised'))
3+
global.should = chai.should()
4+
global.expect = chai.expect

0 commit comments

Comments
 (0)