Skip to content

Commit

Permalink
remove _cloneDeepWith
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgeny Metelkin committed Nov 9, 2023
1 parent 06d85d9 commit 12bc2ed
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
2 changes: 0 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore
- _set
- _omit
- _intersection
- _cloneDeepWith
- _mapValues
- flatten => flat

### Dose class
Expand Down
34 changes: 26 additions & 8 deletions src/module-system/table-module.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { convertExcelSync } = require('../xlsx-connector');
const _cloneDeepWith = require('lodash/cloneDeepWith');

/**
* To initialize a Heta module of the "table" type.
Expand All @@ -26,15 +25,15 @@ function tableLoader(fileContent, _options){

let parsed = rawData
.filter((x) => x.on) // ignore rows
.map((x) => {
.map((x) => {
let cleaned = _cloneDeepWith(x, (value) => {
if (value != null && typeof value.valueOf() === 'string') {
if (typeof value?.valueOf() === 'string') {
return clean(value);
}
if (Array.isArray(value)) {
return value
.map((y) => clean(y))
} else if (Array.isArray(value)) {
return value.map((y) => clean(y))
.filter((y) => y !== ''); // removes empty strings from array
} else {
return value;
}
});

Expand Down Expand Up @@ -76,4 +75,23 @@ function forceBool(x) {
}
}

module.exports = tableLoader;
// clone all own properties and arrays
function _cloneDeepWith(o, handler = (x) => x) {
if (o instanceof Object) {
var clone;
if (o instanceof Array) {
clone = o.map((key) => _cloneDeepWith(key, handler));
} else {
clone = {};
Object.entries(o).forEach(([key, value]) => {
clone[key] = _cloneDeepWith(value, handler);
});
}

return handler(clone);
} else {
return handler(o);
}
}

module.exports = tableLoader;

0 comments on commit 12bc2ed

Please sign in to comment.