@lumjs/core 1.0.0-beta.4 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/obj/clone.js CHANGED
@@ -19,6 +19,7 @@ const copyProps = require('./copyprops');
19
19
  * | `CLONE.ENTIRE` | ✓ | × | ✓ | |
20
20
  * | `CLONE.JSON` | × | × | ✓ | Uses JSON, so no `function` or `symbol` support. |
21
21
  *
22
+ * @alias module:@lumjs/core/obj.CLONE
22
23
  */
23
24
  const CLONE = Enum(['DEF','FULL','ALL','DEEP','ENTIRE','JSON']);
24
25
 
@@ -43,25 +44,26 @@ const copyProps = require('./copyprops');
43
44
  *
44
45
  * Note: The `CLONE` enum is also aliased as `clone.MODE` as an alternative.
45
46
  *
46
- * @param {boolean} [opts.addClone=false] - Call {@link Lum._.addClone} on the cloned object.
47
+ * @param {boolean} [opts.addClone=false] - Call `addClone()` on the cloned object.
47
48
  *
48
49
  * The options sent to this function will be used as the defaults in
49
- * the clone() method added to the object.
50
+ * the `clone()` method added to the object.
50
51
  *
51
- * @param {boolean} [opts.addLock=false] - Call {@link Lum._.addLock} on the cloned object.
52
+ * @param {boolean} [opts.addLock=false] - Call `addLock()` on the cloned object.
52
53
  *
53
- * No further options for this, just add a lock() method to the clone.
54
+ * No further options for this, just add a `lock()` method to the clone.
54
55
  *
55
- * @param {?object} [opts.copy] Call {@link Lum._.copy} on the cloned object.
56
+ * @param {?object} [opts.copy] Call `copyProps()` on the cloned object.
56
57
  *
57
58
  * Will pass the original `obj` as the source to copy from.
58
59
  * Will pass `opts.copy` as the options.
59
60
  *
60
61
  * @return {object} - The clone of the object.
62
+ * @alias module:@lumjs/core/obj.clone
61
63
  */
62
64
  function clone(obj, opts={})
