reorganize directory and file structure
This commit is contained in:
parent
1d826ea8d4
commit
48390b8556
99 changed files with 1155 additions and 1629 deletions
27
lib/util/util.js
Normal file
27
lib/util/util.js
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
// zip two arrays
|
||||
export function zip(a, b) {
|
||||
return a.map((k, i) => [k, b[i]]);
|
||||
}
|
||||
|
||||
export function capitalizeFirstLetter(val) {
|
||||
return String(val).charAt(0).toUpperCase() + String(val).slice(1);
|
||||
}
|
||||
|
||||
const _mapRecursiveStructure = mapping => transform => root => {
|
||||
const found = mapping.get(root);
|
||||
if (found) {
|
||||
// already mapped
|
||||
// return existing result to prevent endless recursion
|
||||
return found;
|
||||
}
|
||||
// note the indirection (wrapped in lamda), this allows the user to recursively map the children (which may refer to the root) without yet having finished mapping the root.
|
||||
let memo;
|
||||
const result = () => {
|
||||
// memoization is necessary for correctness
|
||||
return memo || (memo = transform(root, _mapRecursiveStructure(mapping)(transform)));
|
||||
};
|
||||
mapping.set(root, result);
|
||||
return result;
|
||||
};
|
||||
|
||||
export const mapRecursiveStructure = _mapRecursiveStructure(new Map());
|
||||
Loading…
Add table
Add a link
Reference in a new issue