{"id":18524668,"url":"https://github.com/bengreenier-archive/schema-settings","last_synced_at":"2026-04-13T22:33:58.754Z","repository":{"id":74695670,"uuid":"150027838","full_name":"bengreenier-archive/schema-settings","owner":"bengreenier-archive","description":"JSON Schema based settings provider","archived":false,"fork":false,"pushed_at":"2018-11-19T16:08:03.000Z","size":35,"stargazers_count":0,"open_issues_count":4,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-03-18T16:59:08.963Z","etag":null,"topics":["json","json-schema","settings"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bengreenier-archive.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":"2018-09-23T21:39:35.000Z","updated_at":"2019-09-29T11:28:06.000Z","dependencies_parsed_at":"2023-02-26T06:30:13.689Z","dependency_job_id":null,"html_url":"https://github.com/bengreenier-archive/schema-settings","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bengreenier-archive/schema-settings","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bengreenier-archive%2Fschema-settings","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bengreenier-archive%2Fschema-settings/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bengreenier-archive%2Fschema-settings/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bengreenier-archive%2Fschema-settings/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bengreenier-archive","download_url":"https://codeload.github.com/bengreenier-archive/schema-settings/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bengreenier-archive%2Fschema-settings/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30952607,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-26T06:40:55.358Z","status":"ssl_error","status_checked_at":"2026-03-26T06:40:44.656Z","response_time":114,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["json","json-schema","settings"],"created_at":"2024-11-06T17:43:02.652Z","updated_at":"2026-04-13T22:33:58.732Z","avatar_url":"https://github.com/bengreenier-archive.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# schema-settings\n\n[![Build Status](https://travis-ci.org/bengreenier/schema-settings.svg?branch=master)](https://travis-ci.org/bengreenier/schema-settings)\n\n\u003e __Deprecated.__ See [contributes](https://github.com/overlayed-app/contributes).\n\nJSON Schema based settings provider :gear:\n\n```\nconst SSettings = require('schema-settings')\nconst settings = new SSettings({\n  schema: {\n    properties: {\n      foo: { type: 'string', default: 'bar' }\n    }\n  },\n  location: `${__dirname}/settings.json`\n})\n\n\nconst foo = settings.get('foo')\n\n// prints 'bar'\nconsole.log(foo)\n```\n\nI wanted a strongly constrained settings implementation that made it easy for folks to define additional setting constraints (as external plugins). I also wanted it to be easy to use. I think `schema-settings` does those things well.\n\n## API\n\n\u003e First, install with `npm i schema-settings`\n\n### global\n\nA global [SchemaSettings](#schemasettings) instance, for use when you don't wish to maintain an instance.\n\nThis is designed for electron renderer process workloads, but may be broadly useful. Simply `configure` once\nand then reference where needed. For example:\n\n```\nconst settings = require('schema-settings`).global\nsettings.configure({\n  schema: {\n    properties: {\n      todo: {type: 'string', default: 'populate this json schema constraints object' }\n    }\n  },\n  location: './path-on-disk-to-save-settings-to.json'\n})\n\n// 'populate this json schema constraints object'\nsettings.get('todo')\n```\n\n### SchemaSettings\n\n#### constructor\n\n```\n/**\n* Creates an instance of SchemaSettings\n* \n* By default, this uses coercion and defaults for the provided schema\n* \n* @param ISchemaSettingsArgs Ctor args\n*/\n```\n\nArguments:\n\n```\n/**\n* The ajv compatible JSONSchema definition\n*/\nschema : object,\n\n/**\n* The location of the settings data file\n*/\nlocation : string,\n\n/**\n* A readFile implementation\n*/\nreadFile ?: readFileSync,\n\n/**\n* A writeFile implementation\n*/\nwriteFile ?: writeFileSync,\n\n/**\n* The ajv compilation arguments\n*/\najvArgs ?: Options,\n\n/**\n* The separator used to denote object hierarchy in selectors\n*/\nhierarchySeparator ?: string,\n\n/**\n* The separator used to denote the start of array indices in selectors\n*/\narrayStartSeparator ?: string,\n\n/**\n* The separator used to denote the end of array indices in selectors\n*/\narrayEndSeparator ?: string\n```\n\nExample:\n\n```\nconst SS = require('schema-settings`)\nconst settings = new SS({\n  schema: {\n    properties: {\n      todo: {type: 'string', default: 'populate this json schema constraints object' }\n    }\n  },\n  location: './path-on-disk-to-save-settings-to.json'\n})\n```\n\n#### get\n\n```\n/**\n* Get's all or a portion of the settings\n* @param selector sub object selector\n*/\n```\n\nArguments:\n\n```\n/**\n* sub object selector used to determine what portion of the settings object you demand\n* Optional\n*/\nselector ?: string\n```\n\nExample:\n\n```\nconst todo = settings.get('todo')\n\n// outputs 'populate this json schema constraints object'\nconsole.log(todo)\n```\n\n#### getTree\n\n\u003e Designed for internal use only\n\n```\n/**\n* Get's a portion of settings, maintaining the object tree leading to that portion\n* @param selector sub object selector\n*/\n```\n\nArguments:\n\n```\n/**\n* sub object selector used to determine what portion of the settings object you demand\n* Optional\n*/\nselector ?: string\n```\n\nExample:\n\n```\nconst todoTree = settings.getTree('todo')\n\n// outputs {todo: 'populate this json schema constraints object'}\nconsole.log(todoTree)\n```\n\n#### set\n\n```\n/**\n* Set's a portion of the settings\n* @param selector sub object selector\n* @param val value to store\n*/\n```\n\nArguments:\n\n```\n/**\n* sub object selector used to determine what portion of the settings object you wish to change\n* Optional\n*/\nselector ?: string\n\n/**\n* The value you wish to set for settings\n* Note: If you omit the selector argument, this argument will be first\n*/\nval : object\n```\n\nExample:\n\n```\n// will write a new value for 'todo'\nsettings.set('todo', 'i\\'ve done it now!')\n```\n\n#### walkTree\n\n\u003e Designed for internal use only\n\n```\n/**\n* Walks toward a selector against a given object and calls callback for each step\n* @param selector sub object selector\n* @param obj object\n* @param cb step callback, given (obj ptr, selector part, selector part index, total selector parts count)\n*/\n```\n\nArguments:\n\n```\n/**\n* sub object selector used to determine what portion of the settings object you wish to walk toward\n*/\nselector : string\n\n/**\n* The object you wish to walk over\n*/\nobj : object\n\n/**\n* The callback that will be invoked for each step\n* it's given:\n*    obj: a pointer to the node in the object we are currently walking on\n*    key: the key that we are about to walk into\n*    index: the index of the key, as a part of the overall selector\n*    keyCount: the number of total keys that makeup the overall selector\n*/\ncb : (obj : object, key : string, index : number, keyCount : number)\n```\n\n#### evaluateSelector\n\n```\n/**\n* Evaluates a selector against a given object and returns the selected bits\n* @param selector sub object selector\n* @param obj object\n* @param type the evaluation type we use (copy-tree, or reference src object)\n*/\n```\n\nArguments:\n\n```\n/**\n* sub object selector used to determine what portion of the settings object you wish to walk toward\n*/\nselector : string\n\n/**\n* The object you wish to walk over\n*/\nobj : object\n\n/**\n* The evaluation type we use ('reference' or 'copy')\n* This determines if we reference a part of the larger object in the return type\n* or if we copy the object/relevant bits to it's own structure\n*/\ntype : 'reference' | 'copy' = 'reference'\n```\n\n#### generateSelectors\n\n```\n/**\n* Generates selectors for a given object shape\n* @param srcObject object for which to generate selectors\n*/\n```\n\nArguments:\n\n```\n/**\n* The object you wish to generate selectors for\n*/\nsrcObject : object\n```\n\nExample:\n\n```\nconst selectors = settings.generateSelectors({todo: 'hello'})\n\n// outputs ['todo']\nconsole.log(selectors)\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbengreenier-archive%2Fschema-settings","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbengreenier-archive%2Fschema-settings","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbengreenier-archive%2Fschema-settings/lists"}