MCPcopy
hub / github.com/immutable-js/immutable-js / fromJSWith

Function fromJSWith

src/fromJS.js:20–46  ·  view source on GitHub ↗
(stack, converter, value, key, keyPath, parentValue)

Source from the content-addressed store, hash-verified

18}
19
20function fromJSWith(stack, converter, value, key, keyPath, parentValue) {
21 if (
22 typeof value !== 'string' &&
23 !isImmutable(value) &&
24 (isArrayLike(value) || hasIterator(value) || isPlainObj(value))
25 ) {
26 if (~stack.indexOf(value)) {
27 throw new TypeError('Cannot convert circular structure to Immutable');
28 }
29 stack.push(value);
30 // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
31 keyPath && key !== '' && keyPath.push(key);
32 const converted = converter.call(
33 parentValue,
34 key,
35 Seq(value).map((v, k) =>
36 fromJSWith(stack, converter, v, k, keyPath, value)
37 ),
38 keyPath && keyPath.slice()
39 );
40 stack.pop();
41 // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
42 keyPath && keyPath.pop();
43 return converted;
44 }
45 return value;
46}
47
48function defaultConverter(k, v) {
49 // Effectively the opposite of "Collection.toSeq()"

Callers 1

fromJSFunction · 0.85

Calls 9

isImmutableFunction · 0.90
hasIteratorFunction · 0.90
SeqClass · 0.90
isArrayLikeFunction · 0.85
indexOfMethod · 0.65
pushMethod · 0.65
mapMethod · 0.65
sliceMethod · 0.65
popMethod · 0.65

Tested by

no test coverage detected