1.0.2 • Published 3 years ago
iter-path v1.0.2
iter-path
Access and update deep properties.
Installation
To install the latest stable version, run the following command:
npm install react-json-fp
Or if you're using yarn:
yarn add react-json-fp
Usage
import iterPath from "iter-path"
const medication = {
resourceType: "Medication",
id: "med0320",
code: {
coding: [
{
system: "http://snomed.info/sct",
code: "324252006",
display: "Azithromycin 250mg capsule (product)",
},
],
},
form: {
coding: [
{
system: "http://snomed.info/sct",
code: "385055001",
display: "Tablet dose form (qualifier value)",
},
],
},
}
function continueFn(value, { key }) {
return key === "code" && typeof value === "string"
}
function replacerFn(value) {
return "abc-" + value
}
return iterPath(medication, replacerFn, [continueFn])
will return the following...
{
"resourceType": "Medication",
"id": "med0320",
"code": {
"coding": [
{
"system": "http://snomed.info/sct",
"code": "abc-324252006",
"display": "Azithromycin 250mg capsule (product)"
}
]
},
"form": {
"coding": [
{
"system": "http://snomed.info/sct",
"code": "abc-385055001",
"display": "Tablet dose form (qualifier value)"
}
]
}
}