Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
adrai committed Dec 19, 2022
1 parent 2c5f38b commit 4a0f6fa
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
41 changes: 34 additions & 7 deletions lib/formats/json5.js
Expand Up @@ -85,12 +85,34 @@ var parse = function parse (text, reviver) {
function internalize (holder, name, reviver) {
const value = holder[name];
if (value != null && typeof value === 'object') {
for (const key in value) {
const replacement = internalize(value, key, reviver);
if (replacement === undefined) {
delete value[key];
} else {
value[key] = replacement;
if (Array.isArray(value)) {
for (let i = 0; i < value.length; i++) {
const key = String(i);
const replacement = internalize(value, key, reviver);
if (replacement === undefined) {
delete value[key];
} else {
Object.defineProperty(value, key, {
value: replacement,
writable: true,
enumerable: true,
configurable: true,
});
}
}
} else {
for (const key in value) {
const replacement = internalize(value, key, reviver);
if (replacement === undefined) {
delete value[key];
} else {
Object.defineProperty(value, key, {
value: replacement,
writable: true,
enumerable: true,
configurable: true,
});
}
}
}
}
Expand Down Expand Up @@ -1016,7 +1038,12 @@ function push () {
if (Array.isArray(parent)) {
parent.push(value);
} else {
parent[key] = value;
Object.defineProperty(parent, key, {
value,
writable: true,
enumerable: true,
configurable: true,
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Expand Up @@ -61,7 +61,7 @@ class Backend {
}

create (languages, namespace, key, fallbackValue, callback) {
if (!callback) callback = () => {}
if (typeof callback !== 'function') callback = () => {}
if (typeof languages === 'string') languages = [languages]

let todo = languages.length
Expand Down
8 changes: 4 additions & 4 deletions package.json
Expand Up @@ -28,18 +28,18 @@
"@babel/preset-env": "7.20.2",
"babel-plugin-add-module-exports": "1.0.4",
"dtslint": "4.2.1",
"eslint": "8.29.0",
"eslint": "8.30.0",
"eslint-config-standard": "17.0.0",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-n": "15.6.0",
"eslint-plugin-promise": "6.1.1",
"eslint-plugin-require-path-exists": "1.1.9",
"eslint-plugin-standard": "5.0.0",
"expect.js": "0.3.1",
"i18next": "22.1.5",
"i18next": "22.4.6",
"js-yaml": "4.1.0",
"json5": "2.2.1",
"mocha": "10.1.0",
"json5": "2.2.2",
"mocha": "10.2.0",
"tslint": "5.20.1",
"tsd": "0.25.0",
"typescript": "4.9.4",
Expand Down

0 comments on commit 4a0f6fa

Please sign in to comment.