- Notifications
You must be signed in to change notification settings - Fork11
🌊 Tiniest FP-friendly JavaScript utils library
License
nanoutils/nanoutils
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Tiniest JavaScript utils library
First, installnanoutils
:
$ npm install --save nanoutils
or install it withyarn
:
$ yarn add nanoutils
To use ES modules we wrote a pluginbabel-plugin-nanoutils
To install:
$ npm install --save-dev babel-plugin-nanoutils
or
$ yarn add --dev babel-plugin-nanoutils
Using.babelrc
:
{ "preset": ["env"]+ "plugins": ["nanoutils"]}
via CLI:
{ "scripts": {+ "babel": "babel --plugins nanoutils app.js", "test": "jest && eslint ." }}
or with Node API:
const babel = require('babel-core')babel.transform('code', {+ plugins: ['nanoutils']})
import{ascend,az,prop,sortBy}from"nanoutils";constsortByName=sortBy(az(prop("name")));constsortByAge=sortBy(ascend(prop("age")));constconsultants=[{name:"Mike",age:30},{name:"David",age:35},{name:"Alex",age:25},];sortByName(consultants);// [{ name: 'Alex', age: 25 }, { name: 'David', age: 35 }, { name: 'Mike', age: 30 }]sortByAge(consultants);// [{ name: 'Alex', age: 25 }, { name: 'Mike', age: 30 }, { name: 'David', age: 35 }]
import{add,filterT,mapT,pipeT,prop,transduce}from"nanoutils";constisEven=(value)=>value%2===0;constsumOfAllEvenAgesNextYear=(array)=>transduce(pipeT(mapT(prop("age")),mapT(add(1)),filterT(isEven)),add,0,array);constconsultants=[{name:"Mike",age:30},{name:"David",age:35},{name:"Alex",age:25},];sumOfAllEvenAgesNextYear(ages);// 62
import{ascend,identity,join,mean,memoizeWith,sort}from"nanoutils";constgetHash=pipe(sort(ascend(identity)),join("-"));constmemoizedMean=memoizeWith(getHash,mean);memoizedMean([1,2,3]);// 2memoizedMean([1,2,3]);// 2 (extracts from memoizeWith function with hash='1-2-3')memoizedMean([3,1,2]);// 2 (extracts from memoizeWith function with hash='1-2-3')
We support nano-hype in JavaScript and want to create as much nano-things as possible.
So we're starting a challenge - write Ramda clone where no one method will be over 1KB size.
More nano's for the God of nano's!
- Functional style. FP is cool, isn't it? 😎 So we'll add some Ramda methods too.
- No ES6 features. We don't use Babel to save support in older browsers and save a status of nano-library.
- Usemethods composition only if it won't greatly increase the size of method
It's production-ready but still has following drawbacks:
- No TS types
It's also a Ramda-supportive, you can see both docs and types here:Ramda docs
- Create methods list
- Complete all needed methods (we get list of methods from Ramda) with 100% tests and types coverage
- Add documentation for all methods
- Create a tool to split nanoutils to separated packages
- Cover all methods with performance tests
- Reduce methods sizes even more
- Compare to
lodash
,underscore
(?)
If you want to help, here are some tools for you.
npm run method:add <...methods> -- [flags]yarn method:add <...methods> -- [flags]Params: methods List with method names (separated by space)Flags: -f Overwrite methods (if exists) --curried Add curried method you can use --curried=<N> to add curryN --types Add index.d.ts for method typings --perf Add <method>.performance.js for performance test of method
It will createlib/method
dir with following files:
index.js File with methodindex.d.ts TypeScript typings (if --types passed)method.test.js Test for method (I use Jest)method.performance.js Performance test for method (if --perf passed)
npm run size <...methods>yarn size <...methods>Paramsmethods List of method names (separated by space) you want to check. If no methods it will check size of all methods
npm run time <...methods>yarn time <...methods>Paramsmethods List of method names (separated by space) you want to check. If no methods it will check time of all possible methods (which have *.performance.js file) If type is set as no_perf (by default), it will throw an error: max.performance.js must have data to return
npm run method:check <type>yarn method:check <type>Paramstype What to display? - both: display methods that are both in ramda and nanoutils - nano: display nanoutils methods that ramda doesn't have - ramda: display ramda methods that nanoutils doesn't have
We usesize-limit to check the size of methods.
About
🌊 Tiniest FP-friendly JavaScript utils library
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors7
Uh oh!
There was an error while loading.Please reload this page.