Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sammarks/object-reference
Resolve self-referencing objects in NodeJS.
https://github.com/sammarks/object-reference
config configuration javascript npm-package objects references
Last synced: 19 days ago
JSON representation
Resolve self-referencing objects in NodeJS.
- Host: GitHub
- URL: https://github.com/sammarks/object-reference
- Owner: sammarks
- License: mit
- Created: 2018-07-09T03:58:41.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-11-15T12:31:59.000Z (over 6 years ago)
- Last Synced: 2025-01-24T00:09:23.868Z (28 days ago)
- Topics: config, configuration, javascript, npm-package, objects, references
- Language: TypeScript
- Size: 84 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README

[](https://circleci.com/gh/sammarks/object-reference/tree/master)
[](https://www.npmjs.com/package/object-reference)
[](https://www.npmjs.com/package/object-reference)

Object reference allows you to build objects that reference themselves.
## Get Started
```sh
npm install --save object-reference
``````js
const resolve = require('object-reference')const theme = {
colors: {
black: '#424242',
white: '#FFF'
},
background: '$.colors.white',
foreground: '$.colors.black',
margins: {
page: '30px'
}
}const processedTheme = resolve(theme)
console.log(processedTheme)// {
// colors: {
// black: '#424242',
// white: '#FFF'
// },
// background: '#FFF',
// foreground: '#424242',
// margins: {
// page: '30px'
// }
// }
```## Features
- Uses `_.get()` from [Lodash](https://github.com/lodash/lodash) under the hood.
- Detects circular references and throws a detailed error message explaining the situation.
- Resolves nested references (references that reference other references).## Why use this?
I've found the perfect use-case to be defining configuration in a single object, with common
variables like colors or sizes at the top of the configuration file, and then specific overrides
underneath that reference the variables by default.This allows the user to have the simplicity of changing a few variables at the top of the document
to make a sweeping impact, or getting fine-grained and changing small values toward the bottom
of the document.