63
65
  {
64
- //console.debug("Lum~clone()", obj, opts);
66
+ //console.debug("clone()", obj, opts);
65
67
 
66
68
  if (!isComplex(obj))
67
69
  { // Doesn't need cloning.
@@ -156,7 +158,7 @@ exports.clone = clone;
156
158
  *
157
159
  * ```{mode: CLONE.DEF, addClone: true, addLock: false}```
158
160
  *
159
- * @method Lum._.addClone
161
+ * @alias module:@lumjs/core/obj.addClone
160
162
  */
161
163
  function addClone(obj, defOpts=null)
162
164
  {
@@ -185,14 +187,14 @@ exports.addClone = addClone;
185
187
  * If the object is extensible, it's returned as is.
186
188
  *
187
189
  * If not, if the object has a `clone()` method it will be used.
188
- * Otherwise use the {@link Lum._.clone} method.
190
+ * Otherwise use our `clone()` function.
189
191
  *
190
192
  * @param {object} obj - The object to clone if needed.
191
193
  * @param {object} [opts] - Options to pass to `clone()` method.
192
194
  *
193
195
  * @return {object} - Either the original object, or an extensible clone.
194
196
  *
195
- * @method Lum._.cloneIfLocked
197
+ * @alias module:@lumjs/core/obj.cloneIfLocked
196
198
  */
197
199
  function cloneIfLocked(obj, opts)
198
200
  {
@@ -3,6 +3,8 @@
3
3
  *
4
4
  * It does no type checking, and has no qualms about overwriting properties.
5
5
  * You probably want something like `copyProps` instead.
6
+ *
7
+ * @alias module:@lumjs/core/obj.copyAll
6
8
  */
7
9
  function copyAll(target, ...sources)
8
10
  {
@@ -13,6 +15,7 @@ function copyAll(target, ...sources)
13
15
  target[name] = source[name];
14
16
  }
15
17
  }
18
+ return target;
16
19
  }
17
20
 
18
21
  module.exports = copyAll;
@@ -23,6 +23,7 @@ const {B,isObj,isComplex,isArray,def: defProp} = require('../types');
23
23
  * if that property can be overwritten or not.
24
24
  *
25
25
  * @returns {object} The `target` object.
26
+ * @alias module:@lumjs/core/obj.copyProps
26
27
  */
27
28
  function copyProps(source, target, propOpts)
28
29
  {
@@ -0,0 +1,38 @@
1
+ const types = require('../types');
2
+ const {isComplex,isObj} = types;
3
+
4
+ /**
5
+ * Get a property descriptor.
6
+ *
7
+ * This is like `Object.getOwnPropertyDescriptor`, except that method
8
+ * fails if the property is inhereted. This method will travel through
9
+ * the entire prototype chain until it finds the descriptor.
10
+ *
11
+ * @param {object|function} obj - Object to find a property in.
12
+ * @param {string} prop - Name of the property we want the descriptor of.
13
+ * @param {mixed} [defval] The fallback value if no descriptor is found.
14
+ *
15
+ * @returns {mixed} - The descriptor if found, `defval` if not.
16
+ */
17
+ function getProperty(obj, prop, defval)
18
+ {
19
+ if (!isComplex(obj)) throw new TypeError("Target must be an object or function");
20
+ // Yeah it looks like an infinite loop, but it's not.
21
+ while (true)
22
+ {
23
+ const desc = Object.getOwnPropertyDescriptor(obj, prop);
24
+ if (isObj(desc))
25
+ { // Found it.
26
+ return desc;
27
+ }
28
+
29
+ // Didn't find it, so let's try the next object in the prototype chain.
30
+ obj = Object.getPrototypeOf(obj);
31
+ if (!isComplex(obj))
32
+ { // We've gone as far up the prototype chain as we can, bye now!
33
+ return defval;
34
+ }
35
+ }
36
+ }
37
+
38
+ module.exports = getProperty;
package/lib/obj/index.js CHANGED
@@ -1,7 +1,7 @@
1
- // Object helper utilities.
2
- // We *could* use `copyAll` to simply merge everything in here automatically.
3
- // But I'm going to be more explicit and import everything I want separately.
4
- // I may change my mind on that in the future, who knows.
1
+ /**
2
+ * Object helpers sub-module.
3
+ * @module @lumjs/core/obj
4
+ */
5
5
 
6
6
  const copyAll = require('./copyall');
7
7
  const copyProps = require('./copyprops');
@@ -9,6 +9,7 @@ const {CLONE,clone,addClone,cloneIfLocked} = require('./clone');
9
9
  const {lock,addLock} = require('./lock');
10
10
  const {mergeNested,syncNested} = require('./merge');
11
11
  const ns = require('./ns');
12
+ const getProperty = require('./getproperty');
12
13
  const
13
14
  {
14
15
  getObjectPath,setObjectPath,
@@ -20,4 +21,5 @@ module.exports =
20
21
  CLONE, clone, addClone, cloneIfLocked, lock, addLock,
21
22
  mergeNested, syncNested, copyProps, copyAll, ns,
22
23
  getObjectPath, setObjectPath, getNamespace, setNamespace,
24
+ getProperty,
23
25
  }
package/lib/obj/lock.js CHANGED
@@ -5,8 +5,8 @@ const {B, isObj, def} = require('../types');
5
5
  * Lock an object using Object.freeze()
6
6
  *
7
7
  * @param {object} obj - The object we want to lock.
8
- * @param {boolean} [clonable=true] Pass to {@link Lum._.addClone} first?
9
- * @param {object} [cloneOpts=null] Options for addClone.
8
+ * @param {boolean} [clonable=true] Pass to `addClone()` first?
9
+ * @param {object} [cloneOpts=null] Options for `addClone()`.
10
10
  * @param {boolean} [useSeal=false] Use Object.seal() instead of freeze.
11
11
  *
12
12
  * If cloneOpts is `null` then we will use the following:
@@ -14,8 +14,7 @@ const {B, isObj, def} = require('../types');
14
14
  * ```{mode: CLONE.DEF, addClone: true, addLock: true}```
15
15
  *
16
16
  * @return {object} The locked object.
17
- *
18
- * @method Lum._.lock
17
+ * @alias module:@lumjs/core/obj.lock
19
18
  */
20
19
  function lock(obj, clonable=true, cloneOpts=null, useSeal=false)
21
20
  {
@@ -37,12 +36,17 @@ const {B, isObj, def} = require('../types');
37
36
  /**
38
37
  * Add a lock() method to an object.
39
38
  *
40
- * Adds a wrapper version of {@link Lum._.lock} to the object as a method.
41
- *
42
- * @param {object} obj - The object we're adding lock() to.
43
- * @param {object} opts - Options (TODO: document this).
39
+ * Adds a wrapper version of `lock()` to the object as a method.
44
40
  *
45
- * @method Lum._.addLock
41
+ * @param {object} obj - The object we're adding `lock()` to.
42
+ * @param {object} [opts] - Options and defaults.
43
+ * In addition to options specific to this function, any options
44
+ * supported by `addClone()` may be specified here as well.
45
+ * @param {object} [opts.lockDesc] Descriptor rules the `lock()` method.
46
+ * @param {boolean} [opts.addClone=true] Default for `clonable` parameter.
47
+ * @param {object} [opts.useSeal=false] Default for `useSeal` parameter.
48
+ * @returns {object} `obj`
49
+ * @alias module:@lumjs/core/obj.addLock
46
50
  */
47
51
  function addLock(obj, opts)
48
52
  {
package/lib/obj/merge.js CHANGED
@@ -20,6 +20,7 @@ const {B, isObj} = require('../types');
20
20
  * as the `opts` argument directly will set this option.
21
21
  *
22
22
  * @returns {object} The `target` object.
23
+ * @alias module:@lumjs/core/obj.mergeNested
23
24
  */
24
25
  function mergeNested(source, target, opts={})
25
26
  {
@@ -64,6 +65,7 @@ const {B, isObj} = require('../types');
64
65
  * @param {object} [opts2=opts1] Options for the second merge operation.
65
66
  * If this is not specified, `opts2` will be the same as `opts1`.
66
67
  *
68
+ * @alias module:@lumjs/core/obj.syncNested
67
69
  */
68
70
  function syncNested(obj1, obj2, opts1={}, opts2=opts1)
69
71
  {
package/lib/obj/ns.js CHANGED
@@ -1,17 +1,19 @@
1
1
  // Import required bits here.
2
2
  const
3
3
  {
4
- B, root, isObj, needObj, def, nonEmptyArray, notNil
4
+ B, root, isObj, needObj, def, nonEmptyArray, notNil,
5
+ doesDescriptorTemplate,
5
6
  } = require('../types');
6
7
 
7
8
  /**
8
- * Internal: need a String or Array
9
+ * Need a String or Array
10
+ * @alias module:@lumjs/core/obj.SOA
9
11
  */
10
12
  function SOA(name, err=true)
11
13
  {
12
14
  const msg = (typeof name === S)
13
- ? name + ' ' + this.message
14
- : this.message;
15
+ ? name + ' ' + SOA.message
16
+ : SOA.message;
15
17
  return err ? (new TypeError(msg)) : msg;
16
18
  }
17
19
  SOA.message = "must be a string or non-empty array";
@@ -19,6 +21,17 @@ def(SOA, 'toString', function() { return this.message; });
19
21
 
20
22
  exports.SOA = SOA;
21
23
 
24
+ /**
25
+ * Get a namespace path string.
26
+ *
27
+ * If it's already a string, return it as is.
28
+ * If it's an array of strings, join the elements with a `.` character.
29
+ *
30
+ * @param {(string|string[])} ns - A dotted string, or array of paths.
31
+ * @param {*} name - Name to use in the SOA error
32
+ * @returns {string}
33
+ * @alias module:@lumjs/core/obj.nsString
34
+ */
22
35
  function nsString(ns, name='Namespace')
23
36
  {
24
37
  if (nonEmptyArray(ns))
@@ -34,6 +47,17 @@ function nsString(ns, name='Namespace')
34
47
 
35
48
  exports.nsString = nsString;
36
49
 
50
+ /**
51
+ * Get a namespace path array.
52
+ *
53
+ * If it's already an array, return it as is.
54
+ * If it's a string, split it into an array, with the `.` delimiter.
55
+ *
56
+ * @param {(string|string[])} ns - A dotted string, or array of paths.
57
+ * @param {*} name - Name to use in the SOA error
58
+ * @returns {string[]}
59
+ * @alias module:@lumjs/core/obj.nsArray
60
+ */
37
61
  function nsArray(ns, name='Namespace')
38
62
  {
39
63
  if (typeof ns === S)
@@ -52,15 +76,20 @@ exports.nsArray = nsArray;
52
76
  /**
53
77
  * Get a (nested) property from an object with a given path.
54
78
  *
55
- * @param {object} obj - Object we're looking in.
79
+ * @param {(object|function)} obj - Object we're looking in.
56
80
  * @param {(string|Array)} proppath - Property path we're looking for.
57
81
  * Generally a string of dot (`.`) separated nested property names.
58
- * @param {object} [opts] TBD.
82
+ * @param {(object|boolean)} [opts] Options changing the behaviours.
83
+ * If this is a `boolean` it's assumed to be the `opts.log` option.
84
+ * @param {boolean} [opts.log=false] Log errors for missing namespaces?
85
+ * @param {*} [opts.default] A default value if the namespace is not found.
86
+ *
59
87
  * @return {*} The property if found, or `opts.default` if not.
88
+ * @alias module:@lumjs/core/obj.getObjectPath
60
89
  */
61
90
  function getObjectPath(obj, proppath, opts={})
62
91
  {
63
- needObj(obj);
92
+ needObj(obj, true);
64
93
 
65
94
  if (typeof opts === B)
66
95
  opts = {log: opts};
@@ -92,19 +121,32 @@ exports.getObjectPath = getObjectPath;
92
121
  /**
93
122
  * Create a nested property path if it does not exist.
94
123
  *
95
- * @param {object} obj - Object the property path is for.
124
+ * @param {(object|function)} obj - Object the property path is for.
96
125
  * @param {(string|Array)} proppath - Property path to create.
97
- * @param {object} [opts] TBD.
98
- * @return {*} Generally the last object in the nested path.
99
- * However the output may vary depending on the options.
126
+ * @param {object} [opts] Options changing the behaviours.
127
+ * @param {*} [opts.value] A value to assign to the last property path.
128
+ * @param {boolean} [opts.overwrite=false] Allow overwriting property paths.
129
+ * Only applicable if `opts.value` was also specified.
130
+ * @param {object} [opts.desc] Descriptor rules for defining the properties.
131
+ * Must NOT contain `value`, `get`, or `set` properties.
132
+ * Only, `configurable`, `enumerable`, and `writable` are supported.
133
+ * Will be ignored if `opts.assign` is `true`.
134
+ * @param {boolean} [opts.assign=false] Use direct assignment instead of `def()`.
135
+ * @param {boolean} [opts.returnThis=false] Return `this` variable.
136
+ * @param {boolean} [opts.returnObj=false] Return the `obj` parameter.
137
+ * @return {*} Generally the last object in the nested property paths.
138
+ * Unless one of `opts.returnThis` or `opts.returnObj` was `true`.
139
+ * @alias module:@lumjs/core/obj.setObjectPath
100
140
  */
101
141
  function setObjectPath(obj, proppath, opts={})
102
142
  {
103
- needObj(obj); needObj(opts);
143
+ needObj(obj, true, 'obj parameter must be an object or function');
144
+ needObj(opts, 'opts parameter must be an object');
145
+
104
146
  proppath = nsArray(proppath);
105
147
 
106
148
  let assign;
107
- if (isObj(opts.desc))
149
+ if (doesDescriptorTemplate(opts.desc))
108
150
  { // An explicit descriptor.
109
151
  assign = (o,p,v={}) =>
110
152
  {
@@ -169,9 +211,15 @@ exports.setObjectPath = setObjectPath;
169
211
 
170
212
  /**
171
213
  * Get a global namespace path if it exists.
214
+ *
215
+ * This literally just calls `getObjectPath()` on the `root` object.
172
216
  *
173
- * - TODO: document this.
174
- * - TODO: rewrite `ns.get` to use this behind the scenes.
217
+ * @param {(string|Array)} proppath - Property path we're looking for.
218
+ * Generally a string of dot (`.`) separated nested property names.
219
+ * @param {object} [opts] See `getObjectPath()` for details.
220
+ * @return {*} The property if found, or `opts.default` if not.
221
+ * @alias module:@lumjs/core/obj.getNamespace
222
+ * @see module:@lumjs/core/obj.getObjectPath
175
223
  */
176
224
  function getNamespace(namespaces, opts={})
177
225
  {
@@ -183,12 +231,17 @@ exports.getNamespace = getNamespace;
183
231
  /**
184
232
  * Create a global namespace path if it does not exist.
185
233
  *
186
- * - TODO: document this.
187
- * - TODO: rewrite `ns.add` to use this behind the scenes.
234
+ * This literally just calls `setObjectPath()` on the `root` object.
235
+ *
236
+ * @param {(string|Array)} proppath - Property path to create.
237
+ * @param {object} [opts] See `setObjectPath()` for details.
238
+ * @return {*} See `setObjectPath()` for details.
239
+ * @alias module:@lumjs/core/obj.setNamespace
240
+ * @see module:@lumjs/core/obj.setObjectPath
188
241
  */
189
242
  function setNamespace(namespaces, opts={})
190
243
  {
191
244
  return setObjectPath(root, namespaces, opts);
192
245
  }
193
246
 
194
- exports.setNamespace = setNamespace;
247
+ exports.setNamespace = setNamespace;
package/lib/objectid.js CHANGED
@@ -4,9 +4,8 @@ const {notNil,def,isNil} = require('./types');
4
4
  /**
5
5
  * Generate a large random number.
6
6
  *
7
- * Takes advantage of
8
- *
9
7
  * @returns {number}
8
+ * @alias module:@lumjs/core.randomNumber
10
9
  */
11
10
  function randomNumber()
12
11
  {
@@ -18,6 +17,7 @@ exports.randomNumber = randomNumber;
18
17
  /**
19
18
  * A class for creating unique identifier objects.
20
19
  * Generally only used by my own inernal libraries, thus the name.
20
+ * @alias module:@lumjs/core.InternalObjectId
21
21
  */
22
22
  class InternalObjectId
23
23
  {
@@ -34,7 +34,6 @@ class InternalObjectId
34
34
  * @param {boolean} [opts.useInstance=true] Store object or id value?
35
35
  * If this is `true` (now the default), we store the instance itself.
36
36
  * If this is `false` (the old default), we store just the `id` value.
37
- *
38
37
  */
39
38
  constructor(opts={})
40
39
  {
package/lib/observable.js CHANGED
@@ -1,11 +1,8 @@
1
- // This library was original based on the observable library from riot.js,
2
- // but has been refactored and expanded a lot since then.
3
1
 
4
- const types = require('./types');
5
- const {B,F,S,def,isObj,isComplex} = types;
2
+ const {B,F,S,def,isObj,isComplex,TYPES} = require('./types');;
6
3
 
7
4
  /**
8
- * Make an object support the observable API.
5
+ * Make an object support the *Observable* API.
9
6
  *
10
7
  * Adds `on()`, `off()`, `one()`, and `trigger()` methods.
11
8
  *
@@ -39,6 +36,8 @@ const {B,F,S,def,isObj,isComplex} = types;
39
36
  * In any other case it defaults to `null`.
40
37
  *
41
38
  * @returns {object} el
39
+ *
40
+ * @exports module:@lumjs/core/observable
42
41
  */
43
42
  function observable (el={}, opts={})
44
43
  {
@@ -274,9 +273,10 @@ function observable (el={}, opts={})
274
273
  module.exports = observable;
275
274
 
276
275
  /**
277
- * See if an object appears to be observable.
276
+ * See if a value implements the *Observable* interface.
278
277
  *
279
- * @param {object} obj
278
+ * @function module:@lumjs/core/observable.is
279
+ * @param {*} obj - The expected object/function to test.
280
280
  * @returns {boolean}
281
281
  */
282
282
  function isObservable(obj)
@@ -289,5 +289,19 @@ function isObservable(obj)
289
289
  // Add an 'is()' method to `observable` itself.
290
290
  def(observable, 'is', isObservable);
291
291
 
292
- // And make it available as `types.doesObservable`
293
- types.doesObservable = isObservable;
292
+ /**
293
+ * Does a value implement the Observable interface?
294
+ * @name module:@lumjs/core/types.doesObservable
295
+ * @function
296
+ * @param {*} v - The expected object/function to test.
297
+ * @returns {boolean}
298
+ * @see module:@lumjs/core/observable.is
299
+ */
300
+
301
+ /**
302
+ * Extension type for the {@link module:@lumjs/core/observable} interface.
303
+ * @memberof module:@lumjs/core/types.TYPES
304
+ * @member {string} OBSERV - Implements the *Observable* interface.
305
+ */
306
+
307
+ TYPES.add('OBSERV', 'observable', isObservable, 'doesObservable');
package/lib/opt.js CHANGED
@@ -1,4 +1,7 @@
1
- // Simple option handling.
1
+ /**
2
+ * Functions for working with options and default values.
3
+ * @module @lumjs/core/opt
4
+ */
2
5
 
3
6
  const {U,needObj,needType} = require('./types');
4
7
 
@@ -16,6 +19,7 @@ const {U,needObj,needType} = require('./types');
16
19
  * be used as `this` for the function.
17
20
  *
18
21
  * @return {*} Either the specified `opt` value or the default value.
22
+ * @alias module:@lumjs/core/opt.val
19
23
  */
20
24
  function val(opt, defvalue, allowNull=false, isLazy=false, lazyThis=null)
21
25
  {
@@ -49,6 +53,7 @@ exports.val = val;
49
53
  * @param {object} [lazyThis=opts] Same as `val()`.
50
54
  *
51
55
  * @return {*} Either the property value, or the default value.
56
+ * module:@lumjs/core/opt.get
52
57
  */
53
58
  function get(obj, optname, defvalue, allowNull=true, isLazy=false, lazyThis=obj)
54
59
  {
package/lib/strings.js CHANGED
@@ -1,4 +1,7 @@
1
- // String methods.
1
+ /**
2
+ * String and locale related functions.
3
+ * @module @lumjs/core/strings
4
+ */
2
5
  const {S,B,F,isObj,root,isArray,needType,needObj} = require('./types')
3
6
 
4
7
  /**
@@ -8,7 +11,8 @@ const {S,B,F,isObj,root,isArray,needType,needObj} = require('./types')
8
11
  * 2. If `Intl` exists it will be used.
9
12
  * 3. If neither of those exist, uses `'en-US'` as a default.
10
13
  *
11
- * @returns string - The locale/language string.
14
+ * @returns {string} - The locale/language string.
15
+ * @alias module:@lumjs/core/strings.getLocale
12
16
  */
13
17
  function getLocale()
14
18
  {
@@ -42,7 +46,8 @@ exports.getLocale = getLocale;
42
46
  * @param {boolean} [lcrest=false] Make the rest of the string lowercase?
43
47
  * @param {string} [locale=getLocale()] The locale/language of the string.
44
48
  *
45
- * @returns string - The output string.
49
+ * @returns {string} - The output string.
50
+ * @alias module:@lumjs/core/strings.ucfirst
46
51
  */
47
52
  function ucfirst ([ first, ...rest ], lcrest = false, locale = getLocale())
48
53
  {
@@ -61,11 +66,13 @@ exports.ucfirst = ucfirst;
61
66
  * Make the first character of each *word* in a string uppercase.
62
67
  *
63
68
  * @param {string} string - The input string.
64
- * @param {boolean} [unicode=false] Use Unicode words? (Only uses ASCII words otherwise)
69
+ * @param {boolean} [unicode=false] Use *Unicode* words?
70
+ * Only uses simple *PCRE-style* words (`\w`) otherwise.
65
71
  * @param {boolean} [lcrest=false] Make the rest of each word lowercase?
66
72
  * @param {string} [locale=getLocale()] The locale/language of the string.
67
73
  *
68
74
  * @returns {string} - The output string.
75
+ * @alias module:@lumjs/core/strings.ucwords
69
76
  */
70
77
  function ucwords(string, unicode = false, lcrest = false, locale = getLocale())
71
78
  {
@@ -77,6 +84,12 @@ exports.ucwords = ucwords;
77
84
 
78
85
  /**
79
86
  * Is the passed in value a valid `String.replace` search value.
87
+ *
88
+ * Only strings and `RegExp` objects are valid.
89
+ *
90
+ * @param {*} v - Value to check.
91
+ * @returns {boolean}
92
+ * @alias module:@lumjs/core/strings.isSearch
80
93
  */
81
94
  function isSearch(value)
82
95
  {
@@ -87,6 +100,12 @@ exports.isSearch = isSearch;
87
100
 
88
101
  /**
89
102
  * Is the passed in value a valid `String.replace` replacement value.
103
+ *
104
+ * Only strings and functions are valid.
105
+ *
106
+ * @param {*} v - Value to check.
107
+ * @returns {boolean}
108
+ * @alias module:@lumjs/core/strings.isReplacement
90
109
  */
91
110
  function isReplacement(value)
92
111
  {
@@ -95,6 +114,26 @@ function isReplacement(value)
95
114
 
96
115
  exports.isReplacement = isReplacement;
97
116
 
117
+ /**
118
+ * Apply multiple replacement rules to a string.
119
+ *
120
+ * @param {string} string - The input string.
121
+ * @param {object} replacements - Replacement rules.
122
+ *
123
+ * If this is an `Array` then each item in the array can be:
124
+ * - Another array with two items, `[find, replace]`;
125
+ * - A `boolean`, will change the current `useAll` settting.
126
+ *
127
+ * If this is any other kind of `object` then the enumerable
128
+ * property *keys* will be used as `find` strings, and the
129
+ * associated *values* will be used as the `replacement` values.
130
+ *
131
+ * @param {boolean} [useAll] Which replacement method will be used.
132
+ * If `true` we use `replaceAll()`, if `false` we use `replace()`.
133
+ * The default is `false` if `value` is an `Array`, or `true` otherwise.
134
+ * @returns {string} The output string with all replacements performed.
135
+ * @alias module:@lumjs/core/strings.replaceItems
136
+ */
98
137
  function replaceItems(string, replacements, useAll)
99
138
  {
100
139
  needType(S, string);