Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add core functions #165

Merged
merged 30 commits into from
Dec 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
5dc6db6
:sparkles: Add array.filter
nlepage Dec 14, 2017
480568b
:sparkles: Add array.map
nlepage Dec 14, 2017
237311a
:sparkles: Add array.pop
nlepage Dec 14, 2017
de91892
:bulb: Add array.map JSDoc
nlepage Dec 14, 2017
e2072cb
:sparkles: Add array.shift
nlepage Dec 14, 2017
11395a5
:sparkles: Add array.sort
nlepage Dec 14, 2017
e63e19b
:bulb: Update array functions JSDoc
nlepage Dec 14, 2017
37df6f3
:truck: Move math functions to lang
nlepage Dec 14, 2017
494b6be
:white_check_mark: Update array tests titles
nlepage Dec 14, 2017
ec8404b
:white_check_mark: Update tests titles to have namespace
nlepage Dec 14, 2017
741c100
:fire: Remove set, update and unset aliases from object
nlepage Dec 14, 2017
47e82ee
:recycle: Simplify namespaces indexes
nlepage Dec 14, 2017
75749b3
:recycle: Run number functions operands into Number
nlepage Dec 14, 2017
344c8b7
:bulb: Replace/remove lodash mentions
nlepage Dec 14, 2017
3427a45
:sparkles: Add string.concat
nlepage Dec 14, 2017
874f9c3
:recycle: Use convertStringMethod in string.replace
nlepage Dec 14, 2017
2639a05
:bug: Avoid name conflicts in flow
nlepage Dec 14, 2017
3e46bba
:rotating_light: fix linter error in flow generated files
nlepage Dec 14, 2017
6209b87
:rotating_light: fix linter error in flow generated files
nlepage Dec 14, 2017
574d51c
:sparkles: Add string.padEnd
nlepage Dec 14, 2017
8db4fd8
:sparkles: Add string.padStart
nlepage Dec 14, 2017
14cfdab
:sparkles: Add string.slice
nlepage Dec 14, 2017
34fec30
:sparkles: Add string.substr
nlepage Dec 14, 2017
e7764ca
:sparkles: Add string.substring
nlepage Dec 14, 2017
acc6a93
:sparkles: Add toLocaleLowerCase
nlepage Dec 14, 2017
5169da6
:sparkles: Add string.toLocaleUpperCase
nlepage Dec 14, 2017
affa012
:sparkles: Add string.toLowerCase and string.toUpperCase
nlepage Dec 14, 2017
03498c5
:sparkles: Add string.trim
nlepage Dec 14, 2017
1234b26
:sparkles: Add string.trimLeft and string.trimRight
nlepage Dec 14, 2017
68d40d0
:white_check_mark: fix tests
nlepage Dec 14, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions misc/generate-flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,19 @@ const generateFlow = async () => {

const nsItems = itemsByNamespace[namespace]

nsItems.forEach(async ({ name }) => await writeFile(
path.resolve(nsDir, `${name}.js`),
`import { ${name} } from '${namespace}/${name}'
await (async () => {
for (const { name } of nsItems) {
await writeFile(
path.resolve(nsDir, `${name}.js`),
`import { ${name} } from '${namespace}/${name}'

const { curried } = ${name}

export { curried as ${name} }
`,
))
)
}
})()

await writeFile(
path.resolve(nsDir, 'index.js'),
Expand All @@ -51,10 +55,19 @@ export { curried as ${name} }
)
}))

const exportedNames = new Set()
await writeFile(
path.resolve(flowDir, 'exports.js'),
`${namespaces.map(namespace => `export * from './${namespace}'`).join('\n')}
`${namespaces.map(namespace => {
const nsItems = itemsByNamespace[namespace].filter(({ name }) => !exportedNames.has(name))
nsItems.forEach(({ name }) => exportedNames.add(name))
/* eslint-disable */
return `export {
${nsItems.map(({ name }) => ` ${name},`).join('\n')}
} from './${namespace}'`
}).join('\n\n')}
`,
/* eslint-enable */
)
} catch (e) {
console.error(e) // eslint-disable-line no-console
Expand Down
5 changes: 3 additions & 2 deletions packages/immutadot/src/array/concat.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import { convertArrayMethod } from './convertArrayMethod'
* @param {...Array} arrays The arrays to concatenate.
* @return {Object} Returns the updated object.
* @example concat({ nested: { prop: [1, 2] } }, 'nested.prop', [3, 4]) // => { nested: { prop: [1, 2, 3, 4] } }
* @see {@link https://lodash.com/docs#concat|lodash.concat} for more information.
* @see {@link https://mdn.io/Array.prototype.concat|Array.prototype.concat} for more information.
* @since 0.2.0
* @flow
*/
const concat = convertArrayMethod('concat', false, true)
const concat = convertArrayMethod('concat', false)

export { concat }
2 changes: 1 addition & 1 deletion packages/immutadot/src/array/concat.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { concat } from 'array'
import { immutaTest } from 'test.utils'

describe('Concat', () => {
describe('array.concat', () => {

it('should concat an array', () => {
immutaTest((input, path) => {
Expand Down
3 changes: 2 additions & 1 deletion packages/immutadot/src/array/fill.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import { convertArrayMethod } from './convertArrayMethod'
* @param {number} [end=array.length]
* @return {Object} Returns the updated object.
* @example fill({ nested: { prop: [1, 2, 3, 4] } }, 'nested.prop', 6, 1, 3) // => { nested: { prop: [1, 6, 6, 4] } }
* @see {@link https://lodash.com/docs#fill|lodash.fill} for more information.
* @see {@link https://mdn.io/Array.prototype.fill|Array.prototype.fill} for more information.
* @since 0.3.0
* @flow
*/
const fill = convertArrayMethod('fill')

export { fill }
2 changes: 1 addition & 1 deletion packages/immutadot/src/array/fill.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { fill } from 'array'
import { immutaTest } from 'test.utils'

describe('Fill', () => {
describe('array.fill', () => {

it('should fill array with 6 from 1 to 3 excluded', () => {
immutaTest((input, path) => {
Expand Down
18 changes: 18 additions & 0 deletions packages/immutadot/src/array/filter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { convertArrayMethod } from './convertArrayMethod'

/**
* Replaces by an array of elements <code>predicate</code> returns truthy for.
* @function
* @memberof array
* @param {Object} object The object to modify.
* @param {Array|string} path The path of the property to set.
* @param {function} predicate The function invoked per iteration.
* @return {Object} Returns the updated object.
* @example filter({ nested: { prop: [1, 2, 3, 4] } }, 'nested.prop', v => v % 2) // => { nested: { prop: [1, 3] } }
* @see {@link https://mdn.io/Array.prototype.filter|Array.prototype.filter} for more information.
* @since 1.0.0
* @flow
*/
const filter = convertArrayMethod('filter', false)

export { filter }
36 changes: 36 additions & 0 deletions packages/immutadot/src/array/filter.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* eslint-env jest */
import { filter } from 'array'
import { immutaTest } from 'test.utils'

describe('array.filter', () => {

it('should filter elements', () => {
immutaTest((input, path) => {
const output = filter(input, path, v => v % 2 === 0)
expect(output).toEqual({
nested: { prop: [2, 4] },
other: {},
})
return output
}, {
nested: { prop: [1, 2, 3, 4] },
other: {},
}, 'nested.prop')
})

it('should replace deep undefined with array', () => {
immutaTest((input, path) => {
const output = filter(input, path, () => true)
expect(output).toEqual({ nested: { prop: [] } })
return output
}, undefined, 'nested.prop')
})

it('should wrap value in an array', () => {
immutaTest((input, path) => {
const output = filter(input, path, () => true)
expect(output).toEqual({ nested: { prop: [2] } })
return output
}, { nested: { prop: 2 } }, 'nested.prop')
})
})
30 changes: 13 additions & 17 deletions packages/immutadot/src/array/index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import { concat } from './concat'
import { fill } from './fill'
import { push } from './push'
import { reverse } from './reverse'
import { slice } from './slice'
import { splice } from './splice'
import { unshift } from './unshift'

/**
* Array functions.
* @namespace array
* @since 0.1.6
*/
export {
concat,
fill,
push,
reverse,
slice,
splice,
unshift,
}

export { filter } from './filter'
export { concat } from './concat'
export { fill } from './fill'
export { map } from './map'
export { pop } from './pop'
export { push } from './push'
export { reverse } from './reverse'
export { shift } from './shift'
export { slice } from './slice'
export { splice } from './splice'
export { sort } from './sort'
export { unshift } from './unshift'
18 changes: 18 additions & 0 deletions packages/immutadot/src/array/map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { convertArrayMethod } from './convertArrayMethod'

/**
* Replaces by an array of values by running each element in the former collection thru callback.
* @function
* @memberof array
* @param {Object} object The object to modify.
* @param {Array|string} path The path of the property to set.
* @param {function} callback The function invoked per iteration.
* @return {Object} Returns the updated object.
* @example map({ nested: { prop: [1, 2, 3] } }, 'nested.prop', v => v * 2) // => { nested: { prop: [2, 4, 6] } }
* @see {@link https://mdn.io/Array.prototype.map|Array.prototype.map} for more information.
* @since 1.0.0
* @flow
*/
const map = convertArrayMethod('map', false)

export { map }
36 changes: 36 additions & 0 deletions packages/immutadot/src/array/map.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* eslint-env jest */
import { immutaTest } from 'test.utils'
import { map } from 'array'

describe('array.map', () => {

it('should map elements', () => {
immutaTest((input, path) => {
const output = map(input, path, v => v * v)
expect(output).toEqual({
nested: { prop: [1, 4, 9, 16] },
other: {},
})
return output
}, {
nested: { prop: [1, 2, 3, 4] },
other: {},
}, 'nested.prop')
})

it('should replace deep undefined with array', () => {
immutaTest((input, path) => {
const output = map(input, path, v => v)
expect(output).toEqual({ nested: { prop: [] } })
return output
}, undefined, 'nested.prop')
})

it('should wrap value in an array', () => {
immutaTest((input, path) => {
const output = map(input, path, v => v * v)
expect(output).toEqual({ nested: { prop: [4] } })
return output
}, { nested: { prop: 2 } }, 'nested.prop')
})
})
17 changes: 17 additions & 0 deletions packages/immutadot/src/array/pop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { convertArrayMethod } from './convertArrayMethod'

/**
* Replaces by an array of elements with last element removed.
* @function
* @memberof array
* @param {Object} object The object to modify.
* @param {Array|string} path The path of the property to set.
* @return {Object} Returns the updated object.
* @example pop({ nested: { prop: [1, 2, 3, 4] } }, 'nested.prop') // => { nested: { prop: [1, 2, 3] } }
* @see {@link https://mdn.io/Array.prototype.pop|Array.prototype.pop} for more information.
* @since 1.0.0
* @flow
*/
const pop = convertArrayMethod('pop')

export { pop }
42 changes: 42 additions & 0 deletions packages/immutadot/src/array/pop.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* eslint-env jest */
import { immutaTest } from 'test.utils'
import { pop } from 'array'

describe('array.pop', () => {

it('should remove last element', () => {
immutaTest((input, path) => {
const output = pop(input, path)
expect(output).toEqual({
nested: { prop: [1, 2, 3] },
other: {},
})
return output
}, {
nested: { prop: [1, 2, 3, 4] },
other: {},
}, 'nested.prop')
})

it('should replace deep undefined with array', () => {
immutaTest((input, path) => {
const output = pop(input, path, () => true)
expect(output).toEqual({ nested: { prop: [] } })
return output
}, undefined, 'nested.prop')
})

it('should wrap value in array and remove it', () => {
immutaTest((input, path) => {
const output = pop(input, path)
expect(output).toEqual({
nested: { prop: [] },
other: {},
})
return output
}, {
nested: { prop: 123 },
other: {},
}, 'nested.prop')
})
})
1 change: 1 addition & 0 deletions packages/immutadot/src/array/push.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ import { convertArrayMethod } from './convertArrayMethod'
* @flow
*/
const push = convertArrayMethod('push')

export { push }
2 changes: 1 addition & 1 deletion packages/immutadot/src/array/push.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { immutaTest } from 'test.utils'
import { push } from 'array'

describe('Push', () => {
describe('array.push', () => {

it('should add one element', () => {
immutaTest((input, path) => {
Expand Down
3 changes: 2 additions & 1 deletion packages/immutadot/src/array/reverse.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import { convertArrayMethod } from './convertArrayMethod'
* @param {Array|string} path The path of the property to set.
* @return {Object} Returns the updated object.
* @example reverse({ nested: { prop: [1, 2, 3] } }, 'nested.prop') // => { nested: { prop: [3, 2, 1] } }
* @see {@link https://lodash.com/docs#reverse|lodash.reverse} for more information.
* @see {@link https://mdn.io/Array.prototype.reverse|Array.prototype.reverse} for more information..
* @since 0.3.0
* @flow
*/
const reverse = convertArrayMethod('reverse')

export { reverse }
2 changes: 1 addition & 1 deletion packages/immutadot/src/array/reverse.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { immutaTest } from 'test.utils'
import { reverse } from 'array'

describe('Reverse', () => {
describe('array.reverse', () => {

it('should reverse the elements', () => {
immutaTest((input, path) => {
Expand Down
17 changes: 17 additions & 0 deletions packages/immutadot/src/array/shift.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { convertArrayMethod } from './convertArrayMethod'

/**
* Replaces by an array of elements with first element removed.
* @function
* @memberof array
* @param {Object} object The object to modify.
* @param {Array|string} path The path of the property to set.
* @return {Object} Returns the updated object.
* @example shift({ nested: { prop: [1, 2, 3, 4] } }, 'nested.prop') // => { nested: { prop: [2, 3, 4] } }
* @see {@link https://mdn.io/Array.prototype.shift|Array.prototype.shift} for more information.
* @since 1.0.0
* @flow
*/
const shift = convertArrayMethod('shift')

export { shift }
42 changes: 42 additions & 0 deletions packages/immutadot/src/array/shift.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* eslint-env jest */
import { immutaTest } from 'test.utils'
import { shift } from 'array'

describe('array.shift', () => {

it('should remove first element', () => {
immutaTest((input, path) => {
const output = shift(input, path)
expect(output).toEqual({
nested: { prop: [2, 3, 4] },
other: {},
})
return output
}, {
nested: { prop: [1, 2, 3, 4] },
other: {},
}, 'nested.prop')
})

it('should replace deep undefined with array', () => {
immutaTest((input, path) => {
const output = shift(input, path, () => true)
expect(output).toEqual({ nested: { prop: [] } })
return output
}, undefined, 'nested.prop')
})

it('should wrap value in array and remove it', () => {
immutaTest((input, path) => {
const output = shift(input, path)
expect(output).toEqual({
nested: { prop: [] },
other: {},
})
return output
}, {
nested: { prop: 123 },
other: {},
}, 'nested.prop')
})
})
Loading