opendb-store 1.0.1 → 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 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.
@@ -33,7 +33,7 @@ function generateKey(key) {
33
33
  return `${config$1.namespace}${config$1.separator}${key}`;
34
34
  }
35
35
 
36
- const version = '1.0.0';
36
+ const version = '1.0.3';
37
37
 
38
38
  var config = {
39
39
  version,
@@ -205,13 +205,6 @@ function ensureSupport(storage) {
205
205
  return storage;
206
206
  }
207
207
 
208
- function working(storage) {
209
- if (!storage) {
210
- return false;
211
- }
212
- return true;
213
- }
214
-
215
208
  const db = {
216
209
  config,
217
210
  local: storageoperations(ensureSupport(window.localStorage)),
@@ -219,4 +212,4 @@ const db = {
219
212
  };
220
213
 
221
214
  export { db as default };
222
- //# sourceMappingURL=opendb.esm.js.map
215
+ //# sourceMappingURL=opendb-esm.js.map
@@ -0,0 +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.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,30 +1,34 @@
1
1
  {
2
2
  "name": "opendb-store",
3
- "version": "1.0.1",
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
- "main": "./dist/opendb.esm.js",
5
+ "main": "./dist/opendb-esm.js",
6
6
  "type": "module",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
10
10
  "files": [
11
11
  "src",
12
- "dist/opendb.esm.js",
12
+ "dist/opendb-esm.js",
13
+ "dist/opendb-esm.min.js",
13
14
  "README.md"
14
15
  ],
15
16
  "scripts": {
17
+ "prepare": "husky",
18
+ "lint": "eslint src/**/*.js tests/*.js",
19
+ "format": "prettier --write .",
20
+ "bundle": "npm run module-package-json && rollup -c && eslint dist/opendb-esm.js",
21
+ "module-package-json": "echo \"export const version = '${npm_package_version}';\" > src/config/version.js",
22
+ "prepare-tests": "npm run bundle",
23
+ "test-node": "jest",
24
+ "test": "npm run lint && npm run prepare-tests && npm run test-node",
16
25
  "clean": "rm -rf dist",
17
- "build:dev": "webpack --config webpack.dev.js",
18
- "build:prod": "webpack --config webpack.prod.js",
19
- "build": "npm run build:dev && npm run build:prod",
20
- "build:rollup": "rollup -c",
21
- "test": "jest",
22
- "test:seq": "jest --runInBand",
23
26
  "lint:fix": "eslint \"src/**/*.js\" \"tests/*.js\" \"public/*.js\" --fix",
24
- "format": "prettier --write .",
25
- "lint": "eslint \"src/**/*.js\" \"tests/*.js\" \"public/*.js\"",
27
+ "minify-esm": "npx terser dist/opendb-esm.js -o dist/opendb-esm.min.js --compress --mangle",
28
+ "build-esm": "npm run minify-esm",
29
+ "build": "npm run bundle && npm run build-esm",
26
30
  "semantic-release": "semantic-release",
27
- "prepare": "husky"
31
+ "prepublishOnly": "npm run build"
28
32
  },
29
33
  "repository": {
30
34
  "type": "git",
@@ -84,6 +88,7 @@
84
88
  "prettier": "^3.4.2",
85
89
  "rollup": "^4.34.0",
86
90
  "semantic-release": "^24.2.1",
91
+ "terser": "^5.37.0",
87
92
  "terser-webpack-plugin": "^5.3.11",
88
93
  "webpack": "^5.97.1",
89
94
  "webpack-cli": "^6.0.1",
@@ -1 +1 @@
1
- export const version = '1.0.1';
1
+ export const version = '1.0.3';
@@ -4,10 +4,3 @@ export default function ensureSupport(storage) {
4
4
  }
5
5
  return storage;
6
6
  }
7
-
8
- export function working(storage) {
9
- if (!storage) {
10
- return false;
11
- }
12
- return true;
13
- }
@@ -0,0 +1 @@
1
+ {"type":"module","version":"1.0.1"}