{"id":21832296,"url":"https://github.com/hoseungme/storage-typed","last_synced_at":"2026-05-18T14:08:24.181Z","repository":{"id":57702429,"uuid":"500024354","full_name":"hoseungme/storage-typed","owner":"hoseungme","description":"Type-safe web Storage wrapper that provides automatic JSON parsing/stringifying and type-specific features","archived":false,"fork":false,"pushed_at":"2022-06-10T22:30:58.000Z","size":307,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-24T15:38:56.391Z","etag":null,"topics":["javascript","localstorage","sessionstorage","storage","typescript","web","webstorage"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/hoseungme.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":"2022-06-05T07:01:12.000Z","updated_at":"2023-09-10T10:35:00.000Z","dependencies_parsed_at":"2022-09-26T21:11:18.276Z","dependency_job_id":null,"html_url":"https://github.com/hoseungme/storage-typed","commit_stats":null,"previous_names":["hoseungme/storage-typed","hoseungjang/storage-typed"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/hoseungme/storage-typed","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoseungme%2Fstorage-typed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoseungme%2Fstorage-typed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoseungme%2Fstorage-typed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoseungme%2Fstorage-typed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hoseungme","download_url":"https://codeload.github.com/hoseungme/storage-typed/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoseungme%2Fstorage-typed/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33180356,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-18T09:27:30.708Z","status":"ssl_error","status_checked_at":"2026-05-18T09:27:28.300Z","response_time":71,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":["javascript","localstorage","sessionstorage","storage","typescript","web","webstorage"],"created_at":"2024-11-27T19:19:02.209Z","updated_at":"2026-05-18T14:08:24.150Z","avatar_url":"https://github.com/hoseungme.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## storage-typed\n\nWeb Storage only accepts string value so you should write this verbose code everytime:\n\n```typescript\n// get\ntry {\n  const value = window.localStorage.getItem(key);\n  return value ? JSON.parse(value) : null;\n} catch (e) {\n  /* ... */\n}\n\n// set\nwindow.localStorage.setItem(key, JSON.stringify(value));\n```\n\nAnd it does not provide any type-specific operation. (e.g. increasing number value, push to array)\n\n```typescript\n// increasing count\nconst count = JSON.parse(window.localStorage.getItem(key));\nwindow.localStorage.setItem(key, JSON.stringify(count + 1));\n\n// push to array\nconst arr = JSON.parse(window.localStorage.getItem(key));\nwindow.localStorage.setItem(key, JSON.stringify([...arr, value]));\n```\n\nSo `storage-typed` resolves all things above.\n\n```typescript\nconst count = TypedStorageFactory.create(\"count\", 0); // NumberTypedStorage\ncount.increase();\ncount.get(); // 1\n\nconst arr = TypedStorageFactory.create(\"array\", [\"foo\"]); // ArrayTypedStorage\narr.pop(); // \"foo\"\narr.push(\"bar\");\narr.get(); // [\"bar\"]\n\n/* and any other types... */\n```\n\n## API References\n\n- [TypedStorageFactory](#typedstoragefactory)\n- [TypedStorage](#typedstorage)\n  - [TypedStorageOptions](#typedstorageoptions)\n- [NumberTypedStorage](#numbertypedstorage)\n- [BooleanTypedStorage](#booleantypedstorage)\n- [ArrayTypedStorage](#arraytypedstorage)\n\n### TypedStorageFactory\n\nCreates TypedStorage by type of passed initial value. [Note test code.](./src/factory.spec.ts)\n\n```typescript\nTypedStorageFactory.create\u003cT\u003e(key, initialValue, options);\n```\n\n- create: `(key, initialValue, options) =\u003e TypedStorage\u003cT\u003e | NumberTypedStorage | BooleanTypedStorage | ArrayTypedStorage\u003cT[number]\u003e`\n  - returns instanceof `TypedStorage` by type of passed initial value\n  - parameters\n    - key: `string`\n      - required\n      - unique key for value\n    - initialValue: `T`\n      - required\n      - any value which `TypedStorage` will be initialized with\n    - options: `TypedStorageOptions\u003cT\u003e`\n      - optional\n      - [note TypedStorageOptions](#typedstorageoptions)\n\n### TypedStorage\n\nProvides JSON parsing/stringifying. [Note test code.](./src/any.spec.ts)\n\n```typescript\nconst storage = new TypedStorage\u003cT\u003e(key, initialValue, options);\nstorage.get();\nstorage.set(value);\n```\n\n- constructor: `(key, initialValue, options) =\u003e TypedStorage\u003cT\u003e`\n\n  - returns instanceof `TypedStorage` by type of passed initial value\n  - parameters\n    - key: `string`\n      - required\n      - unique key for value\n    - initialValue: `T`\n      - required\n      - any value which `TypedStorage` will be initialized with\n    - options: `TypedStorageOptions\u003cT\u003e`\n      - optional\n      - [note TypedStorageOptions](#typedstorageoptions)\n\n- get: `() =\u003e T`\n\n  - returns current value\n\n- set: `(next) =\u003e void`\n  - sets current value to passed value\n  - parameters\n    - next: `T`\n      - required\n      - next value\n\n#### TypedStorageOptions\n\n```typescript\ninterface TypedStorageOptions\u003cT\u003e {\n  storage?: Storage;\n}\n```\n\n- storage: `Storage`\n  - `Storage` which `TypedStorage` will use\n\n### NumberTypedStorage\n\nExtends number-specific methods based on `TypedStorage` API. [Note test code.](./src/number.spec.ts)\n\n```typescript\nconst storage = new NumberTypedStorage(key, initialValue, options);\nstorage.increase();\nstorage.decrease();\n```\n\n- constructor: `(key, initialValue, options) =\u003e TypedStorage\u003cnumber\u003e`\n\n  - returns instanceof `TypedStorage` by type of passed initial value\n  - parameters\n    - key: `string`\n      - required\n      - unique key for value\n    - initialValue: `number`\n      - required\n      - any value which `NumberTypedStorage` will be initialized with\n    - options: `TypedStorageOptions\u003cnumber\u003e`\n      - optional\n      - [note TypedStorageOptions](#typedstorageoptions)\n\n- increase: `() =\u003e void`\n\n  - adds 1 to current value\n\n- decrease: `() =\u003e void`\n  - subtracts 1 from current value\n\n### BooleanTypedStorage\n\nExtends boolean-specific methods based on `TypedStorage` API. [Note test code.](./src/boolean.spec.ts)\n\n```typescript\nconst storage = new BooleanTypedStorage(key, initialValue, options);\nstorage.toggle();\nstorage.true();\nstorage.false();\n```\n\n- constructor: `(key, initialValue, options) =\u003e TypedStorage\u003cboolean\u003e`\n\n  - returns instanceof `TypedStorage` by type of passed initial value\n  - parameters\n    - key: `string`\n      - required\n      - unique key for value\n    - initialValue: `boolean`\n      - required\n      - any value which `BooleanTypedStorage` will be initialized with\n    - options: `TypedStorageOptions\u003cboolean\u003e`\n      - optional\n      - [note TypedStorageOptions](#typedstorageoptions)\n\n- toggle: `() =\u003e void`\n\n  - reverses current value\n\n- true: `() =\u003e void`\n\n  - sets current value to true\n\n- false: `() =\u003e void`\n  - sets current value to false\n\n### ArrayTypedStorage\n\nExtends number-specific methods based on `TypedStorage` API. [Note test code.](./src/array.spec.ts)\n\n```typescript\nconst storage = new ArrayTypedStorage\u003cT\u003e(key, initialValue, options);\nstorage.push(value);\nstorage.pop();\n```\n\n- constructor: `(key, initialValue, options) =\u003e TypedStorage\u003cT[]\u003e`\n\n  - returns instanceof `TypedStorage` by type of passed initial value\n  - parameters\n    - key: `string`\n      - required\n      - unique key for value\n    - initialValue: `T[]`\n      - required\n      - any value which `NumberTypedStorage` will be initialized with\n    - options: `TypedStorageOptions\u003cT[]\u003e`\n      - optional\n      - [note TypedStorageOptions](#typedstorageoptions)\n\n- push: `(value: T) =\u003e void`\n\n  - appends value to the end of current array\n\n- pop: `() =\u003e T | null`\n  - removes last value of current array. if it is empty, `pop` returns null.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoseungme%2Fstorage-typed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhoseungme%2Fstorage-typed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoseungme%2Fstorage-typed/lists"}