{"id":20181794,"url":"https://github.com/nichoth/state","last_synced_at":"2025-09-03T18:42:10.390Z","repository":{"id":57130920,"uuid":"108688353","full_name":"nichoth/state","owner":"nichoth","description":"State container","archived":false,"fork":false,"pushed_at":"2018-06-13T19:14:25.000Z","size":45,"stargazers_count":1,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-10T06:33:45.701Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nichoth.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-28T22:20:15.000Z","updated_at":"2018-06-13T19:14:26.000Z","dependencies_parsed_at":"2022-09-01T00:12:34.009Z","dependency_job_id":null,"html_url":"https://github.com/nichoth/state","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/nichoth/state","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nichoth%2Fstate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nichoth%2Fstate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nichoth%2Fstate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nichoth%2Fstate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nichoth","download_url":"https://codeload.github.com/nichoth/state/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nichoth%2Fstate/sbom","scorecard":{"id":684692,"data":{"date":"2025-08-04","repo":{"name":"github.com/nichoth/state","commit":"278dded6db1d1d41566e2c05f5336eb306ec95a1"},"scorecard":{"version":"v5.2.1-28-gc1d103a9","commit":"c1d103a9bb9f635ec7260bf9aa0699466fa4be0e"},"score":1.3,"checks":[{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#pinned-dependencies"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#code-review"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#binary-artifacts"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#sast"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#security-policy"}},{"name":"License","score":0,"reason":"license file not detected","details":["Warn: project does not have a license file"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#license"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":0,"reason":"19 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw","Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-hr2v-3952-633q","Warn: Project is vulnerable to: GHSA-2pr6-76vf-7546","Warn: Project is vulnerable to: GHSA-8j8c-7jfh-h6hx","Warn: Project is vulnerable to: GHSA-fvqr-27wr-82fm","Warn: Project is vulnerable to: GHSA-4xc9-xhrj-v574","Warn: Project is vulnerable to: GHSA-x5rq-j2xg-h7qm","Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695","Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw","Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9","Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-52f5-9888-hmc6"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-22T00:24:11.154Z","repository_id":57130920,"created_at":"2025-08-22T00:24:11.155Z","updated_at":"2025-08-22T00:24:11.155Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273492387,"owners_count":25115596,"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","status":"online","status_checked_at":"2025-09-03T02:00:09.631Z","response_time":76,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2024-11-14T02:36:46.321Z","updated_at":"2025-09-03T18:42:10.191Z","avatar_url":"https://github.com/nichoth.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# old school mutable state\n\nAbstract state container\n\nThis package provides minimal prototypes for creating state machines. The core is `index.js`, a class with 2 methods for subscribing to changes and publishing updates. All children inherit from this.\n\nSorted lists are also included here in `list.js`, which has methods for basic crud operations.\n\n`struct.js` is a simple observable object.\n\nThere are several utility functions also -- `extend`, a helper for inheriting, `Merge`, which composes multiple state machines, and `map`.\n\n## install \n\n    $ npm install @nichoth/state\n\n\n## example\n\n### inherit from this module\n\n```js\nvar Store = require('../')\nvar xtend = require('xtend')\nvar assert = require('assert')\n\n// you need to implement _state\n// if _state is an object, it is deep cloned whenever we instantiate a\n// new FooStore\n// _state can also be a function that returns a new object. It will\n// be called during construction\nvar FooStore = Store.extend({\n    _state: { foo: 'foo' },\n\n    // **all methods should be synchronous**\n    setFoo: function (value) {\n        this._state.foo = value\n        return this.publish()\n    }\n})\n\nvar fooStore = FooStore()\n\n// get state\nvar state = fooStore.state()\nconsole.log('initial state', state)\nassert.deepEqual(state, { foo: 'foo' })\n\n// subscribe to changes\nvar stopListening = fooStore.state(function onChange (state) {\n    console.log('new state', state)\n    assert.equal(state.foo, 'bar')\n})\nfooStore.setFoo('bar')\n\n// unsubscribe\nstopListening()\nvar stop = fooStore.state(state =\u003e assert.equal(state.foo, 'baz'))\nfooStore.setFoo('baz')\nstop()\n\n\n// `_state` can be a function that returns initial state\nvar BarStore = Store.extend({\n    _state: function (init) {\n        return { bar: init }\n    },\n\n    setBar: function (val) {\n        this._state.bar = val\n        return this.publish()\n    }\n})\n\nvar barStore = BarStore('baz')\nassert.equal(barStore.state().bar, 'baz')\n```\n\n### State.Merge\n\nCompose multiple state machines, and get change events whenever one of\nthem changes\n\n```js\n// emit a change event whenever one of the children changes\nvar merged = Store.Merge({\n    foo: fooStore,\n    bar: barStore\n})\n\nvar unlisten = merged.state(function onChange (state) {\n    console.log('merged', state)\n    assert.deepEqual(state, {\n        foo: { foo: 'aaaaa' },\n        bar: { bar: 'baz' }\n    })\n})\n\nfooStore.setFoo('aaaaa')\n\nunlisten()\n```\n\n### State.map\n\nTake an existing store and return a new store that is mapped\nby a predicate function\n\n```js\nvar mapped = Store.map(function (state) {\n    return xtend(state, {\n        woo: 'woo'\n    })\n}, fooStore)\n\nmapped.state(function onChange (state) {\n    console.log('mapped', state)\n    assert.deepEqual(state, { foo: 'hello', woo: 'woo' })\n})\n\nfooStore.setFoo('hello')\n```\n\n### struct\nA simple observable object with one method, `.set`.\n\n```js\nvar Struct = require('@nichoth/state/struct')\nvar assert = require('assert')\n\nvar myState = Struct({\n    hello: 'world',\n    foo: 'bar'\n})\n\n// do a shallow merge\nmyState.set({ hello: 'ok' })\n\nassert.deepEqual(myState.state(), {\n    hello: 'ok',\n    foo: 'bar'\n})\n```\n\n### List\nA sorted list of objects\n\n```js\nvar Store = require('../')\nvar ListStore = require('../list')\nvar assert = require('assert')\n\nvar Foos = Store.extend({\n    // these are required\n    idKey: 'id',\n    sortBy: 'hello',\n}, ListStore)\n\nvar foos = Foos()\n\nconsole.log(foos.state())\nassert.deepEqual(foos.state(), {\n    data: {},\n    sorted: [],\n    hasFetched: false\n})\n```\n\n#### list.get(array) =\u003e list\n\nSet this store's list of sorted data\n```js\n// the get method assumes the list is *already* sorted\nfoos.get([{ id: 2, hello: 'ham' }, { id: 1, hello: 'world' }])\nconsole.log(foos.state())\nassert.deepEqual(foos.state(), {\n    data: {\n        '1': { id: 1, hello: 'world' },\n        '2': { id: 2, hello: 'ham' }\n    },\n    sorted: [ { id: 2, hello: 'ham' }, { id: 1, hello: 'world' } ],\n    hasFetched: true\n})\n```\n\n#### list.add(object) =\u003e list\n\nAdd an element in the correct sorted position\n```js\nfoos.add({ id: 3, hello: 'bar' })\nassert.equal(foos.state().sorted[0].hello, 'bar')\n```\n\n#### list.edit(object) =\u003e list\n\nLookup an object by id, and update the given properties\n```js\nfoos.edit({ id: 3, hello: 'baz' })\nassert.equal(foos.state().sorted[0].hello, 'baz')\nassert.equal(foos.state().data['3'].hello, 'baz')\n```\n\n#### list.delete(object) =\u003e list\n\nLookup an object by id and delete it from the store\n```js\nfoos.delete({ id: 2 })\nconsole.log(foos.state())\nassert.deepEqual(foos.state(), {\n    data: {\n        '1': { id: 1, hello: 'world' },\n        '3': { id: 3, hello: 'baz' }\n    },\n    sorted: [ { id: 3, hello: 'baz' }, { id: 1, hello: 'world' } ],\n    hasFetched: true\n})\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnichoth%2Fstate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnichoth%2Fstate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnichoth%2Fstate/lists"}