zenika-open-source / immutadot Goto Github PK
View Code? Open in Web Editor NEWimmutadot is a JavaScript library to deal with nested immutable structures.
Home Page: https://immutadot.zenika.com
License: MIT License
immutadot is a JavaScript library to deal with nested immutable structures.
Home Page: https://immutadot.zenika.com
License: MIT License
concat
difference
drop
pull
remove
Write an apply
function allowing to browse a path generated by toPath
and apply an operation at the end of the path...
Add a documentation generated using jsdoc.
Allow the use of using
within a chain
sequence :
const o = { nested: { a: 2, b: 3 } }
chain(o)
.using('nested.b').add('nested.a')
.using('nested.a').multiply('nested.b')
.value() // => { nested: { a: 5, b: 6 } }
Allow to do it with the second chain parameter 🚀 :
const o = { nested: { a: 2, b: 3 } }
chain(o, 'nested')
.using('b').add('a')
.using('a').multiply('b')
.value() // => { nested: { a: 5, b: 6 } }
Rewrite set
without lodash.
Since master branch is protected, publish-docs.sh can't push to master.
using('<path>').update(...)
crashes with TypeError: updater.apply is not a function
Version : 0.2.0
Call updater with the '<path>'
argument.
'<path>'
argument is used as the updater.
const input = {
pages: [1, 2, 3],
selectedPages: [4, 5, 6],
}
const output = using('pages').update(input, 'selectedPages', (selectedPages, pages) => pages.map(page => page * 2))
expect(output).toEqual({
pages: [1, 2, 3],
selectedPages: [2, 4, 6],
})
Collection :
Math :
Object :
String :
I cannot specify array properties in path.
// An example of code using the feature
const categories = [{
sections: [{
attributes: [{
name: 'name',
value: 'value'
}]
}]
}]
const filteredCategories = filter(
categories,
'sections.attributes',
({ value }) => isEmpty(value)
)
Use _.toPath
Go back to babel stage-2 instead of stage-0
Add TS definition file to have type checking
Using immutadot properly with typescript
Add the lodash equivalent of mapValues
:
const obj = {nested: { a: 1, b: 2, c: 3 } }
const obj2 = mapValues(obj, "nested", (value, key, o) => value * value)
// obj2 = {nested : { a: 1, b: 4, c: 9 } }
push
based on Array.prototype.push
splice
based on Array.prototype.splice
unshift
based on Array.prototype.unshift
lodash/fp/update
sends a shallow clone of the updated value to the updater :
lodash/fp
version of functions mutating at first level onlylodash/toArray
before using mutating Array methods.Add the lodash pickBy function like this :
const objectOne = {
nested: {
a: 1,
b: 2,
c: 3,
d: 4,
},
}
const result = pickBy(objectOne, 'nested', v => v < 3)
// => result = {
nested: {
a: 1,
b: 2
},
}
Add core.using
, allowing to pass more arguments from the source object to update
and derived functions.
using
will not have unset
core function.
using().update()
will not have the "function only" version of update
.
ℹ️ First version will not be integrated with chain
, see #15 for integration.
Example 1 with update
:
const o = { nested: { a: 2, b: 3 } }
using('nested.b')
.update(o, 'nested.a', (a, b) => a * b) // => { nested: { a: 6, b: 3 } }
Example 2 with add
:
const o = { nested: { a: 2, b: 3 } }
using('nested.b')
.add(o, 'nested.a') // => { nested: { a: 5, b: 3 } }
Example 3 with update
and several arguments :
const o = { nested: { a: 2, b: 3, c: 4 } }
using('nested.b', 'nested.c')
.update(o, 'nested.a', (a, b, c) => a * b + c) // => { nested: { a: 10, b: 3, c: 4 } }
Example 4 with set
:
const o = { nested: { a: 2 } }
using('nested.a')
.set(o, 'nested.b') // => { nested: { a: 2, b: 2 } }
Add a second parameter path
to reduce the scope of the chained operations :
const o = { nested: { a: 2, b: 3 } }
chain(o, 'nested')
.add('a', 1)
.substract('b', 1)
.value() // => { nested: { a: 3, b: 2 } }
set
, update
and unset
into object
namespace.using
into util
namespaceWith pagination ?
JsDoc doesn't allow the creation of synonyms for a function.
JsDoc's @alias has been designed to "to treat all references to a member as if the member had a different name", but not rhe creation of synonyms.
lodash uses docdown, which has been tweaked to process @alias
as a list of synonyms.
All examples of the documentation should be runnable using runkit.
This is the case in lodash's documentation, I don't know how it is done.
Have the ability to reference a function regardless of the version.
For now the functions are organized in namespaces, and the namespace is part of the path in the URL :
https://zenika.github.io/immutadot/immutadot/0.2/array.html#concat
This forces to put also the version in the URL.
The namespace would be better placed in the hash of the URL, allowing shorter links :
https://zenika.github.io/immutadot#array.concat
Which would redirect to the latest version of the documentation.
Lodash uses @category
instead of @namespace
to do this.
Functions such as mapValues
, pickBy
, etc. are always converted with the exact same code.
It could be interesting to "automate" the conversion of such functions.
A prerequisite for the solution would be to keep the documentation as it is right now.
Avoid inline export default
// Do
const myFunc = ...
export default myFunc
// Instead of
export default ...
unshift
's jsdoc isn't appropriate. It is the one from push
Wrong test description for remove
feature
We are currently saving both npm 5 and yarn lock files in github.
For sure it is not realistic to ask of contributors to think of updating both these files when adding or upgrading dependencies.
There is currently a discussion at yarnpkg/yarn#3614 about supporting npm 5 package-lock.json
, which would be nice...
In the mean time, it seems there is no elegant way of dealing with this.
We could choose to keep only one of the lock files, but we can not make sure that contributors will use npm over yarn or yarn over npm.
Currently npm seems to suffer a minor drawback in comparison to yarn, related to unwanted updates to package-lock.json
when switching between Linux (or Windows !) and Mac npm/npm#17722, in particular with fsevents which is a Mac specific dependency.
@frinyvonnick Have you used npm 5 and experienced unwanted package-lock.json
updates on the project ?
Add a support file https://help.github.com/articles/adding-support-resources-to-your-project/
Use rollup ? Or webpack ?
When a new tag is created :
Add chain
allowing to do :
chain(object)
.set('nested.prop1', 'value')
.update('nested.prop2', value => value + 1)
.value()
differenceBy
differenceWith
dropRight
dropRightWhile
dropWhile
fill
intersection
intersectionBy
intersectionWith
pullAll
pullAllBy
pullAllWith
pullAt
reverse
slice
take
takeRight
takeRightWhile
takeWhile
union
unionBy
without -> pull
xor
xorBy
xorWith
Modify every element of the value like map
const result = map(object, 'props.values', val => val * val)
There is a typo in index.js file in string namespace. There is a z instead of a t in method name.
import { capizalize } from './capizalize'
import { replace } from './replace'
import { toLower } from './toLower'
import { toUpper } from './toUpper'
/**
* String functions.
* @namespace string
* @since 0.3.0
*/
export {
capizalize,
replace,
toLower,
toUpper,
}
Version : 3.0.0
New jsdoc version breaks documentation template
yarn docs
Use JsDoc @callback
to document predicates etc.
In order to avoid bugs such as #91, import tested functions from namespace instead of a direct import.
import { capitalize } from 'string'
instead of
import { capitalize } from './capitalize'
publish-docs.sh
should fail if one of its commands fails.
Add math.add based on lodash.add
Add non default exports and try to deprecate default exports.
const o = { nested: { a: 1, b: 2 } }
assign(o, 'nested', { b: 3, c: 4 }) // => { nested: { a:1, b: 3, c: 4 } }
Put back object.update
to its simple form.
Add util.convert(fn)
to replace object.update(fn)
Reintroduce trailing commas in functions as soon as JsDoc 3.5.0 is out.
See issue 1356 at JsDoc.
0.4 ?
Add a method to push into an array
newObject = push(object, 'props.array', value)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.