opendb-store 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -0
- package/dist/opendb-esm.js +1 -1
- package/dist/opendb-esm.min.js +1 -1
- package/package.json +1 -1
- package/src/config/version.js +1 -1
package/README.md
CHANGED
|
@@ -7,6 +7,19 @@
|
|
|
7
7
|
local - Contain localStorage methods
|
|
8
8
|
session - Contain sessionStorage methods
|
|
9
9
|
|
|
10
|
+
## Installation Guide
|
|
11
|
+
```
|
|
12
|
+
npm i opendb-store
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Import opendb-store in Your Project
|
|
16
|
+
```
|
|
17
|
+
import db from 'opendb-store'
|
|
18
|
+
|
|
19
|
+
db.local.set('libname', 'OpenDB Store');
|
|
20
|
+
console.log('Welcome to: ', db.local.get('libname'));
|
|
21
|
+
```
|
|
22
|
+
|
|
10
23
|
## Local Storage
|
|
11
24
|
|
|
12
25
|
> LocalStorage is a web storage that allows websites to store data persistently on a user's browser.
|
package/dist/opendb-esm.js
CHANGED
package/dist/opendb-esm.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const config$1={namespace:"app",separator:".",trimKeys:!0,expiry:!0};function createNamespace(e){config$1.namespace=e}function switchNamespace(e){config$1.namespace=e}function getCurrentNamespace(){return config$1.namespace}function get$1(){return config$1}function setSeparator(e){config$1.separator=e}function getSeparator(){return config$1.separator}function generateKey(e){return`${config$1.namespace}${config$1.separator}${e}`}const version="1.0.
|
|
1
|
+
const config$1={namespace:"app",separator:".",trimKeys:!0,expiry:!0};function createNamespace(e){config$1.namespace=e}function switchNamespace(e){config$1.namespace=e}function getCurrentNamespace(){return config$1.namespace}function get$1(){return config$1}function setSeparator(e){config$1.separator=e}function getSeparator(){return config$1.separator}function generateKey(e){return`${config$1.namespace}${config$1.separator}${e}`}const version="1.0.3";var config={version:"1.0.3",createNamespace:createNamespace,getCurrentNamespace:getCurrentNamespace,switchNamespace:switchNamespace,get:get$1,setSeparator:setSeparator,getSeparator:getSeparator,generateKey:generateKey};function from(e){e&&switchNamespace(e)}function parse(e){try{return JSON.parse(e)}catch{return e}}function isUndefined(e){return void 0===e}function isNull(e){return null===e||"null"===e}var util={parse:parse,isUndefined:isUndefined,isNull:isNull};function isInvalidArg(e){return isUndefined(e)||isNull(e)}function get(e,t=null){if(isInvalidArg(e))return null;const r=config.generateKey(e),n=this.storage.getItem(r);if(util.isNull(n))return null;try{let r=util.parse(n);return r.expire&&Date.now()>r.expire?(this.remove(e),t):r.value}catch{return t}}function set(e,t,r={}){if(isInvalidArg(e))return null;const n=config.generateKey(e),{expire:a}=r;let o={value:t,...a?{expire:Date.now()+a}:{}};this.storage.setItem(n,JSON.stringify(o))}function has(e){return!!this.get(e)}function remove(e){const t=config.generateKey(e);return this.storage.removeItem(t)}function clear(){return this.storage.clear()}function key(e){return this.storage.key(e)}function keys(){const e=[];for(let t=0;t<this.storage.length;t++)e.push(this.storage.key(t));return e}function trim(e){return this.storage.get(e).trim()}function setFormattedData(e,t){const r=getSeparator();for(let n in t)n in t&&this.set(`${e}${r}${n}`,t[n])}function getFormattedData(e){const t={},r=getSeparator();for(let n=0,a=this.storage.length;n<a;n++){const a=this.key(n),[,o,s]=a.split(`${r}`,3);o===e&&s&&(t[s]=this.get(`${o}${r}${s}`))}return t}var storageMethods={from:from,get:get,set:set,has:has,remove:remove,clear:clear,key:key,keys:keys,trim:trim,getFormattedData:getFormattedData,setFormattedData:setFormattedData};function storageoperations(e){return{storage:e,get count(){return e.length},...storageMethods}}function ensureSupport(e){if(!e)throw new Error("Storage is not supported in this environment.");return e}const db={config:config,local:storageoperations(ensureSupport(window.localStorage)),session:storageoperations(ensureSupport(window.sessionStorage))};export{db as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opendb-store",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "A lightweight utility to manage browser storage (localStorage, sessionStorage, and cookies) with advanced features. Easily configure namespaces, key trimming, and data expiry.",
|
|
5
5
|
"main": "./dist/opendb-esm.js",
|
|
6
6
|
"type": "module",
|
package/src/config/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.0.
|
|
1
|
+
export const version = '1.0.3';
|