From 4de1876be36b869b1d3f4bf69a7db878dfe770e6 Mon Sep 17 00:00:00 2001
From: Nicolas Lepage <19571875+nlepage@users.noreply.github.com>
Date: Thu, 7 Dec 2017 15:44:30 +0100
Subject: [PATCH] :truck: Create path namespace fix #147 (#155)
---
packages/immutadot/src/core/convert.js | 2 +-
packages/immutadot/src/core/get.js | 2 +-
packages/immutadot/src/core/index.js | 1 -
packages/immutadot/src/core/set.js | 2 +-
packages/immutadot/src/core/unset.js | 2 +-
packages/immutadot/src/core/update.js | 2 +-
.../immutadot/src/{core => path}/apply.js | 8 ++++----
.../src/{core => path}/apply.spec.js | 0
packages/immutadot/src/path/index.js | 7 +++++++
.../src/{core => path}/parser.utils.js | 12 +++++------
.../src/{core => path}/path.utils.js | 10 +++++-----
.../src/{core => path}/path.utils.spec.js | 0
.../immutadot/src/{core => path}/toPath.js | 20 +++++++++----------
.../src/{core => path}/toPath.spec.js | 2 +-
packages/immutadot/src/seq/ChainWrapper.js | 4 ++--
15 files changed, 40 insertions(+), 34 deletions(-)
rename packages/immutadot/src/{core => path}/apply.js (98%)
rename packages/immutadot/src/{core => path}/apply.spec.js (100%)
create mode 100644 packages/immutadot/src/path/index.js
rename packages/immutadot/src/{core => path}/parser.utils.js (95%)
rename packages/immutadot/src/{core => path}/path.utils.js (96%)
rename packages/immutadot/src/{core => path}/path.utils.spec.js (100%)
rename packages/immutadot/src/{core => path}/toPath.js (97%)
rename packages/immutadot/src/{core => path}/toPath.spec.js (98%)
diff --git a/packages/immutadot/src/core/convert.js b/packages/immutadot/src/core/convert.js
index e703ecbe..fec91011 100644
--- a/packages/immutadot/src/core/convert.js
+++ b/packages/immutadot/src/core/convert.js
@@ -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) }
diff --git a/packages/immutadot/src/core/get.js b/packages/immutadot/src/core/get.js
index e9a10f8b..a6450523 100644
--- a/packages/immutadot/src/core/get.js
+++ b/packages/immutadot/src/core/get.js
@@ -1,5 +1,5 @@
import { isNil } from 'util/lang'
-import { unsafeToPath } from './toPath'
+import { unsafeToPath } from 'path/toPath'
/**
* Gets the value at path
of obj
.
diff --git a/packages/immutadot/src/core/index.js b/packages/immutadot/src/core/index.js
index 090aec99..ad8bb678 100644
--- a/packages/immutadot/src/core/index.js
+++ b/packages/immutadot/src/core/index.js
@@ -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'
diff --git a/packages/immutadot/src/core/set.js b/packages/immutadot/src/core/set.js
index 328c39f7..a5f5dfad 100644
--- a/packages/immutadot/src/core/set.js
+++ b/packages/immutadot/src/core/set.js
@@ -1,4 +1,4 @@
-import { apply } from './apply'
+import { apply } from 'path/apply'
const setOperation = (obj, prop, _, value) => { obj[prop] = value }
diff --git a/packages/immutadot/src/core/unset.js b/packages/immutadot/src/core/unset.js
index 2c43553d..c68e5864 100644
--- a/packages/immutadot/src/core/unset.js
+++ b/packages/immutadot/src/core/unset.js
@@ -1,4 +1,4 @@
-import { apply } from './apply'
+import { apply } from 'path/apply'
const unsetOperation = (obj, prop) => { delete obj[prop] }
diff --git a/packages/immutadot/src/core/update.js b/packages/immutadot/src/core/update.js
index 1b8ab337..4df4a9c3 100644
--- a/packages/immutadot/src/core/update.js
+++ b/packages/immutadot/src/core/update.js
@@ -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) }
diff --git a/packages/immutadot/src/core/apply.js b/packages/immutadot/src/path/apply.js
similarity index 98%
rename from packages/immutadot/src/core/apply.js
rename to packages/immutadot/src/path/apply.js
index ff8d1a5c..a3121c6d 100644
--- a/packages/immutadot/src/core/apply.js
+++ b/packages/immutadot/src/path/apply.js
@@ -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
*/
@@ -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
@@ -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
@@ -72,7 +72,7 @@ const copyIfNecessary = (value, prop, doCopy) => {
/**
* Creates a function able to apply operation
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 operation
diff --git a/packages/immutadot/src/core/apply.spec.js b/packages/immutadot/src/path/apply.spec.js
similarity index 100%
rename from packages/immutadot/src/core/apply.spec.js
rename to packages/immutadot/src/path/apply.spec.js
diff --git a/packages/immutadot/src/path/index.js b/packages/immutadot/src/path/index.js
new file mode 100644
index 00000000..19fd7e9e
--- /dev/null
+++ b/packages/immutadot/src/path/index.js
@@ -0,0 +1,7 @@
+/**
+* Path functions.
+* @namespace path
+* @since 1.0.0
+*/
+
+export { toPath } from './toPath'
diff --git a/packages/immutadot/src/core/parser.utils.js b/packages/immutadot/src/path/parser.utils.js
similarity index 95%
rename from packages/immutadot/src/core/parser.utils.js
rename to packages/immutadot/src/path/parser.utils.js
index 3754f2ca..d919b1a2 100644
--- a/packages/immutadot/src/core/parser.utils.js
+++ b/packages/immutadot/src/path/parser.utils.js
@@ -1,6 +1,6 @@
/**
* @typedef {function(string): T | null} Parser
- * @memberof core
+ * @memberof path
* @private
* @since 1.0.0
*/
@@ -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} the resulting parser
* @private
@@ -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} parser parser to filter
* @param {function(*): boolean} predicate predicate to use
* @return {core.Parser} resulting parser
@@ -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} parser parser for which to process the result
* @param {function(T): R} mapper function to transform the result of the parser
* @return {core.Parser} resulting parser
@@ -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 null
.
* @function
- * @memberof core
+ * @memberof path
* @param {core.Parser} parser the first parser
* @param {core.Parser} other the second parser
* @return {core.Parser} resulting parser
@@ -65,7 +65,7 @@ export const fallback = (parser, other) => str => {
/**
* Chains a list of parsers together using fallback
.
* @function
- * @memberof core
+ * @memberof path
* @param {Array>} parsers a list of parsers to try in order
* @return {core.Parser<*>} resulting parser
* @private
diff --git a/packages/immutadot/src/core/path.utils.js b/packages/immutadot/src/path/path.utils.js
similarity index 96%
rename from packages/immutadot/src/core/path.utils.js
rename to packages/immutadot/src/path/path.utils.js
index 5f50b373..ce007a92 100644
--- a/packages/immutadot/src/core/path.utils.js
+++ b/packages/immutadot/src/path/path.utils.js
@@ -11,7 +11,7 @@ export const getSliceBound = (value, defaultValue, length) => {
/**
* Get the actual bounds of a slice.
* @function
- * @memberof core
+ * @memberof path
* @param {Array} bounds The bounds of the slice
* @param {number} length The length of the actual array
* @returns {Array} The actual bounds of the slice
@@ -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
*/
@@ -37,7 +37,7 @@ export const isIndex = isNaturalInteger
* @function
* @param {*} arg The value to test
* @return {boolean} True if arg
is a valid slice index, false otherwise
- * @memberof core
+ * @memberof path
* @private
* @since 1.0.0
*/
@@ -48,7 +48,7 @@ export const isSliceIndex = arg => arg === undefined || Number.isSafeInteger(arg
* @function
* @param {*} arg The value to test
* @return {boolean} True if arg
is a slice, false otherwise
- * @memberof core
+ * @memberof path
* @private
* @since 1.0.0
*/
@@ -63,7 +63,7 @@ export const isSlice = arg => {
* @param {Array} path The path to test.
* @param {Array} pAppliedPaths Already applied paths.
* @returns {boolean} true>
if path
has already been applied, false
otherwise.
- * @memberof core
+ * @memberof path
* @private
* @since 1.0.0
*/
diff --git a/packages/immutadot/src/core/path.utils.spec.js b/packages/immutadot/src/path/path.utils.spec.js
similarity index 100%
rename from packages/immutadot/src/core/path.utils.spec.js
rename to packages/immutadot/src/path/path.utils.spec.js
diff --git a/packages/immutadot/src/core/toPath.js b/packages/immutadot/src/path/toPath.js
similarity index 97%
rename from packages/immutadot/src/core/toPath.js
rename to packages/immutadot/src/path/toPath.js
index 51bc7120..f39d40f4 100644
--- a/packages/immutadot/src/core/toPath.js
+++ b/packages/immutadot/src/path/toPath.js
@@ -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
*/
@@ -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
*/
@@ -50,7 +50,7 @@ const unescapeQuotes = (str, quote) => str.replace(new RegExp(`\\\\${quote}`, 'g
* @function
* @param {string} str The string to convert
* @return {number} undefined
if str
is empty, otherwise an int (may be NaN)
- * @memberof core
+ * @memberof path
* @private
* @since 1.0.0
*/
@@ -59,7 +59,7 @@ const toSliceIndex = str => str === '' ? undefined : Number(str)
/**
* Tests whether arg
is a valid slice index, that is undefined
or a valid int.
* @function
- * @memberof core
+ * @memberof path
* @param {*} arg The value to test
* @return {boolean} True if arg
is a valid slice index, false otherwise.
* @private
@@ -70,7 +70,7 @@ const isSliceIndex = arg => arg === undefined || Number.isSafeInteger(arg)
/**
* Tests whether arg
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 arg
is a valid slice index once converted to a number, false otherwise.
* @private
@@ -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
*/
@@ -156,7 +156,7 @@ const applyParsers = race([
* @function
* @param {*} arg The value to convert
* @return {Array} The path represented as an array of keys
- * @memberof core
+ * @memberof path
* @private
* @since 1.0.0
*/
@@ -174,7 +174,7 @@ const cache = new Map()
* @function
* @param {string} str The string to convert
* @return {Array} The path represented as an array of keys
- * @memberof core
+ * @memberof path
* @private
* @since 1.0.0
*/
@@ -198,7 +198,7 @@ const memoizedStringToPath = str => {
* @function
* @param {string|Array|*} arg The value to convert
* @return {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]]
*/
@@ -209,7 +209,7 @@ const toPath = allowingArrays(arg => [...memoizedStringToPath(arg)])
* @function
* @param {string|Array|*} arg The value to convert
* @return {Array} The path represented as an array of keys
- * @memberof core
+ * @memberof path
* @since 1.0.0
* @private
*/
diff --git a/packages/immutadot/src/core/toPath.spec.js b/packages/immutadot/src/path/toPath.spec.js
similarity index 98%
rename from packages/immutadot/src/core/toPath.spec.js
rename to packages/immutadot/src/path/toPath.spec.js
index 7813a01f..3845dc47 100644
--- a/packages/immutadot/src/core/toPath.spec.js
+++ b/packages/immutadot/src/path/toPath.spec.js
@@ -1,5 +1,5 @@
/* eslint-env jest */
-import { toPath } from 'core'
+import { toPath } from 'path'
describe('ToPath', () => {
diff --git a/packages/immutadot/src/seq/ChainWrapper.js b/packages/immutadot/src/seq/ChainWrapper.js
index db5315e0..cd1f5ae0 100644
--- a/packages/immutadot/src/seq/ChainWrapper.js
+++ b/packages/immutadot/src/seq/ChainWrapper.js
@@ -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.
@@ -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,