Skip to content

Commit 7efafbb

Browse files
committed
inital commit
0 parents  commit 7efafbb

File tree

352 files changed

+7170
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

352 files changed

+7170
-0
lines changed

.babelrc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"presets": [
3+
[
4+
"env",
5+
{
6+
"loose": true,
7+
"exclude": [
8+
"transform-es2015-typeof-symbol"
9+
],
10+
"targets": {
11+
"browsers": {
12+
"chrome": 28,
13+
"safari": 6,
14+
"firefox": 28,
15+
"opera": 32,
16+
"ie": 11
17+
}
18+
}
19+
}
20+
],
21+
"react"
22+
],
23+
"plugins": [
24+
"transform-object-rest-spread"
25+
]
26+
}

.esdoc.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"source": "./src",
3+
"destination": "docs/",
4+
"excludes": [
5+
"node_modules",
6+
"docs",
7+
"build"
8+
],
9+
"plugins": [
10+
{
11+
"name": "./plugins/esdoc/curry.js"
12+
},
13+
{
14+
"name": "esdoc-importpath-plugin",
15+
"option": {
16+
"replaces": [
17+
{
18+
"from": "^src/",
19+
"to": ""
20+
},
21+
{
22+
"from": "\\.js$",
23+
"to": ""
24+
}
25+
]
26+
}
27+
},
28+
{
29+
"name": "esdoc-standard-plugin",
30+
"option": {
31+
"test": {
32+
"source": "./",
33+
"includes": [
34+
"(__tests__).+\\.js$"
35+
]
36+
}
37+
}
38+
},
39+
{
40+
"name": "esdoc-ecmascript-proposal-plugin",
41+
"option": {
42+
"all": true
43+
}
44+
}
45+
]
46+
}

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
build
3+
docs
4+
coverage
5+
.DS_Store

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__tests__

.npmrc

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

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 0.6.2
2+
+ Add changelog
3+
+ Convert utils build with babel

