diff --git a/misc/generate-flow.js b/misc/generate-flow.js index ba583ced..e9934247 100644 --- a/misc/generate-flow.js +++ b/misc/generate-flow.js @@ -39,6 +39,16 @@ const generateFlow = async () => { const namespaces = _.keys(itemsByNamespace) + const conflicts = _.chain(items) + .filter('flow') + .reduce((acc, { name }) => ({ + ...acc, + [name]: acc[name] !== undefined, + }), {}) + .pickBy() + .keys() + .value() + await Promise.all(namespaces.map(async namespace => { const nsDir = path.resolve(flowDir, namespace) await ensureDir(nsDir) @@ -66,15 +76,13 @@ export { curried as ${name} } ) })) - const exportedNames = new Set() await writeFile( path.resolve(flowDir, 'exports.js'), `${namespaces.map(namespace => { - const nsItems = itemsByNamespace[namespace].filter(({ name }) => !exportedNames.has(name)) - nsItems.forEach(({ name }) => exportedNames.add(name)) + const nsItems = itemsByNamespace[namespace] /* eslint-disable comma-spacing,indent */ return `export { -${nsItems.map(({ name }) => ` ${name},`).join('\n')} +${nsItems.map(({ name }) => ` ${name}${conflicts.includes(name) ? ` as ${namespace}${_.capitalize(name)}` : ''},`).join('\n')} } from './${namespace}'` }).join('\n\n')} `, /* eslint-enable */ @@ -100,6 +108,21 @@ ChainWrapper.prototype.${name} = function(path, ...args) { } `, /* eslint-enable */ ) + + if (conflicts.includes(name)) { + await writeFile( + path.resolve(nsDir, `${name}.ns.js`), + /* eslint-disable indent */ +`import { ChainWrapper } from '${external ? 'immutadot/' : ''}seq/ChainWrapper' + +import { ${name} } from '${namespace}/${name}' + +ChainWrapper.prototype.${namespace}${_.capitalize(name)} = function(path, ...args) { + return this._call(${name}, path, args) +} +`, /* eslint-enable */ + ) + } } })() @@ -107,6 +130,13 @@ ChainWrapper.prototype.${name} = function(path, ...args) { path.resolve(nsDir, 'index.js'), /* eslint-disable indent */ `${nsItems.map(({ name }) => `import './${name}'`).join('\n')} +`, /* eslint-enable */ + ) + + await writeFile( + path.resolve(nsDir, 'ns.js'), + /* eslint-disable indent */ +`${nsItems.map(({ name }) => `import './${name}${conflicts.includes(name) ? '.ns' : ''}'`).join('\n')} `, /* eslint-enable */ ) })) @@ -114,7 +144,7 @@ ChainWrapper.prototype.${name} = function(path, ...args) { await writeFile( path.resolve(seqDir, 'all.js'), /* eslint-disable indent */ - `${namespaces.map(namespace => `import './${namespace}'`).join('\n')} + `${namespaces.map(namespace => `import './${namespace}/ns'`).join('\n')} `, /* eslint-enable */ ) } catch (e) { diff --git a/packages/immutadot/src/array/concat.js b/packages/immutadot/src/array/concat.js index 200dacbb..0182f440 100644 --- a/packages/immutadot/src/array/concat.js +++ b/packages/immutadot/src/array/concat.js @@ -1,7 +1,8 @@ import { convertArrayMethod } from './convertArrayMethod' /** - * Replaces an array concatenating the former array with additional arrays and/or values. + * Replaces an array concatenating the former array with additional arrays and/or values.
+ * ⚠ Due to name conflicts, this function is named arrayConcat when imported from top level (import { arrayConcat } from 'immutadot'). * @function * @memberof array * @param {Object} object The object to modify. diff --git a/packages/immutadot/src/array/slice.js b/packages/immutadot/src/array/slice.js index 8f61cacc..712c5999 100644 --- a/packages/immutadot/src/array/slice.js +++ b/packages/immutadot/src/array/slice.js @@ -1,7 +1,8 @@ import { convertArrayMethod } from './convertArrayMethod' /** - * Replaces an array by a slice of the former array from start up to, but not including, end. + * Replaces an array by a slice of the former array from start up to, but not including, end.
+ * ⚠ Due to name conflicts, this function is named arraySlice when imported from top level (import { arraySlice } from 'immutadot'). * @function * @memberof array * @param {Object} object The object to modify. diff --git a/packages/immutadot/src/index.js b/packages/immutadot/src/index.js index c5fb0780..e5f99c36 100644 --- a/packages/immutadot/src/index.js +++ b/packages/immutadot/src/index.js @@ -1,7 +1,35 @@ -export * from './array' +export { + concat as arrayConcat, + fill, + filter, + map, + pop, + push, + reverse, + shift, + slice as arraySlice, + sort, + splice, + unshift, +} from './array' export * from './core' export * from './lang' export * from './object' export * from './seq' -export * from './string' +export { + concat as stringConcat, + padEnd, + padStart, + replace, + slice as stringSlice, + substr, + substring, + toLocaleLowerCase, + toLocaleUpperCase, + toLowerCase, + toUpperCase, + trim, + trimLeft, + trimRight, +} from './string' export * from './util' diff --git a/packages/immutadot/src/string/concat.js b/packages/immutadot/src/string/concat.js index 674a4267..d4fd4403 100644 --- a/packages/immutadot/src/string/concat.js +++ b/packages/immutadot/src/string/concat.js @@ -1,7 +1,8 @@ import { convertStringMethod } from './convertStringMethod' /** - * Replaces by former string concatenated with strings. + * Replaces by former string concatenated with strings.
+ * ⚠ Due to name conflicts, this function is named stringConcat when imported from top level (import { stringConcat } from 'immutadot'). * @function * @memberof string * @param {Object} object The object to modify. diff --git a/packages/immutadot/src/string/slice.js b/packages/immutadot/src/string/slice.js index 29eb5063..3817be14 100644 --- a/packages/immutadot/src/string/slice.js +++ b/packages/immutadot/src/string/slice.js @@ -1,7 +1,8 @@ import { convertStringMethod } from './convertStringMethod' /** - * Replaces by a slice of former string starting at beginIndex and ending at endIndex or end of the string. + * Replaces by a slice of former string starting at beginIndex and ending at endIndex or end of the string.
+ * ⚠ Due to name conflicts, this function is named stringSlice when imported from top level (import { stringSlice } from 'immutadot'). * @function * @memberof string * @param {Object} object The object to modify.