{"id":17036002,"url":"https://github.com/phucbm/pia","last_synced_at":"2026-05-06T05:41:16.373Z","repository":{"id":61737389,"uuid":"547246820","full_name":"phucbm/pia","owner":"phucbm","description":"Leverage the use of localStorage and sessionStorage","archived":false,"fork":false,"pushed_at":"2024-02-02T02:59:58.000Z","size":351,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-17T10:22:36.536Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phucbm.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":"2022-10-07T11:20:04.000Z","updated_at":"2024-07-15T01:53:12.000Z","dependencies_parsed_at":"2024-11-29T22:18:21.940Z","dependency_job_id":null,"html_url":"https://github.com/phucbm/pia","commit_stats":{"total_commits":18,"total_committers":1,"mean_commits":18.0,"dds":0.0,"last_synced_commit":"a076b70286aa1c705af6235966c112005479a94c"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":"phucbm/js-webpack-boilerplate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phucbm%2Fpia","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phucbm%2Fpia/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phucbm%2Fpia/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phucbm%2Fpia/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phucbm","download_url":"https://codeload.github.com/phucbm/pia/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245031345,"owners_count":20549913,"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-14T08:48:54.256Z","updated_at":"2026-05-06T05:41:16.365Z","avatar_url":"https://github.com/phucbm.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PiaJS\n\n[![npm version](https://badgen.net/npm/v/piajs?activeTab=versions?icon=npm)](https://www.npmjs.com/package/piajs?activeTab=versions)\n[![npm downloads](https://badgen.net/npm/dm/piajs?activeTab=versions?icon=npm)](https://www.npmjs.com/package/piajs?activeTab=versions)\n[![npm dependents](https://badgen.net/npm/dependents/piajs?activeTab=versions?icon=npm)](https://www.npmjs.com/package/piajs?activeTab=versions)\n[![github stars](https://badgen.net/github/stars/phucbm/pia?icon=github)](https://github.com/phucbm/pia/)\n[![jsdelivr hits](https://badgen.net/jsdelivr/hits/gh/phucbm/pia?icon=jsdelivr)](https://www.jsdelivr.com/package/gh/phucbm/pia)\n[![jsdelivr npm rank](https://badgen.net/jsdelivr/rank/npm/piajs?activeTab=versions?icon=npm)](https://www.npmjs.com/package/piajs?activeTab=versions)\n[![github license](https://badgen.net/github/license/phucbm/pia?icon=github)](https://github.com/phucbm/pia/blob/main/LICENSE)\n[![Made in Vietnam](https://raw.githubusercontent.com/webuild-community/badge/master/svg/made.svg)](https://webuild.community)\n\n\u003e A simple, lightweight JavaScript API for handling browser storage\n\n- Automatically switch between `localStorage` and `sessionStorage` depends on your expires setting\n- Accepts any value type\n- No dependency\n\n## Cookies vs. Local Storage vs. Session Storage\n\n|                        | Cookies            | Local Storage                     | Session Storage | \n|------------------------|--------------------|-----------------------------------|-----------------|\n| **Capacity**           | 4kb                | 10mb                              | 5mb             |\n| **Accessible from**    | Any window         | Any window                        | Same tab        |\n| **Expires**            | Manually set       | Never (_Manually set with PiaJS_) | On tab close    |\n| **Storage location**   | Browser and server | Browser only                      | Browser only    |\n| **Sent with requests** | Yes                | No                                | No              |\n\n## Installation\n\nUsing package manager:\n\n```shell\nnpm i piajs\n```\n\nImport\n\n```js\nimport \"piajs\";\n```\n\nUsing CDN:\n\n```html\n\u003c!-- PiaJs --\u003e\n\u003cscript src=\"https://cdn.jsdelivr.net/gh/phucbm/pia@0.1.2/dist/pia.min.js\"\u003e\u003c/script\u003e\n```\n\n## Usage\n\n### Create record\n\nCreate a record, valid across the entire browser.\n\n```js\nPia.set('key', 1); // number\nPia.set('key', [1, 2]); // array\nPia.set('key', \"string\"); // string\nPia.set('key', {value: \"123\"}); // object\nPia.set('key', true); // boolean\n```\n\nUnlike normal `localStorage` or `sessionStorage`, PiaJS uses `JSON.stringify()`\nto convert the value to a string, so it would accept any type of value.\n\n\u003e **Warning**\n\u003e Prototypes of an _Object_ will be treated as a plain string value. So you can't store instances with Pia.\n\n### Set expires\n\n```js\nPia.set('key', 'your value', {expires: 'session'}); // valid in the current browser tab only\nPia.set('key', 'your value', {expires: 7}); // valid for 7 days\nPia.set('key', 'your value', {expires: '1 day'}); // valid for 1 day\nPia.set('key', 'your value', {expires: '2 days'}); // valid for 2 days\nPia.set('key', 'your value', {expires: '48 hours'}); // valid for 48 hours\n```\n\n\u003e **Note**\n\u003e If you leave `expires` empty or something unrecognized, it will never expire.\n\n### Read record\n\n```js\nPia.get('key');\nPia.get('key', true); // =\u003e full value object\nPia.get('nothing'); // =\u003e null\n```\n\n### Delete record\n\n```js\nPia.remove('key');\n```\n\n### Test record\n\nRun this in the console\n\n```js\nPia.test()\n```\n\nLog the info about a record\n\n```js\nconsole.log(Pia.test('key'));\n\nconst info = {\n    \"leftover\": [\n        \"2 day(s) left\",\n        \"created 134 second(s) ago\",\n        \"created 2 minute(s) ago\",\n        \"created 0 hour(s) ago\",\n        \"created 0 day(s) ago\"\n    ],\n    \"record\": {\n        \"key\": \"pia-day\",\n        \"valueType\": \"string\",\n        \"value\": \"test update\",\n        \"raw_expires\": 2,\n        \"expires\": 2,\n        \"unit\": \"day\",\n        \"storageType\": \"localStorage\",\n        \"arguments\": {\n            \"0\": \"pia-day\",\n            \"1\": \"test day\",\n            \"2\": {\n                \"expires\": 2\n            }\n        },\n        \"createdDate\": \"Thu Jun 29 2023 10:44:25 GMT+0700 (Indochina Time)\"\n    }\n};\n```\n\nTest quickly in the console panel\n\n![test pia](https://github.com/phucbm/pia/assets/14942380/28d16d27-9fe6-4262-8781-80a023dcab3e)\n\n## Deployment\n\n```shell\n# Install packages\nnpm i\n\n# Run dev server\nnpm run dev\n\n# Build prod files\nnpm run prod\n```\n\n\u003c!---\nBuild sources from `./web` to `./build`\n\n```shell\nnpm run build\n```\n\nBuild files from `./src` to `./dist` then publish to `npm`\n\n```shell\nnpm run publish\n```\n---\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphucbm%2Fpia","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphucbm%2Fpia","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphucbm%2Fpia/lists"}