COMPARE.md

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
# Comparison with other libraries
2+
3+
### [Ramda](http://ramdajs.com/)
4+
Ramda was a huge inspiration for Tinkoff Utils! it has a lot of similarities with naming style, uses same functional programming approach and many other things, with luck of some less popular design ideas like `__` prefixes, `lens*` functions and etc.
5+
6+
| Ramda | Utils |
7+
| --- | ------ |
8+
| R.all | /array/all |
9+
| R.allPass | /function/allPass |
10+
| R.always | /function/always |
11+
| R.any | /array/any |
12+
| R.anyPass | /function/anyPass |
13+
| R.both | /function/both |
14+
| R.clone | /clone |
15+
| R.complement | /function/complement |
16+
| R.compose | /function/compose |
17+
| R.composeP | /function/composeP |
18+
| R.concat | /array/concat |
19+
| R.cond | /function/cond |
20+
| R.contains | /array/includes |
21+
| R.curry | /function/curry (`__` not supported) |
22+
| R.curryN | /function/curryN |
23+
| R.defaultTo | /defaultTo |
24+
| R.difference | /array/difference |
25+
| R.dropWhile | /array/dropWhile |
26+
| R.either | /function/either |
27+
| R.empty | /is/empty |
28+
| R.equals | /is/equal |
29+
| R.endsWith | /string/endsWith | !only for strings |
30+
| R.F | /function/F |
31+
| R.filter | /array/filter | for arrays, /object/filter | for objects |
32+
| R.find | /array/find |
33+
| R.findIndex | /array/findIndex |
34+
| R.flatten | /array/flatten |
35+
| R.flip | /function/flip |
36+
| R.forEach | /array/each |
37+
| R.forEachObjIndexed | /object/each |
38+
| R.fromPairs | /object/fromPairs |
39+
| R.groupBy | /object/groupBy | for objects |
40+
| R.has | /object/has |
41+
| R.head | /array/head |
42+
| R.identity | /function/identity |
43+
| R.ifElse | /function/ifElse |
44+
| R.intersection | /array/intersection |
45+
| R.is | /is/* |
46+
| R.isEmpty | /is/empty |
47+
| R.isNil | /is/nil |
48+
| R.join | /array/join |
49+
| R.keys | /object/keys |
50+
| R.last | /array/last |
51+
| R.length | /array/length |
52+
| R.map | /array/map | for arrays, /object/map | for objects |
53+
| R.mapObjIndexed | /object/map |
54+
| R.maxBy | /array/maxBy |
55+
| R.merge | /object/merge (accepts n arguments, bot not less than 2) |
56+
| R.mergeAll | /object/merge (accepts an argument list not an array of arguments) |
57+
| R.mergeDeepLeft | /object/mergeDeep |
58+
| R.mergeWith | /object/mergeWith |
59+
| R.negate | /negate |
60+
| R.not | /not |
61+
| R.nth | /array/nth |
62+
| R.objOf | /object/objOf |
63+
| R.omit | /object/omit |
64+
| R.once | /function/once |
65+
| R.path | /object/path |
66+
| R.pathEq | /object/pathEq |
67+
| R.pathOr | /object/pathOr **Note** order of arguments is different (Utils always accepts path as first argument) |
68+
| R.pathSatisfies | /object/pathApply |
69+
| R.pick | /object/pick |
70+
| R.pickBy | /object/pickBy |
71+
| R.pipe | /object/compose (prefer to use compose) |
72+
| R.prop | /object/prop |
73+
| R.propEq | /object/propEq |
74+
| R.propOr | /object/propOr **Note** order of arguments is different (Utils always accepts prop name as first argument) |
75+
| R.propApply | /object/propApply |
76+
| R.range | /array/range |
77+
| R.reduce | /array/reduce, /object/reduce |
78+
| R.reduceWhile | /array/reduceWhile |
79+
| R.reject | /array/reject |
80+
| R.repeat | /array/repeat |
81+
| R.replace | /string/replace |
82+
| R.sort | /array/sort |
83+
| R.sortBy | /array/sortBy |
84+
| R.split | /string/split |
85+
| R.startsWith | /string/startsWith |
86+
| R.sum | /array/sum |
87+
| R.tail | /array/tail |
88+
| R.take | /array/take |
89+
| R.tap | /function/tap |
90+
| R.test | /string/test |
91+
| R.toLower | /string/toLower |
92+
| R.toPairs | /object/toPairs |
93+
| R.toString | /string/toString |
94+
| R.toUpper | /string/toUpper |
95+
| R.trim | /string/trim |
96+
| R.type | /type |
97+
| R.uniq | /array/uniq |
98+
| R.uniqBy | /array/uniqBy |
99+
| R.values | /object/values |
100+
| R.when | /function/when |
101+
| R.where | /object/where |
102+
| R.zip | /array/zip |
103+
| R.zipWith | /array/zipWith |
104+
| R.comparator | /function/comparator |
105+
| R.indexOf | /array/indexOf |
106+
| R.adjust | /array/adjust |
107+
| R.append | /array/append |
108+
| R.slice | /array/slice |
109+
| R.drop | /array/drop |
110+
| R.dropLast | /array/dropLast |
111+
| R.remove | /array/remove |
112+
| R.update | /array/update |
113+
| R.without | /array/without |
114+
115+
116+
### [Lodash](https://lodash.com/)
117+
Be careful when migrating from lodash to Utils:
118+
1. Check function signature, since Utils uses data as the last argument in contrast with lodash
119+
1. Singular lodash methods can accept various argument types when Utils functions are focused and cohesive
120+
1. Some Lodash functions mutate passed arguments
121+
122+
| Lodash | Utils |
123+
| --- | ------ |
124+
| _.compact | /array/filter + /function/identity `filter(identity)` |
125+
| _.concat | /array/concat |
126+
| _.difference | /array/difference |
127+
| _.dropWhile | /array/dropWhile |
128+
| _.findIndex | /array/findIndex |
129+
| _.first | /array/head |
130+
| _.flattenDeep | /array/flatten |
131+
| _.fromPairs | /object/fromPairs |
132+
| _.intersection | /array/intersection |
133+
| _.join | /array/join |
134+
| _.last | /array/last |
135+
| _.nth | /array/nth |
136+
| _.pull* | pull* mutates array, if there no need in it, then /array/filter + /function/* |
137+
| _.remove | mutates date, otherwise /array/filter + /function/* |
138+
| _.reverse | /array/reverse |
139+
| _.take | /array/take |
140+
| _.uniq | /array/uniq |
141+
| _.uniqBy | /array/uniqBy |
142+
| _.without | /array/filter + /function/* |
143+
| _.zip | /array/zip |
144+
| _.zipWith | /array/zipWith |
145+
| _.each | /array/each, /object/each |
146+
| _.forEach | /array/each, /object/each |
147+
| _.every | /array/all |
148+
| _.find | /array/find |
149+
| _.groupBy | /object/groupBy |
150+
| _.includes | /array/includes |
151+
| _.keyBy | /object/keyBy |
152+
| _.map | /array/map, /object/map |
153+
| _.partition | /array/partition |
154+
| _.reduce | /array/reduce, /object/reduce |
155+
| _.reject | /array/filter + /not `filter(not)` |
156+
| _.shuffle | /array/shuffle |
157+
| _.some | /array/any |
158+
| _.sortBy | /array/sortBy |
159+
| _.curry | /function/curry |
160+
| _.debounce | /function/debounce |
161+
| _.flip | /function/flip |
162+
| _.negate | /function/complement |
163+
| _.once | /function/once |
164+
| _.thtottle | /function/throttle |
165+
| _.castArray | /array/toArray |
166+
| _.clone | Object.assign({}, x) |
167+
| _.cloneDeep | /clone |
168+
| _.is* | /is/* a small part |
169+
| _.assign | Object.assign |
170+
| _.at | /array/map + /object/path |
171+
| _.defaults | /object/merge |
172+
| _.defaultsDeep | /object/mergeDeep |
173+
| _.entries | /object/toPairs |
174+
| _.forOwn | /object/each |
175+
| _.get | /object/path, /object/pathOr `get(obj, 'a.b[0].c', 'dflt') => pathOr(['a', 'b', 0, 'c'], 'dflt', obj)` |
176+
| _.has | /object/has |
177+
| _.keys | /object/keys |
178+
| _.mapKeys | /object/reduce + specific function |
179+
| _.mapValues | /object/map |
180+
| _.merge | /object/mergeDeep |
181+
| _.omit | /object/omit |
182+
| _.pick | /object/pick |
183+
| _.pickBy | /object/pickBy |
184+
| _.result | /object/pathApply + /function/applyOrReturn `result(obj, 'a.b', 'dflt') => pathApply(['a', 'b'], applyOrReturn, obj) || 'dflt'` |
185+
| _.set | /object/pathSet `set(obj, 'a.b[0]', 'val') => newObj = pathSet(['a', 'b', 0], 'val', obj)` |
186+
| _.toPairs | /object/toPairs |
187+
| _.values | /object/values |
188+
| _.tap | /function/tap |
189+
| _.capitalize | /string/capitalize |
190+
| _.endsWith | /string/endsWith |
191+
| _.escape | /string/escape |
192+
| _.escapeRegExp | /string/escapeRegExp |
193+
| _.repeat | /array/repeat + /array/join |
194+
| _.replace | /string/replace |
195+
| _.split | /string/split |
196+
| _.toLower | /string/toLower |
197+
| _.toUpper | /string/toUpper |
198+
| _.trim | /string/trim |
199+
| _.trimStart | /string/trimLeft |
200+
| _.unescape | /string/unescape |
201+
| _.cond | /function/cond |
202+
| _.conforms | /object/where |
203+
| _.constant | /function/always |
204+
| _.defaultTo | /defaultTo |
205+
| _.identity | /function/identity |
206+
| _.noop | /function/noop |
207+
| _.range | /array/range |
208+
| _.stub* | /function/always |
209+
| _.uniqueId | /uniqueId |

CONTRIBUTING.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Contributing
2+
1. Fork, then clone the repo
3+
1. Install dependencies with `npm install`
4+
1. Make sure the tests pass with `npm run test`
5+
1. Make changes. Make the tests pass
6+
1. Push to your fork and submit a pull request
7+
8+
## How to add new utility
9+
1. You should decide where to place new utility according the structure of library
10+
1. Pick the name of the new utility (corresponding to functionality or well-known name if there is analogue in other libraries (ramda, lodash))
11+
1. Create new file with picked named in corresponding directory, and add file with the same name to the directory '_\_tests__'
12+
1. Implement new functionality. For auto currying wrap utility to `/function/curry` or `/function/curryN` (curry doesn't support default and rest arguments, so prefer to use curryN)
13+
1. Add tests (don't forget edge cases and exceptions)
14+
1. Add JSDoc with description of functionality, arguments types and a little example
15+
16+
## How to write JSDoc right
17+
List of supported tags are [here](https://esdoc.org/manual/tags.html)
18+
19+
List of unnecessary things in JSDoc:
20+
1. Description of utility
21+
1. If there is some additional information you want to add - prepend it with '*\*Note:**'
22+
1. Add arguments types and description for them (see @param)
23+
1. Add type and description for return value (see @return)
24+
1. Add an example to demonstrate to to use utility (see @example)
25+
26+
##### Example
27+
```javascript
28+
import curryN from '../function/curryN';
29+
30+
/**
31+
* Returns `true` if at least one of elements of the list match the predicate,
32+
* `false` otherwise.
33+
*
34+
* @param {Function} fn The predicate function.
35+
* @param {Array} arr The array to consider.
36+
* @return {Boolean} `true` if the predicate is satisfied by at least one element, `false`
37+
* otherwise.
38+
* @example
39+
*
40+
* var lessThan0 = x => x < 0;
41+
* var lessThan2 = x => x < 2;
42+
* any(lessThan0)([1, 2]); //=> false
43+
* any(lessThan2)([1, 2]); //=> true
44+
*/
45+
export default curryN(2, (fn, arr = []) => {
46+
for (let i = 0; i < arr.length; i++) {
47+
if (fn(arr[i], i, arr)) {
48+
return true;
49+
}
50+
}
51+
52+
return false;
53+
});
54+
```

LICENSE

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright 2018 Tinkoff <frontend@tinkoff.ru>
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

0 commit comments

Comments
 (0)