Package Exports
- @thi.ng/resolve-map
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@thi.ng/resolve-map) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@thi.ng/resolve-map
This project is part of the @thi.ng/umbrella monorepo.
About
DAG resolution of vanilla objects & arrays with internally linked values.
It's common practice to use nested JS objects for configuration purposes. Frequently some values in the object are copies or derivatives of other values, which can lead to mistakes during refactoring and/or duplication of effort.
To avoid these issues, this library provides the ability to define single sources of truth, create references (links) to these values and a provide a resolution mechanism to recursively expand their real values and/or compute derived values. Both absolute & relative references are supported.
See source & tests for further details.
Installation
yarn add @thi.ng/resolve-mapUsage examples
import { resolveMap } from "@thi.ng/resolve-map";
resolveMap({
colors: {
bg: "white",
text: "black",
selected: "red",
},
main: {
fontsizes: [12, 16, 20]
},
button: {
bg: "->/colors.text",
label: "->/colors.bg",
fontsize: (resolve) => `${resolve("main.fontsizes.0")}px`,
},
buttonPrimary: {
bg: "->/colors.selected",
label: "->/button.label",
fontsize: (resolve) => `${resolve("main.fontsizes.2")}px`,
}
})
// {
// colors: {
// bg: "white",
// text: "black",
// selected: "red"
// },
// main: {
// fontsizes: [ 12, 16, 20 ]
// },
// button: {
// "bg": "black",
// "label": "white",
// "fontsize": "12px"
// },
// buttonPrimary: {
// bg: "red",
// label: "black",
// fontsize: "20px"
// }
// }Authors
- Karsten Schmidt
License
© 2018 Karsten Schmidt // Apache Software License 2.0