Skip to content
This repository has been archived by the owner on Jan 6, 2025. It is now read-only.

Commit

Permalink
🚚 Create path namespace fix #147 (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
nlepage authored Dec 7, 2017
1 parent 3756f33 commit 4de1876
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 34 deletions.
2 changes: 1 addition & 1 deletion packages/immutadot/src/core/convert.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { apply } from './apply'
import { apply } from 'path/apply'

const makeOperation = updater => (obj, prop, value, ...args) => { obj[prop] = updater(value, ...args) }

Expand Down
2 changes: 1 addition & 1 deletion packages/immutadot/src/core/get.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isNil } from 'util/lang'
import { unsafeToPath } from './toPath'
import { unsafeToPath } from 'path/toPath'

/**
* Gets the value at <code>path</code> of <code>obj</code>.
Expand Down
1 change: 0 additions & 1 deletion packages/immutadot/src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
export { convert } from './convert'
export { get } from './get'
export { set } from './set'
export { toPath } from './toPath'
export { unset } from './unset'
export { update } from './update'
2 changes: 1 addition & 1 deletion packages/immutadot/src/core/set.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { apply } from './apply'
import { apply } from 'path/apply'

const setOperation = (obj, prop, _, value) => { obj[prop] = value }

Expand Down
2 changes: 1 addition & 1 deletion packages/immutadot/src/core/unset.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { apply } from './apply'
import { apply } from 'path/apply'

const unsetOperation = (obj, prop) => { delete obj[prop] }

Expand Down
2 changes: 1 addition & 1 deletion packages/immutadot/src/core/update.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { apply } from './apply'
import { apply } from 'path/apply'

const updateOperation = (obj, prop, value, updater, ...args) => { obj[prop] = updater(value, ...args) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { unsafeToPath } from './toPath'
* @param {*} value The value to make a copy of
* @param {boolean} asArray The value should be copied as an array
* @returns {Object|Array} A copy of value
* @memberof core
* @memberof path
* @private
* @since 1.0.0
*/
Expand Down Expand Up @@ -48,7 +48,7 @@ const copyIfNecessary = (value, prop, doCopy) => {

/**
* Operation to apply on a nested property of an object, to be called by {@link core.apply|apply}.
* @memberof core
* @memberof path
* @callback operation
* @param {*} obj The last nested object
* @param {string|number} prop The prop of the last nested object
Expand All @@ -60,7 +60,7 @@ const copyIfNecessary = (value, prop, doCopy) => {

/**
* A function able to apply an {@link core.operation|operation} on a nested property of an object, returned by {@link core.apply|apply}.
* @memberof core
* @memberof path
* @callback appliedOperation
* @param {*} obj The last nested object
* @param {string} path The prop of the last nested object
Expand All @@ -72,7 +72,7 @@ const copyIfNecessary = (value, prop, doCopy) => {

/**
* Creates a function able to apply <code>operation</code> on a nested property.
* @memberof core
* @memberof path
* @function
* @param {core.operation} operation The operation to apply
* @returns {core.appliedOperation} A function able to apply <code>operation</code>
Expand Down
7 changes: 7 additions & 0 deletions packages/immutadot/src/path/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Path functions.
* @namespace path
* @since 1.0.0
*/

export { toPath } from './toPath'
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @typedef {function(string): T | null} Parser<T>
* @memberof core
* @memberof path
* @private
* @since 1.0.0
*/
Expand All @@ -11,7 +11,7 @@ const maybeMap = (maybe, fn) => maybe === null ? maybe : fn(maybe)
* Creates a parser from a regular expression by matching the input string with
* the regular expression, returning the resulting match object.
* @function
* @memberof core
* @memberof path
* @param {RegExp} regexp the regular expression
* @return {core.Parser<string[]>} the resulting parser
* @private
Expand All @@ -24,7 +24,7 @@ export const regexp = regexp => str => maybeMap(str.match(regexp), match => matc
* the result of another parser does not hold. If the predicate holds then
* the new parser returns the result of the other parser unchanged.
* @function
* @memberof core
* @memberof path
* @param {core.Parser<T>} parser parser to filter
* @param {function(*): boolean} predicate predicate to use
* @return {core.Parser<T>} resulting parser
Expand All @@ -36,7 +36,7 @@ export const filter = (parser, predicate) => str => maybeMap(parser(str), parsed
/**
* Returns a new parser which will post-process the result of another parser.
* @function
* @memberof core
* @memberof path
* @param {core.Parser<T>} parser parser for which to process the result
* @param {function(T): R} mapper function to transform the result of the parser
* @return {core.Parser<R>} resulting parser
Expand All @@ -49,7 +49,7 @@ export const map = (parser, mapper) => str => maybeMap(parser(str), mapper)
* Returns a new parser that attempts parsing with a first parser then falls
* back to a second parser if the first returns <code>null</code>.
* @function
* @memberof core
* @memberof path
* @param {core.Parser<A>} parser the first parser
* @param {core.Parser<B>} other the second parser
* @return {core.Parser<A | B>} resulting parser
Expand All @@ -65,7 +65,7 @@ export const fallback = (parser, other) => str => {
/**
* Chains a list of parsers together using <code>fallback</code>.
* @function
* @memberof core
* @memberof path
* @param {Array<core.Parser<*>>} parsers a list of parsers to try in order
* @return {core.Parser<*>} resulting parser
* @private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const getSliceBound = (value, defaultValue, length) => {
/**
* Get the actual bounds of a slice.
* @function
* @memberof core
* @memberof path
* @param {Array<number>} bounds The bounds of the slice
* @param {number} length The length of the actual array
* @returns {Array<number>} The actual bounds of the slice
Expand All @@ -26,7 +26,7 @@ export const getSliceBounds = ([start, end], length) => ([
/**
* This is an alias for {@link util/isNaturalInteger}.
* @function
* @memberof core
* @memberof path
* @private
* @since 1.0.0
*/
Expand All @@ -37,7 +37,7 @@ export const isIndex = isNaturalInteger
* @function
* @param {*} arg The value to test
* @return {boolean} True if <code>arg</code> is a valid slice index, false otherwise
* @memberof core
* @memberof path
* @private
* @since 1.0.0
*/
Expand All @@ -48,7 +48,7 @@ export const isSliceIndex = arg => arg === undefined || Number.isSafeInteger(arg
* @function
* @param {*} arg The value to test
* @return {boolean} True if <code>arg</code> is a slice, false otherwise
* @memberof core
* @memberof path
* @private
* @since 1.0.0
*/
Expand All @@ -63,7 +63,7 @@ export const isSlice = arg => {
* @param {Array} path The path to test.
* @param {Array} pAppliedPaths Already applied paths.
* @returns {boolean} <code>true></code> if <code>path</code> has already been applied, <code>false</code> otherwise.
* @memberof core
* @memberof path
* @private
* @since 1.0.0
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
* @function
* @param {*} arg The value to convert
* @return {string} A valid path key
* @memberof core
* @memberof path
* @private
* @since 1.0.0
*/
Expand All @@ -39,7 +39,7 @@ const toKey = arg => {
* @param {string} str The string
* @param {string} quote The quote to unescape
* @return {string} The unescaped string
* @memberof core
* @memberof path
* @private
* @since 1.0.0
*/
Expand All @@ -50,7 +50,7 @@ const unescapeQuotes = (str, quote) => str.replace(new RegExp(`\\\\${quote}`, 'g
* @function
* @param {string} str The string to convert
* @return {number} <code>undefined</code> if <code>str</code> is empty, otherwise an int (may be NaN)
* @memberof core
* @memberof path
* @private
* @since 1.0.0
*/
Expand All @@ -59,7 +59,7 @@ const toSliceIndex = str => str === '' ? undefined : Number(str)
/**
* Tests whether <code>arg</code> is a valid slice index, that is <code>undefined</code> or a valid int.
* @function
* @memberof core
* @memberof path
* @param {*} arg The value to test
* @return {boolean} True if <code>arg</code> is a valid slice index, false otherwise.
* @private
Expand All @@ -70,7 +70,7 @@ const isSliceIndex = arg => arg === undefined || Number.isSafeInteger(arg)
/**
* Tests whether <code>arg</code> is a valid slice index once converted to a number.
* @function
* @memberof core
* @memberof path
* @param {*} arg The value to test
* @return {boolean} True if <code>arg</code> is a valid slice index once converted to a number, false otherwise.
* @private
Expand All @@ -86,7 +86,7 @@ const isSliceIndexString = arg => isSliceIndex(arg ? Number(arg) : undefined)
* @function
* @param {function} fn The function to wrap
* @return {function} The wrapper function
* @memberof core
* @memberof path
* @private
* @since 1.0.0
*/
Expand Down Expand Up @@ -156,7 +156,7 @@ const applyParsers = race([
* @function
* @param {*} arg The value to convert
* @return {Array<string|number|Array>} The path represented as an array of keys
* @memberof core
* @memberof path
* @private
* @since 1.0.0
*/
Expand All @@ -174,7 +174,7 @@ const cache = new Map()
* @function
* @param {string} str The string to convert
* @return {Array<string|number|Array>} The path represented as an array of keys
* @memberof core
* @memberof path
* @private
* @since 1.0.0
*/
Expand All @@ -198,7 +198,7 @@ const memoizedStringToPath = str => {
* @function
* @param {string|Array|*} arg The value to convert
* @return {Array<string|number|Array>} The path represented as an array of keys
* @memberof core
* @memberof path
* @since 1.0.0
* @example toPath('a.b[1]["."][1:-1]') // => ['a', 'b', 1, '.', [1, -1]]
*/
Expand All @@ -209,7 +209,7 @@ const toPath = allowingArrays(arg => [...memoizedStringToPath(arg)])
* @function
* @param {string|Array|*} arg The value to convert
* @return {Array<string|number|Array>} The path represented as an array of keys
* @memberof core
* @memberof path
* @since 1.0.0
* @private
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-env jest */
import { toPath } from 'core'
import { toPath } from 'path'

describe('ToPath', () => {

Expand Down
4 changes: 2 additions & 2 deletions packages/immutadot/src/seq/ChainWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as math from 'math'
import * as object from 'object'
import * as string from 'string'

import { unsafeToPath } from 'core/toPath'
import { unsafeToPath } from 'path/toPath'

/**
* Wrapper allowing to make sequences of immutadot functions calls on an object.<br/>
Expand Down Expand Up @@ -118,7 +118,7 @@ class ChainWrapper {
*/

// Add namespaces functions to the ChainWrapper prototype
const { convert, toPath, ...filteredCore } = core // eslint-disable-line no-unused-vars
const { convert, ...filteredCore } = core // eslint-disable-line no-unused-vars
const { set, unset, update, ...filteredObject } = object // eslint-disable-line no-unused-vars
const namespaces = [
array,
Expand Down

0 comments on commit 4de1876

Please sign in to comment.