{"id":16350453,"url":"https://github.com/zspecza/figson","last_synced_at":"2025-03-23T00:33:29.713Z","repository":{"id":15764462,"uuid":"18503316","full_name":"zspecza/figson","owner":"zspecza","description":"Simple config storage","archived":false,"fork":false,"pushed_at":"2016-11-09T08:38:07.000Z","size":89,"stargazers_count":9,"open_issues_count":11,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-29T09:22:44.748Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"CoffeeScript","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/zspecza.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":"contributing.md","funding":null,"license":"license.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-04-07T01:12:29.000Z","updated_at":"2016-10-31T08:58:10.000Z","dependencies_parsed_at":"2022-09-26T20:31:24.528Z","dependency_job_id":null,"html_url":"https://github.com/zspecza/figson","commit_stats":null,"previous_names":["declandewet/figson"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zspecza%2Ffigson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zspecza%2Ffigson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zspecza%2Ffigson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zspecza%2Ffigson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zspecza","download_url":"https://codeload.github.com/zspecza/figson/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221841558,"owners_count":16890025,"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-10-11T01:05:01.359Z","updated_at":"2024-10-28T14:38:54.485Z","avatar_url":"https://github.com/zspecza.png","language":"CoffeeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Figson\n======\n\n[![Build Status](https://travis-ci.org/declandewet/figson.svg?branch=master)](https://travis-ci.org/declandewet/figson)\n[![NPM version](https://badge.fury.io/js/figson.svg)](http://badge.fury.io/js/figson)\n[![Dependency Status](https://david-dm.org/declandewet/figson.svg)](https://david-dm.org/declandewet/figson)\n[![devDependency Status](https://david-dm.org/declandewet/figson/dev-status.svg)](https://david-dm.org/declandewet/figson#info=devDependencies)\n[![Coverage Status](https://coveralls.io/repos/declandewet/figson/badge.png?branch=master)](https://coveralls.io/r/declandewet/figson)\n\nSimple configuration storage.\n\n\u003e **Note:** This project is in early development, and versioning is a little\n  different. [Read this](http://markup.im/#q4_cRZ1Q) for more details.\n\n### Why should you care?\n\nThis project is in very early development, but already makes working with\nJSON, CSON and YAML configuration files a lot easier.\n\n### Installation\n\n```bash\n$ npm install figson --save\n```\n\n--------------------------------------------------------------------------------\n\nUsage\n-----\n\n### Async Example\n\n```javascript\nvar figson = require('figson');\nvar path   = require('path');\n\nfigson.parse('./config.json', function(error, config) {\n  if (error) { throw error; }\n  config.set('foo', 'bar');\n  config.save(function(error) {\n    if (error) { throw error; }\n  });\n});\n```\n\n### Sync Example\n\n```javascript\nvar figson = require('figson');\nvar path   = require('path');\n\ntry {\n  var config = figson.parse('./config.json');\n  config.set('foo', 'bar');\n  config.save();\n} catch (error) {\n  throw error;\n}\n```\n\nYou can swap out `config.json` for `config.cson`, `config.yaml` or `config.yml`.\nEverything will still work, and uses the exact same API as described below.\n\n### Figson API\n\nFigson itself exposes one method:\n\n#### figson.parse(config_file, [callback]);\nAsynchronously reads a configuration file (if there is a callback function), parses it,\nand exposes an `error` and a `config` object to the callback (`function(error, config) {}`).\n`config_file` is the path to the file. Omit the callback for a synchronous operation.\n\n### Config API\n\nThe `config` object is basically just a tiny wrapper around the data inside\nthe configuration file. It exposes a few properties and methods. All of `config`'s methods\nare chainable, and accessing a property with a `config` method uses a tiny\nDSL string similar to how you would access that property using JavaScript's dot\nnotation.\n\n#### config.data\nAn object representing the configuration file.\n\n#### config.val()\nReturns the value of the last key/property in the `config` chain.\n\n#### config.get([key])\nRetrieves the value of the given `key`. If no key is provided, it retrieves\nthe value of the last known key in the chain.\n\n`key` is a string containing the object property who's value you want to retrieve.\n\nExample:\n\n```javascript\n// { some: { property: 'value1' }}\nconfig.get('some.property').val() // =\u003e value1\n// or\nconfig.get().val() // =\u003e value1\n```\n\n#### config.set([key], value)\n\nSets the `key` to the `value`. If no `key` is given, uses the most recent key\nin the chain. The `value` can be a string, number, object, array or null.\n\nExample:\n\n```javascript\n// { an: { array: { property: [] }}}\nconfig.set('an.array.property[0]', 'the value') // { an: { array: { property: ['the value'] }}}\n// or\nconfig.set('a different value') // { an: { array: { property: ['a different value'] }}}\n\n```\n\n#### config.update([key], value)\n\nFirst, attempts a `get()` to determine the existence of the given `key` property. If it\nexists, it will then call `set()` with the new `value`. Otherwise, throws an error.\nUseful if you need to safely set a value. If no `key` is given, updates the\n`key` from the last call in the chain.\n\nExample:\n\n```javascript\nconfig.update('foo', 'baz')\nconfig.get('foo').update('baz')\n```\n\n#### config.destroy([key])\n\n\"deletes\" the given `key` property by setting it's value to `undefined`. If no\nkey is given, it will \"delete\" the key from the last method in the chain.\n\nExample:\n\n```javascript\nconfig.destroy('foo');\nconfig.get('bar').destroy()\n```\n\n#### config.find(partial_key)\n\nThis method is useful for accessing properties that are very deeply nested.\nSuppose you have an object:\n\n```javascript\n{\n  a: {\n    very: {\n      deeply: {\n        nested: {\n          property: 'value'\n        }\n      }\n    }\n  }\n}\n```\n\nYou want to update `a.very.deeply.nested.property` to have the value `foobar`,\nbut you don't want to have to type out the whole property name. Just use `.find()`!\nAs long as the property ends with the key you pass to `find()`, it'll work:\n\n```javascript\nconfig.find('nested.property').set('foobar') // done!\n```\n\n#### config.save([callback])\n\nThis saves the current state of `config.data` to the configuration file. This is a synchronous\noperation, but passing in an optional callback (`function(error) {}`) will make it\nperform asynchronously.\n\nExample:\n\n```javascript\nconfig.save(); // synchronous\n\n// asynchronous\nconfig.save(function(error) {\n  if (error) { throw error; }\n});\n```\n\n### Adding your own configuration file types\n\nFigson exposes a small interface for you to add your own configuration file\nhandlers, if you wish to use a separate data format. Figson uses this interface\ninternally to add support for JSON, CSON and YAML files.\n\nAll you have to do is call `figson.addHandler(name, object)`, where `name` is\nthe name of your handler (e.g. \"CSON\" for CSON files) and where `object` is\na JavaScript object that lists file extensions as well as synchronous and\nasynchronous parse and stringify operations. For example, if you wanted to\nregister JSON, you would do this:\n\n```javascript\nfigson.addHandler('JSON', {\n  extensions: ['.json'],\n  parse: JSON.parse,\n  parseSync: JSON.parse,\n  stringify: JSON.stringify,\n  stringifySync: JSON.stringify\n});\n```\n\nFigson will automatically register the file extension to the correct data\nformat. You can look in\n[lib/handlers](https://github.com/declandewet/figson/tree/master/lib/handlers)\nfor other examples.\n\nContributing:\n-------------\n\nPlease read the [contribution guidelines](https://github.com/declandewet/figson/blob/master/contributing.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzspecza%2Ffigson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzspecza%2Ffigson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzspecza%2Ffigson/lists"}