
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
data-interpreter
Advanced tools
A library to transform / normalize / map a data source (JS Data Structure) using a template
A library to transform / normalize / map a data source (JS Data Structure) using a template.
npm install data-interpreter
constructor([options])
-options
: Is an optional object with any of the follow attributes
splitChar
(String "."): Accesor char, used to indicated inner object attributes in the templatedefaultValue
(Any undefined): Value to be used when no other valued is found from the template in the sourceliteralChar
(String "="): Indicates that the following text in the template must be used as literal valuereverseMapping
(Boolean false): When true, use the absense of literalChar as indication of literal valuecast(source, dictionary[, options])
Main function, used to transfor / cast / translate a template / dictionary using a input (Js data structure)
source
(Object|Array): Source to use as input in the templatedictionary
(String|Object|Array): The structure of the expected output, using the reference to the source.options
(Object): Optional override of the instance optionsgetValueFromObject(source, path)
source
: (Object|Array): Source to use as input to get the datapath
: (String|Array): the path to seek the value, using the splitChar as accesor separator. For example "path.to.inner.value"
or ["path","to","inner","value"]
getType(variableToCheck)
: Helper function that return a string with the tipe of the variable.
variableToCheck
(Any)const source = {
stringLvl1 : "stringValueLvl1",
arrayLvl1 : ["arrayValueLvl1"],
objectLvl1 : {
numberLvl2 : 2,
booleanLvl2 : true,
objectLvl2 : {
stringLvl3 : "stringValueLvl3",
},
},
iterableArray : [
{iterableItemAttribute : "iterableItemValue1"},
{iterableItemAttribute : "iterableItemValue2"},
],
}
data-interpreter
const dataInterpreter = require("data-interpreter");
const interpreter = new dataInterpreter();
interpreter.cast(source, "stringLvl1")
-> "stringValueLvl1"
interpreter.cast(source, {
attrName : "stringLvl1"
})
-> { attrName : "stringValueLvl1" }
interpreter.cast(source, {
attrName : "objectLvl1.numberLvl2"
})
-> { attrName : 2 }
interpreter.cast(source, {
attrName : {
innerAttrName : "stringLvl1"
}
})
-> { attrName : { innerAttrName : "stringValueLvl1"} }
interpreter.cast(source, { attrName : "=LiteralText"})
-> { attrName : "LiteralText"}
interpreter.cast(source, {
attrName : [ "stringLvl1", "objectLvl1.numberLvl2" ]
})
-> { attrName : ["stringValueLvl1", 2] }
interpreter.cast(source, { attributeName : [
"$forEach($iterableArray, $iterationItem, $iterationIndex)",
"$iterationItem.iterableItemAttribute"
]})
-> {attributeName : ["iterableItemValue1", "iterableItemValue2"]}
interpreter.cast(source, { attributeName : [
"$forEach($iterableArray, $iterationItem, $iterationIndex)",
"iterableArray.$iterationIndex.iterableItemAttribute"
]})
-> {attributeName : ["iterableItemValue1", "iterableItemValue2"]}
FAQs
A library to transform / normalize / map a data source (JS Data Structure) using a template
The npm package data-interpreter receives a total of 8 weekly downloads. As such, data-interpreter popularity was classified as not popular.
We found that data-interpreter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.