{"id":22747187,"url":"https://github.com/one-com/node-oconf","last_synced_at":"2025-04-14T11:40:29.918Z","repository":{"id":1830623,"uuid":"2754926","full_name":"One-com/node-oconf","owner":"One-com","description":"Experiments with doing cJSON with includes for configuration management","archived":false,"fork":false,"pushed_at":"2025-01-27T09:19:32.000Z","size":169,"stargazers_count":5,"open_issues_count":2,"forks_count":6,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-04-09T19:50:33.781Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"unpingco/Python-for-Signal-Processing","license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/One-com.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2011-11-11T09:34:42.000Z","updated_at":"2025-01-27T09:19:37.000Z","dependencies_parsed_at":"2024-06-19T05:27:01.888Z","dependency_job_id":"360a5d64-d4e8-4f2e-9161-16ca95ae83aa","html_url":"https://github.com/One-com/node-oconf","commit_stats":null,"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/One-com%2Fnode-oconf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/One-com%2Fnode-oconf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/One-com%2Fnode-oconf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/One-com%2Fnode-oconf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/One-com","download_url":"https://codeload.github.com/One-com/node-oconf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248874209,"owners_count":21175791,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-11T03:13:35.869Z","updated_at":"2025-04-14T11:40:29.895Z","avatar_url":"https://github.com/One-com.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OConf\n\n[![NPM version](https://badge.fury.io/js/oconf.svg)](https://npmjs.com/package/oconf)\n[![Build Status](https://travis-ci.org/One-com/node-oconf.svg)](https://travis-ci.org/One-com/node-oconf)\n[![Coverage Status](https://coveralls.io/repos/One-com/node-oconf/badge.svg)](https://coveralls.io/r/One-com/node-oconf)\n[![Dependency Status](https://david-dm.org/One-com/node-oconf.png)](https://david-dm.org/One-com/node-oconf)\n\nLoad cjson (JSON + c-style) commentaries, with inheritance-sugar on top:\n\n    \u003e var oconf = require('oconf');\n    \u003e oconf.load('config/my-config.cjson');\n    {\n         \"some-setting\": \"default-value\",\n         \"value\": 50\n    }\n\n## The `#include` directive\n\nAnywhere in your cjson file, you can `#include` another cjson file. The file containing the `#include` directive overrides any values from the file being included, in case of conflicts.\n\n### Format\n\nThe basic idea is to experiment with applying `#include`-directives recusively\ninside JSON/cJSON documents:\n\n```javascript\n// default-settings.cjson\n{\n\t\"some-setting\": \"default value\",\n\t\"value\": 100\n}\n```\n\n```javascript\n// my-config.cjson\n{\n\t\"#include\": \"./default-settings.json\",\n\t\"value\": 50\n}\n```\n\nWill result in a config with:\n\n```javascript\n{\n\t\"some-setting\": \"default-value\",\n\t\"value\": 50\n}\n```\n\nThe extension of objects also work recursively, so setting a single sub-key\nsomewhere doesn't override the entire thing.\n\n### Structure\n\nThere are no restrictions in how includes work (except no loops). Usually a\nstructure like this is used:\n\n * `project/config/default.cjson` has project-wide defaults.\n * `project/config/{dev,test,staging,production}.cjson` inherits the default\n   and set keys relevant to respective environments\n * `project/config/$HOSTNAME.cjson` (optional) machine-specifics that inherit\n   from the relevant environment-file.\n * `/etc/$WORKNAME/$PROJECTNAME-secrets.cjson` inherits the machine-specific\n   things and typically adds production secrets.\n\n## The `#public` directive\n\nWith this directive, you can generate a json blob that can be safely exposed to client-side code. This is useful when some properties on the same object are safe to expose to client code, while others are not.\n\n### Restrictions\n\nIn case of conflicts between a `#public` and a non-public key on the same object, an error is thrown - it is usually a sign that a new key needs to be introduced if the same key contains different values for client and server code.\n\nThe `#include` directives are processed before `#public`.\n\n### Format\n\nAnywhere in your cjson file, you can add a `#public` property to an object, denoting some keys on that property you want grouped together on the `#public` property of the root of your config. \n\n```javascript\n// some-public-settings.cjson\n{\n  \"some-setting\": \"default value\",\n  \"value\": 100,\n  \"fancy-list\": {\n    \"expose-foo\": true,\n    \"#public\": {\n      \"scroll-timeout\": 100\n    }\n  }\n}\n```\n\nWill result in a config with:\n\n```javascript\n{\n  \"some-setting\": \"default-value\",\n  \"value\": 100,\n  \"fancy-list\": {\n    \"expose-foo\": true,\n    \"scroll-timeout\": 100\n  },\n  \"#public\": {\n    \"fancy-list\": {\n      \"scroll-timeout\": 100\n    }\n  }\n}\n```\n\n### Returning only configuration marked as `#public`\n\nYou can instruct `oconf.load` to only return configuration properties marked with `#public`:\n\n    \u003e var oconf = require('oconf');\n    \u003e oconf.load('config/some-public-settings.cjson', { public: true });\n    {\n        \"fancy-list\": {\n            \"scroll-timeout\": 100\n        }\n    }\n\nOf course you can also just grab the `#public` property from the result of `oconf.load`:\n\n    \u003e var oconf = require('oconf');\n    \u003e oconf.load('config/some-public-settings.cjson')['#public'];\n    {\n        \"fancy-list\": {\n            \"scroll-timeout\": 100\n        }\n    }\n\n## Binary\n\nTo help resolve configuration on the command line oconf exports a CLI\ntool called oconf. It takes a path to an cjson file, and outputs the\nresolved JSON object.\n\n```\n $ oconf config.cjson\n{\n  \"someConfig\": \"someValue\",\n  \"obj\": {\n    \"foo\": \"bar\"\n  }\n}\n```\n\nYou can lint your configuration files by using the `--lint` flag. It\nwill not output any of the resolved configuration, but only exit with\nan error in case of any formatting errors in the files.\n\n```\n $ oconf --lint config.cjson\n```\n\nBy using the `--extract-option` flag you can supply a path to a value\nas well:\n\n```\n $ oconf --extract-option obj.foo config.cjson\nbar\n```\n\nThe output from the above is the raw data. That is useful when you\nneed to pass the configuration to other CLI tools. If you need the\nJSON formatted data, you can pass the `--option-as-json` option.\n\n```\n $ oconf --extract-option obj.foo --json config.cjson\n\"bar\"\n```\n\nIf the key is missing `oconf --extract-option` will exit with status\ncode 1. If you need to overwrite that behaviour you can pass the\n`--allow-missing-option` flag to oconf which will make it exit with\nstatus code 0 if no value is found at the given path.\n\nYou can also filter out values in the `#public` blob with the `--public` flag.\n\n```\n $ oconf --public some-public-settings.cjson\n{\n  \"fancy-list\": {\n    \"scroll-timeout\": 100\n  }\n}\n```\n\n## Support for relaxed JSON format\n**Reference:** https://www.npmjs.com/package/relaxed-json\n\n```js\n// Contents of config.rjson\n{\n  someConfig: 'someValue'\n}\n```\n\n### In terminal:\n```sh\n $ oconf --relaxed config.rjson\n{\n    \"someConfig\": \"someValue\"\n}\n```\n\nIn Node JS:\n```js\nvar oconf = require('oconf');\nvar data = oconf.load('config.rjson', { relaxed: true });\nconsole.log(JSON.stringify(data));\n\n// Output:\n{\"someConfig\": \"someValue\"}\n```\n\n## Tests\n\nDownload/clone, run `npm install` and then `npm test`.\n\n## License\n\nThe software is provided under the Modified BSD License; See\n[LICENSE](LICENSE) for further details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fone-com%2Fnode-oconf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fone-com%2Fnode-oconf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fone-com%2Fnode-oconf/lists"}