@intlify/message-resolver
Advanced tools
Comparing version 9.0.0-rc.2 to 9.0.0-rc.3
/*! | ||
* @intlify/message-resolver v9.0.0-rc.2 | ||
* @intlify/message-resolver v9.0.0-rc.3 | ||
* (c) 2021 kazuya kawaguchi | ||
@@ -252,4 +252,48 @@ * Released under the MIT License. | ||
} | ||
/** | ||
* Transform flat json in obj to normal json in obj | ||
*/ | ||
function handleFlatJson(obj) { | ||
// check obj | ||
if (!isObject(obj)) { | ||
return obj; | ||
} | ||
for (const key in obj) { | ||
// check key | ||
if (!obj.hasOwnProperty(key)) { | ||
continue; | ||
} | ||
// handle for normal json | ||
if (!key.includes("." /* DOT */)) { | ||
// recursive process value if value is also a object | ||
if (typeof obj[key] === 'object') { | ||
handleFlatJson(obj[key]); | ||
} | ||
} | ||
// handle for flat json, transform to normal json | ||
else { | ||
// go to the last object | ||
const subKeys = key.split("." /* DOT */); | ||
const lastIndex = subKeys.length - 1; | ||
let currentObj = obj; | ||
for (let i = 0; i < lastIndex; i++) { | ||
if (!(subKeys[i] in currentObj)) { | ||
currentObj[subKeys[i]] = {}; | ||
} | ||
currentObj = currentObj[subKeys[i]]; | ||
} | ||
// update last object value, delete old property | ||
currentObj[subKeys[lastIndex]] = obj[key]; | ||
delete obj[key]; | ||
// recursive process value if value is also a object | ||
if (typeof currentObj[subKeys[lastIndex]] === 'object') { | ||
handleFlatJson(currentObj[subKeys[lastIndex]]); | ||
} | ||
} | ||
} | ||
return obj; | ||
} | ||
exports.handleFlatJson = handleFlatJson; | ||
exports.parse = parse; | ||
exports.resolveValue = resolveValue; |
/*! | ||
* @intlify/message-resolver v9.0.0-rc.2 | ||
* @intlify/message-resolver v9.0.0-rc.3 | ||
* (c) 2021 kazuya kawaguchi | ||
@@ -252,4 +252,48 @@ * Released under the MIT License. | ||
} | ||
/** | ||
* Transform flat json in obj to normal json in obj | ||
*/ | ||
function handleFlatJson(obj) { | ||
// check obj | ||
if (!isObject(obj)) { | ||
return obj; | ||
} | ||
for (const key in obj) { | ||
// check key | ||
if (!obj.hasOwnProperty(key)) { | ||
continue; | ||
} | ||
// handle for normal json | ||
if (!key.includes("." /* DOT */)) { | ||
// recursive process value if value is also a object | ||
if (typeof obj[key] === 'object') { | ||
handleFlatJson(obj[key]); | ||
} | ||
} | ||
// handle for flat json, transform to normal json | ||
else { | ||
// go to the last object | ||
const subKeys = key.split("." /* DOT */); | ||
const lastIndex = subKeys.length - 1; | ||
let currentObj = obj; | ||
for (let i = 0; i < lastIndex; i++) { | ||
if (!(subKeys[i] in currentObj)) { | ||
currentObj[subKeys[i]] = {}; | ||
} | ||
currentObj = currentObj[subKeys[i]]; | ||
} | ||
// update last object value, delete old property | ||
currentObj[subKeys[lastIndex]] = obj[key]; | ||
delete obj[key]; | ||
// recursive process value if value is also a object | ||
if (typeof currentObj[subKeys[lastIndex]] === 'object') { | ||
handleFlatJson(currentObj[subKeys[lastIndex]]); | ||
} | ||
} | ||
} | ||
return obj; | ||
} | ||
exports.handleFlatJson = handleFlatJson; | ||
exports.parse = parse; | ||
exports.resolveValue = resolveValue; |
/** | ||
* Transform flat json in obj to normal json in obj | ||
*/ | ||
export declare function handleFlatJson(obj: unknown): unknown; | ||
/** | ||
* Parse a string path into an array of segments | ||
@@ -4,0 +9,0 @@ */ |
/*! | ||
* @intlify/message-resolver v9.0.0-rc.2 | ||
* @intlify/message-resolver v9.0.0-rc.3 | ||
* (c) 2021 kazuya kawaguchi | ||
@@ -249,3 +249,46 @@ * Released under the MIT License. | ||
} | ||
/** | ||
* Transform flat json in obj to normal json in obj | ||
*/ | ||
function handleFlatJson(obj) { | ||
// check obj | ||
if (!isObject(obj)) { | ||
return obj; | ||
} | ||
for (const key in obj) { | ||
// check key | ||
if (!obj.hasOwnProperty(key)) { | ||
continue; | ||
} | ||
// handle for normal json | ||
if (!key.includes("." /* DOT */)) { | ||
// recursive process value if value is also a object | ||
if (typeof obj[key] === 'object') { | ||
handleFlatJson(obj[key]); | ||
} | ||
} | ||
// handle for flat json, transform to normal json | ||
else { | ||
// go to the last object | ||
const subKeys = key.split("." /* DOT */); | ||
const lastIndex = subKeys.length - 1; | ||
let currentObj = obj; | ||
for (let i = 0; i < lastIndex; i++) { | ||
if (!(subKeys[i] in currentObj)) { | ||
currentObj[subKeys[i]] = {}; | ||
} | ||
currentObj = currentObj[subKeys[i]]; | ||
} | ||
// update last object value, delete old property | ||
currentObj[subKeys[lastIndex]] = obj[key]; | ||
delete obj[key]; | ||
// recursive process value if value is also a object | ||
if (typeof currentObj[subKeys[lastIndex]] === 'object') { | ||
handleFlatJson(currentObj[subKeys[lastIndex]]); | ||
} | ||
} | ||
} | ||
return obj; | ||
} | ||
export { parse, resolveValue }; | ||
export { handleFlatJson, parse, resolveValue }; |
{ | ||
"name": "@intlify/message-resolver", | ||
"version": "9.0.0-rc.2", | ||
"version": "9.0.0-rc.3", | ||
"description": "@intlify/message-resolver", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30062
900