opendb-store 1.0.0 → 1.0.2

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
@@ -1,6 +1,4 @@
1
- # OpenDB
2
-
3
- ## What is OpenDB?
1
+ ## What is opendb-store?
4
2
 
5
3
  > A lightweight utility to manage browser storage (localStorage, sessionStorage, and cookies) with advanced features. Easily configure namespaces, key trimming, and data expiry.
6
4
 
@@ -35,13 +33,13 @@ Supports modern browsers including Chrome, Firefox, Safari, and Edge.
35
33
  <!DOCTYPE html>
36
34
  <html lang="en">
37
35
  <head>
38
- <title>OpenDB</title>
36
+ <title>opendb store</title>
39
37
  </head>
40
38
  <body>
41
39
  <script src="opendb.js"></script>
42
40
  <script>
43
41
  (function () {
44
- db.local.set('name', 'openDB');
42
+ db.local.set('name', 'opendb store');
45
43
  console.log(db.local.get('name'));
46
44
  }());
47
45
  </script>
@@ -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.2';
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.2";var config={version:"1.0.2",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,39 +1,68 @@
1
1
  {
2
2
  "name": "opendb-store",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
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
+ "files": [
11
+ "src",
12
+ "dist/opendb-esm.js",
13
+ "dist/opendb-esm.min.js",
14
+ "README.md"
15
+ ],
10
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",
11
25
  "clean": "rm -rf dist",
12
- "build:dev": "webpack --config webpack.dev.js",
13
- "build:prod": "webpack --config webpack.prod.js",
14
- "build": "npm run build:dev && npm run build:prod",
15
- "build:rollup": "rollup -c",
16
- "test": "jest",
17
- "test:seq": "jest --runInBand",
18
26
  "lint:fix": "eslint \"src/**/*.js\" \"tests/*.js\" \"public/*.js\" --fix",
19
- "format": "prettier --write .",
20
- "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",
21
30
  "semantic-release": "semantic-release",
22
- "prepare": "husky"
31
+ "prepublishOnly": "npm run build"
23
32
  },
24
33
  "repository": {
25
34
  "type": "git",
26
- "url": "git+https://github.com/pankajbisht/openDB.git"
35
+ "url": "git+https://github.com/pankajbisht/opendb-store.git"
27
36
  },
28
37
  "keywords": [
29
- "opendb"
38
+ "opendb-store",
39
+ "opendb",
40
+ "store",
41
+ "localStorage",
42
+ "sessionStorage",
43
+ "state-management",
44
+ "data-storage",
45
+ "browser-storage",
46
+ "key-value-store",
47
+ "lightweight-storage",
48
+ "js-storage",
49
+ "persistent-storage",
50
+ "storage-utility",
51
+ "web-storage",
52
+ "cache",
53
+ "frontend-storage",
54
+ "react-storage",
55
+ "vanilla-js-storage",
56
+ "typescript-storage",
57
+ "localstore",
58
+ "sessionstore"
30
59
  ],
31
60
  "author": "Pankaj Bisht",
32
61
  "license": "ISC",
33
62
  "bugs": {
34
- "url": "https://github.com/pankajbisht/openDB/issues"
63
+ "url": "https://github.com/pankajbisht/opendb-store/issues"
35
64
  },
36
- "homepage": "https://github.com/pankajbisht/openDB#readme",
65
+ "homepage": "https://github.com/pankajbisht/opendb-store#readme",
37
66
  "devDependencies": {
38
67
  "@babel/plugin-transform-runtime": "^7.25.9",
39
68
  "@babel/preset-env": "^7.26.7",
@@ -59,6 +88,7 @@
59
88
  "prettier": "^3.4.2",
60
89
  "rollup": "^4.34.0",
61
90
  "semantic-release": "^24.2.1",
91
+ "terser": "^5.37.0",
62
92
  "terser-webpack-plugin": "^5.3.11",
63
93
  "webpack": "^5.97.1",
64
94
  "webpack-cli": "^6.0.1",
@@ -1 +1 @@
1
- export const version = '1.0.0';
1
+ export const version = '1.0.2';
@@ -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"}
package/.babelrc DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "presets": ["@babel/preset-env"]
3
- }
@@ -1,72 +0,0 @@
1
- name: Pull Request CI Pipeline
2
-
3
- on:
4
- push:
5
- branches:
6
- - master
7
- pull_request:
8
- branches:
9
- - master
10
-
11
- jobs:
12
- build:
13
- runs-on: ubuntu-latest
14
-
15
- steps:
16
- # Step 1: Checkout the code
17
- - name: Checkout code
18
- uses: actions/checkout@v2
19
-
20
- # Step 2: Set up Node.js
21
- - name: Set up Node.js
22
- uses: actions/setup-node@v2
23
- with:
24
- node-version-file: .nvmrc
25
-
26
- # Step 3: Install dependencies
27
- - name: Install dependencies
28
- run: npm install
29
-
30
- # Step 4: Ensure dist folder exists
31
- - name: Ensure dist folder exists
32
- run: mkdir -p dist
33
-
34
- # Step 5: Verify if dist folder exists before build
35
- - name: Verify dist folder before build
36
- run: ls -la dist || echo "dist folder does not exist"
37
-
38
- # Step 6: Run Rollup build
39
- - name: Run Rollup Build
40
- run: npm run build:rollup
41
-
42
- # Step 7: Verify if build files are generated
43
- - name: Verify dist folder after build
44
- run: ls -la dist || echo "dist folder is still empty"
45
-
46
- # Step 8: Configure Git User for Commit
47
- - name: Configure Git User for Commit
48
- run: |
49
- git config --global user.name "github-actions[bot]"
50
- git config --global user.email "github-actions[bot]@users.noreply.github.com"
51
-
52
- # Step 9: Add dist folder and commit changes if dist has changes
53
- - name: Add dist folder and commit changes
54
- run: |
55
- git diff --exit-code dist || (
56
- echo "Changes detected in dist folder"
57
- git add dist/
58
- git commit -m "chore: update dist files" || echo "No changes to commit"
59
- git push
60
- )
61
- env:
62
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63
-
64
- # Step 10: Run semantic-release
65
- - name: Run semantic-release
66
- run: npx semantic-release --debug
67
- env:
68
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
69
-
70
- # Step 11: Final message
71
- - name: Everything Done
72
- run: echo "🎉 Build and Release Process Completed Successfully"
package/.husky/pre-commit DELETED
@@ -1 +0,0 @@
1
- npx lint-staged && npm test
package/.nvmrc DELETED
@@ -1 +0,0 @@
1
- v21.7.3
package/.prettierignore DELETED
@@ -1,3 +0,0 @@
1
- dist/*
2
- coverage/*
3
- public/*
package/.prettierrc DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "tabWidth": 2,
3
- "useTabs": false,
4
- "semi": true,
5
- "singleQuote": true,
6
- "trailingComma": "es5"
7
- }
package/.releaserc DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "branches": ["master"],
3
- "plugins": [
4
- "@semantic-release/commit-analyzer",
5
- "@semantic-release/release-notes-generator",
6
- "@semantic-release/changelog",
7
- "@semantic-release/git",
8
- "@semantic-release/github"
9
- ]
10
- }
package/CHANGELOG.md DELETED
@@ -1,36 +0,0 @@
1
- ## [1.1.3](https://github.com/pankajbisht/openDB/compare/v1.1.2...v1.1.3) (2025-02-03)
2
-
3
-
4
- ### Bug Fixes
5
-
6
- * **path:** update package.json ([7c4adfe](https://github.com/pankajbisht/openDB/commit/7c4adfe0a1c65fc0c278dcf676c8f07f8063a42c))
7
-
8
- ## [1.1.2](https://github.com/pankajbisht/openDB/compare/v1.1.1...v1.1.2) (2025-02-03)
9
-
10
-
11
- ### Bug Fixes
12
-
13
- * **version:** update version ([b5f5300](https://github.com/pankajbisht/openDB/commit/b5f5300a4d78ca770ea3abaecab5c26e83367ef0))
14
-
15
- ## [1.1.1](https://github.com/pankajbisht/openDB/compare/v1.1.0...v1.1.1) (2025-02-03)
16
-
17
-
18
- ### Bug Fixes
19
-
20
- * **version:** update version ([c53bed9](https://github.com/pankajbisht/openDB/commit/c53bed927320efa46c66947a7524130b1c4c55cb))
21
-
22
- # [1.1.0](https://github.com/pankajbisht/openDB/compare/v1.0.0...v1.1.0) (2025-02-03)
23
-
24
-
25
- ### Features
26
-
27
- * **Added Husky** for Git hooks automation
28
- * **Integrated lint-staged** for pre-commit linting
29
- * **Implemented expiration support** for local storage
30
- * **Added more test cases** for improved coverage
31
-
32
- ### Features
33
-
34
- * initial setup with Webpack, Rollup, Jest, and CI/CD
35
- * lib has version
36
- * **remove:** implement logic to remove item from storage
@@ -1 +0,0 @@
1
- {"version":3,"file":"opendb.esm.js","sources":["../src/config/config.js","../src/config/version.js","../src/config/index.js","../src/modules/from.js","../src/utils/parse.js","../src/utils/isUndefined.js","../src/utils/isNull.js","../src/utils/index.js","../src/errors/isInvalidArg.js","../src/modules/get.js","../src/modules/set.js","../src/modules/has.js","../src/modules/remove.js","../src/modules/clear.js","../src/modules/key.js","../src/modules/keys.js","../src/modules/trim.js","../src/modules/setFormattedData.js","../src/modules/getFormattedData.js","../src/modules/index.js","../src/modules/operations.js","../src/core/support.js","../src/core/storage.js"],"sourcesContent":null,"names":["config","get"],"mappings":"AAAO,MAAMA,QAAM,GAAG;AACtB,EAAE,SAAS,EAAE,KAAK;AAClB,EAAE,SAAS,EAAE,GAAG;AAChB,EAAE,QAAQ,EAAE,IAAI;AAChB,EAAE,MAAM,EAAE,IAAI;AACd,CAAC;;AAEM,SAAS,eAAe,CAAC,SAAS,EAAE;AAC3C,EAAEA,QAAM,CAAC,SAAS,GAAG,SAAS;AAC9B;;AAEO,SAAS,eAAe,CAAC,SAAS,EAAE;AAC3C,EAAEA,QAAM,CAAC,SAAS,GAAG,SAAS;AAC9B;;AAEO,SAAS,mBAAmB,GAAG;AACtC,EAAE,OAAOA,QAAM,CAAC,SAAS;AACzB;;AAEO,SAASC,KAAG,GAAG;AACtB,EAAE,OAAOD,QAAM;AACf;;AAEO,SAAS,YAAY,CAAC,SAAS,EAAE;AACxC,EAAEA,QAAM,CAAC,SAAS,GAAG,SAAS;AAC9B;;AAEO,SAAS,YAAY,GAAG;AAC/B,EAAE,OAAOA,QAAM,CAAC,SAAS;AACzB;;AAEO,SAAS,WAAW,CAAC,GAAG,EAAE;AACjC,EAAE,OAAO,CAAC,EAAEA,QAAM,CAAC,SAAS,CAAC,EAAEA,QAAM,CAAC,SAAS,CAAC,EAAE,GAAG,CAAC,CAAC;AACvD;;ACjCO,MAAM,OAAO,GAAG,OAAO;;ACY9B,aAAe;AACf,EAAE,OAAO;AACT,EAAE,eAAe;AACjB,EAAE,mBAAmB;AACrB,EAAE,eAAe;AACjB,OAAEC,KAAG;AACL,EAAE,YAAY;AACd,EAAE,YAAY;AACd,EAAE,WAAW;AACb,CAAC;;ACnBc,SAAS,IAAI,CAAC,SA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AAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,QAAQ,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC;AAC3E;AACA;;AAEA,EAAE,OAAO,MAAM;AACf;;ACJA,qBAAe;AACf,EAAE,IAAI;AACN,EAAE,GAAG;AACL,EAAE,GAAG;AACL,EAAE,GAAG;AACL,EAAE,MAAM;AACR,EAAE,KAAK;AACP,EAAE,GAAG;AACL,EAAE,IAAI;AACN,EAAE,IAAI;AACN,EAAE,gBAAgB;AAClB,EAAE,gBAAgB;AAClB,CAAC;;ACtBM,SAAS,iBAAiB,CAAC,OAAO,EAAE;AAC3C,EAAE,OAAO;AACT,IAAI,OAAO;AACX,IAAI,IAAI,KAAK,GAAG;AAChB,MAAM,OAAO,OAAO,CAAC,MAAM;AAC3B,KAAK;AACL,IAAI,GAAG,cAAc;AACrB,GAAG;AACH;;ACVe,SAAS,aAAa,CAAC,OAAO,EAAE;AAC/C,EAAE,IAAI,CAAC,OAAO,EAAE;AAChB,IAAI,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC;AACpE;AACA,EAAE,OAAO,OAAO;AAChB;;AAEO,SAAS,OAAO,CAAC,OAAO,EAAE;AACjC,EAAE,IAAI,CAAC,OAAO,EAAE;AAChB,IAAI,OAAO,KAAK;AAChB;AACA,EAAE,OAAO,IAAI;AACb;;ACRK,MAAC,EAAE,GAAG;AACX,EAAE,MAAM;AACR,EAAE,KAAK,EAAE,iBAAiB,CAAC,aAAa,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;AAC9D,EAAE,OAAO,EAAE,iBAAiB,CAAC,aAAa,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;AAClE;;;;"}
package/eslint.config.js DELETED
@@ -1,40 +0,0 @@
1
- import pluginJs from '@eslint/js';
2
- import prettierPlugin from 'eslint-plugin-prettier';
3
- import prettierConfig from 'eslint-config-prettier';
4
-
5
- /** @type {import("eslint").Linter.FlatConfig[]} */
6
- export default [
7
- {
8
- files: ['src/**/*.{js,jsx}', 'public/**/*.{js,jsx}', 'tests/**/*.{js,jsx}'],
9
- ignores: ['dist/**', 'node_modules/**'],
10
- languageOptions: {
11
- ecmaVersion: 'latest',
12
- sourceType: 'module',
13
- globals: {
14
- window: 'readonly',
15
- document: 'readonly',
16
- console: 'readonly',
17
- fetch: 'readonly',
18
- navigator: 'readonly',
19
- setTimeout: 'readonly',
20
- Blob: 'readonly',
21
-
22
- describe: 'readonly',
23
- test: 'readonly',
24
- expect: 'readonly',
25
- beforeEach: 'readonly',
26
- afterEach: 'readonly',
27
- jest: 'readonly',
28
- },
29
- },
30
- plugins: {
31
- prettier: prettierPlugin,
32
- },
33
- rules: {
34
- 'prettier/prettier': ['error', { singleQuote: true }], // ⬅️ Explicitly enforce single quotes in Prettier
35
- quotes: ['error', 'single', { avoidEscape: true }], // ⬅️ Enforce single quotes in ESLint
36
- },
37
- },
38
- pluginJs.configs.recommended,
39
- prettierConfig,
40
- ];
package/jest.config.js DELETED
@@ -1,24 +0,0 @@
1
- export default {
2
- testEnvironment: 'jsdom', // Use "node" if not testing DOM
3
- verbose: true, // Show passed tests in console
4
- transform: {
5
- '^.+\\.js$': 'babel-jest', // Use Babel for JS files
6
- },
7
- moduleNameMapper: {
8
- '^@src(.*)$': '<rootDir>/src$1', // Webpack alias resolution
9
- },
10
- reporters: [
11
- 'default',
12
- [
13
- 'jest-html-reporter',
14
- {
15
- outputPath: 'jest-report.html',
16
- includeConsoleLog: true, // Adds console logs to HTML report
17
- includeSuiteFailure: true, // Includes failing test suites
18
- includeFailureMsg: true,
19
- includePassedTests: true, // ✅ This ensures passed tests appear in the HTML report
20
- includePendingTests: true, // ✅ If there are skipped tests, show them too
21
- },
22
- ],
23
- ],
24
- };
package/public/index.html DELETED
@@ -1,67 +0,0 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <title>openDB</title>
5
- <meta charset="UTF-8" />
6
- <meta name="name" content="content" />
7
- <style>
8
- * {
9
- padding: 0;
10
- margin: 0;
11
- }
12
- .row {
13
- padding: 20px 10px;
14
- }
15
- #name {
16
- color: red;
17
- font-weight: bold;
18
- }
19
- blockquote {
20
- background: #f9f9f9;
21
- border-left: 5px solid #ccc;
22
- padding: 0.5em 10px;
23
- }
24
- .indicator {
25
- display: inline-block;
26
- width: 12px;
27
- height: 12px;
28
- background: red;
29
- border-radius: 12px;
30
- }
31
- </style>
32
- </head>
33
- <body>
34
- <blockquote>
35
- <p class="row">
36
- At the starting your storage has no value after fill form and submit the
37
- form your storage is set now you can see the change and if you reload
38
- the page value is received from local db.
39
- </p>
40
- </blockquote>
41
-
42
- <div class="row">
43
- <p>
44
- Your name was:
45
- <label class="indicator"></label>
46
- <span id="name"> Local storage is Empty </span>
47
- </p>
48
- </div>
49
-
50
- <form name="form">
51
- <div class="row">
52
- <label for="input">Name:</label>
53
- <input
54
- type="text"
55
- placeholder="Enter the name"
56
- name="name"
57
- id="input"
58
- />
59
- <input type="submit" />
60
- </div>
61
- </form>
62
-
63
- <!-- <script src="../dist/opendb.js"></script> -->
64
- <script type="module" src="./main.js"></script>
65
- <script type="module" src="./main.dev.js"></script>
66
- </body>
67
- </html>
@@ -1,12 +0,0 @@
1
- import db from "../dist/opendb.esm.js"
2
-
3
- db.local.set('name', 'opendb');
4
- console.log(db.local.get('name'));
5
-
6
- (async() => {
7
- db.local.set('expiringKey', 'value', { expire: 500 });
8
- await new Promise((resolve) => setTimeout(resolve, 600));
9
- const result = db.local.get('expiringKey');
10
-
11
- console.log("The result is:", result);
12
- })()
package/public/main.js DELETED
@@ -1,32 +0,0 @@
1
- import db from "../dist/opendb.esm.js"
2
-
3
- (function () {
4
- var dom = document.getElementById("name"),
5
- form = document.forms["form"];
6
-
7
- if (db.local.has("name")) {
8
- domStylingAfterStore(() => {
9
- console.log("Get Data From Store");
10
- });
11
- }
12
-
13
- function domStylingAfterStore(callback) {
14
- dom.textContent = db.local.get("name");
15
- dom.style.color = "green";
16
- dom.previousElementSibling.style.background = "green";
17
-
18
- callback();
19
- }
20
-
21
- form.onsubmit = function () {
22
- var val = this["name"].value;
23
- dom.textContent = val;
24
- db.local.set("name", val);
25
-
26
- domStylingAfterStore(() => {
27
- this["name"].value = "";
28
- });
29
-
30
- return false;
31
- };
32
- })();
package/rollup.common.js DELETED
@@ -1,27 +0,0 @@
1
- import { readFileSync } from 'fs';
2
- import extend from './src/utils/extend.js';
3
-
4
- var intro = readFileSync('src/index.js', 'utf-8').split('\n').slice(3, 7).join('\n');
5
-
6
- var outputBase = {
7
- strict: false,
8
- externalLiveBindings: false,
9
- freeze: false,
10
- };
11
-
12
- var sourcemapBase = {
13
- sourcemap: true,
14
- sourcemapExcludeSources: true,
15
- };
16
-
17
- export function outputConf(particular) {
18
- return extend(particular, outputBase);
19
- }
20
-
21
- export function sourcemapConf(particular) {
22
- return extend(particular, outputBase, sourcemapBase);
23
- }
24
-
25
- export function monolithConf(particular) {
26
- return extend(particular, outputBase, sourcemapBase, {intro});
27
- }
package/rollup.config.js DELETED
@@ -1,12 +0,0 @@
1
- import { monolithConf } from './rollup.common.js';
2
-
3
- export default [
4
- {
5
- input: 'src/index.js',
6
- treeshake: false,
7
- output: monolithConf({
8
- file: 'dist/opendb.esm.js',
9
- format: 'esm',
10
- }),
11
- },
12
- ]
@@ -1,40 +0,0 @@
1
- import db from '../src/index.js';
2
-
3
- describe('Clear Method', () => {
4
- beforeEach(() => {
5
- db.local.clear(); // Ensure storage is empty before each test
6
- });
7
-
8
- test('should clear all keys from storage', () => {
9
- db.local.set('key1', 'value1');
10
- db.local.set('key2', 'value2');
11
- db.local.clear();
12
-
13
- expect(db.local.get('key1')).toBeNull();
14
- expect(db.local.get('key2')).toBeNull();
15
- });
16
-
17
- test('should return false in has() for all keys after clear', () => {
18
- db.local.set('key1', 'value1');
19
- db.local.set('key2', 'value2');
20
- db.local.clear();
21
-
22
- expect(db.local.has('key1')).toBeFalsy();
23
- expect(db.local.has('key2')).toBeFalsy();
24
- });
25
-
26
- test('should work correctly when storage is already empty', () => {
27
- db.local.clear(); // Clearing an already empty storage should not throw an error
28
- expect(() => db.local.clear()).not.toThrow();
29
- });
30
-
31
- test('should remove expired and non-expired keys alike', async () => {
32
- db.local.set('key1', 'value1', { expires: 500 }); // Expires in 500ms
33
- db.local.set('key2', 'value2'); // No expiration
34
- await new Promise((resolve) => setTimeout(resolve, 600)); // Wait for key1 to expire
35
- db.local.clear();
36
-
37
- expect(db.local.has('key1')).toBeFalsy();
38
- expect(db.local.has('key2')).toBeFalsy();
39
- });
40
- });
@@ -1,44 +0,0 @@
1
- import db from '../src/index.js';
2
-
3
- describe('Expiration Handling', () => {
4
- beforeEach(() => {
5
- db.local.clear();
6
- });
7
-
8
- test('1. should return null if key has expired', async () => {
9
- db.local.set('expiringKey', 'value', { expire: 500 }); // Expires in 500ms
10
- await new Promise((resolve) => setTimeout(resolve, 600)); // Wait for 600ms
11
- const result = db.local.get('expiringKey');
12
- expect(result).toBeNull();
13
- });
14
-
15
- test('2. should return value if key has not expired', async () => {
16
- db.local.set('validKey', 'value', { expire: 1000 }); // Expires in 1s
17
- await new Promise((resolve) => setTimeout(resolve, 500)); // Wait 500ms (still valid)
18
- const result = db.local.get('validKey');
19
- expect(result).toBe('value');
20
- });
21
-
22
- test('3. should return false in has() if key has expired', async () => {
23
- db.local.set('expiredKey', 'value', { expire: 300 }); // Expires in 300ms
24
- await new Promise((resolve) => setTimeout(resolve, 400)); // Wait for 400ms
25
- const result = db.local.has('expiredKey');
26
- expect(result).toBeFalsy();
27
- });
28
-
29
- test('4. should return true in has() if key has not expired', async () => {
30
- db.local.set('activeKey', 'value', { expire: 1000 }); // Expires in 1s
31
- await new Promise((resolve) => setTimeout(resolve, 500)); // Wait 500ms (still valid)
32
- const result = db.local.has('activeKey');
33
- expect(result).toBeTruthy();
34
- });
35
-
36
- test('5. should refresh expiration time if key is updated before expiration', async () => {
37
- db.local.set('refreshKey', 'value', { expire: 1000 }); // Expires in 1s
38
- await new Promise((resolve) => setTimeout(resolve, 500)); // Wait 500ms
39
- db.local.set('refreshKey', 'newValue', { expire: 1000 }); // Reset expiry
40
- await new Promise((resolve) => setTimeout(resolve, 700)); // Total 1.2s from initial set
41
- const result = db.local.get('refreshKey');
42
- expect(result).toBe('newValue'); // Should still be available
43
- });
44
- });
package/tests/get.test.js DELETED
@@ -1,58 +0,0 @@
1
- import db from '../src/index.js';
2
-
3
- describe('get Method', () => {
4
- beforeEach(() => {
5
- db.local.clear();
6
- });
7
-
8
- test('should return null if key does not exist in localStorage', () => {
9
- const result = db.local.get();
10
- expect(result).toBeNull();
11
- });
12
-
13
- test('should return null if key does not exist in localStorage', () => {
14
- const result = db.local.get('nonexistentKey');
15
- expect(result).toBeNull();
16
- });
17
-
18
- test('should return null if key is undefined', () => {
19
- const result = db.local.get(undefined);
20
- expect(result).toBeNull();
21
- });
22
-
23
- test('should return null if key is null', () => {
24
- const result = db.local.get(null);
25
- expect(result).toBeNull();
26
- });
27
-
28
- test('should return null if key is empty string', () => {
29
- const result = db.local.get('');
30
- expect(result).toBeNull();
31
- });
32
-
33
- test('should return the stored value if key exists', () => {
34
- db.local.set('testKey', 'testValue');
35
- const result = db.local.get('testKey');
36
- expect(result).toBe('testValue');
37
- });
38
-
39
- test('should return a number if stored value is a number', () => {
40
- db.local.set('numberKey', 42);
41
- const result = db.local.get('numberKey');
42
- expect(result).toBe(42);
43
- });
44
-
45
- test('should return an object if stored value is an object', () => {
46
- const obj = { a: 1, b: 2 };
47
- db.local.set('objectKey', obj);
48
- const result = db.local.get('objectKey');
49
- expect(result).toEqual(obj);
50
- });
51
-
52
- test('should return an array if stored value is an array', () => {
53
- const arr = [1, 2, 3];
54
- db.local.set('arrayKey', arr);
55
- const result = db.local.get('arrayKey');
56
- expect(result).toEqual(arr);
57
- });
58
- });
package/tests/has.test.js DELETED
@@ -1,62 +0,0 @@
1
- import db from '../src/index.js';
2
-
3
- describe('has Method', () => {
4
- beforeEach(() => {
5
- db.local.clear();
6
- });
7
-
8
- test('1. should return false if key does not exist in localStorage', () => {
9
- const result = db.local.has();
10
- expect(result).toBeFalsy();
11
- });
12
-
13
- test('2. should return false if key does not exist in localStorage', () => {
14
- const result = db.local.has('nonexistentKey');
15
- expect(result).toBeFalsy();
16
- });
17
-
18
- test('3. should return false if key is undefined', () => {
19
- const result = db.local.has(undefined);
20
- expect(result).toBeFalsy();
21
- });
22
-
23
- test('4. should return false if key is null', () => {
24
- const result = db.local.has(null);
25
- expect(result).toBeFalsy();
26
- });
27
-
28
- test('5. should return false if key is empty string', () => {
29
- const result = db.local.has('');
30
- expect(result).toBeFalsy();
31
- });
32
-
33
- test('6. should return true if key is present', () => {
34
- db.local.set('testkey', 'testvalue');
35
- const result = db.local.has('testkey');
36
- expect(result).toBe(true);
37
- });
38
-
39
- test('7. should return true if number key is present', () => {
40
- db.local.set(123, 'testvalue');
41
- const result = db.local.has(123);
42
- expect(result).toBe(true);
43
- });
44
-
45
- test('8. should return true if key exists but has an empty string as value', () => {
46
- db.local.set('emptyStringKey', '');
47
- const result = db.local.has('emptyStringKey');
48
- expect(result).toBe(false);
49
- });
50
-
51
- test('9. should return true if key exists but value is null', () => {
52
- db.local.set('nullKey', null);
53
- const result = db.local.has('nullKey');
54
- expect(result).toBe(false);
55
- });
56
-
57
- test('10. should return true if key exists but value is undefined', () => {
58
- db.local.set('undefinedKey', undefined);
59
- const result = db.local.has('undefinedKey');
60
- expect(result).toBe(false);
61
- });
62
- });
@@ -1,118 +0,0 @@
1
- import db from '../src/index.js';
2
- import errorFunctions from '../src/errors/index.js';
3
-
4
- jest.mock('../src/errors/index.js', () => ({
5
- isInvalidArg: jest.fn().mockReturnValue(undefined),
6
- }));
7
-
8
- describe('OpenDB Unit Test Case', () => {
9
- describe('Config Module', () => {
10
- test('getCurrentNamespace should return the default namespace', () => {
11
- expect(db.config.getCurrentNamespace()).toBe('app');
12
- db.config.createNamespace('todo');
13
- expect(db.config.getCurrentNamespace()).toBe('todo');
14
- });
15
-
16
- test('createNamespace create new namespace and should return the current namespace', () => {
17
- db.config.createNamespace('todo');
18
- expect(db.config.getCurrentNamespace()).toBe('todo');
19
- });
20
-
21
- test('switchNamespace switch namespace and should return the current namespace', () => {
22
- db.config.createNamespace('app');
23
- expect(db.config.getCurrentNamespace()).toBe('app');
24
- });
25
-
26
- test('getSeparator get default separator(.)', () => {
27
- expect(db.config.getSeparator()).toBe('.');
28
- });
29
-
30
- test('setSeparator set default new separator', () => {
31
- db.config.setSeparator('-');
32
- expect(db.config.getSeparator()).toBe('-');
33
- });
34
- });
35
-
36
- describe('Error Module', () => {
37
- test('isInvalidArg should return undefined if key is undefined', () => {
38
- const result = errorFunctions.isInvalidArg();
39
- expect(result).toBeUndefined();
40
- });
41
- });
42
-
43
- describe('Storage Module', () => {
44
- describe('get Method', () => {
45
- beforeEach(() => {
46
- db.local.clear();
47
- });
48
-
49
- test('should return null if key does not exist in localStorage', () => {
50
- const result = db.local.get();
51
- expect(result).toBeNull();
52
- });
53
-
54
- test('should return null if key does not exist in localStorage', () => {
55
- const result = db.local.get('nonexistentKey');
56
- expect(result).toBeNull();
57
- });
58
-
59
- test('should return null if key is undefined', () => {
60
- const result = db.local.get(undefined);
61
- expect(result).toBeNull();
62
- });
63
-
64
- test('should return null if key is null', () => {
65
- const result = db.local.get(null);
66
- expect(result).toBeNull();
67
- });
68
-
69
- test('should return null if key is empty string', () => {
70
- const result = db.local.get('');
71
- expect(result).toBeNull();
72
- });
73
- });
74
-
75
- describe('has Method', () => {
76
- beforeEach(() => {
77
- db.local.clear();
78
- });
79
-
80
- test('should return false if key does not exist in localStorage', () => {
81
- const result = db.local.has();
82
- expect(result).toBeFalsy();
83
- });
84
-
85
- test('should return false if key does not exist in localStorage', () => {
86
- const result = db.local.has('nonexistentKey');
87
- expect(result).toBeFalsy();
88
- });
89
-
90
- test('should return false if key is undefined', () => {
91
- const result = db.local.has(undefined);
92
- expect(result).toBeFalsy();
93
- });
94
-
95
- test('should return false if key is null', () => {
96
- const result = db.local.has(null);
97
- expect(result).toBeFalsy();
98
- });
99
-
100
- test('should return false if key is empty string', () => {
101
- const result = db.local.has('');
102
- expect(result).toBeFalsy();
103
- });
104
-
105
- test('should return true if key is present', () => {
106
- db.local.set('testkey', 'testvalue');
107
- const result = db.local.has('testkey');
108
- expect(result).toBe(true);
109
- });
110
-
111
- test('should return true if number key is present', () => {
112
- db.local.set(123, 'testvalue');
113
- const result = db.local.has(123);
114
- expect(result).toBe(true);
115
- });
116
- });
117
- });
118
- });
@@ -1,38 +0,0 @@
1
- import db from '../src/index.js';
2
-
3
- describe('Remove Method', () => {
4
- beforeEach(() => {
5
- db.local.clear();
6
- });
7
-
8
- test('should remove an existing key', () => {
9
- db.local.set('testKey', 'testValue');
10
- db.local.remove('testKey');
11
- const result = db.local.get('testKey');
12
- expect(result).toBeNull();
13
- });
14
-
15
- test('should not throw error if removing non-existent key', () => {
16
- expect(() => db.local.remove('nonExistentKey')).not.toThrow();
17
- });
18
-
19
- test('should return false in has() after removing a key', () => {
20
- db.local.set('removableKey', 'value');
21
- db.local.remove('removableKey');
22
- expect(db.local.has('removableKey')).toBeFalsy();
23
- });
24
-
25
- test('should remove a key before expiration', async () => {
26
- db.local.set('shortLivedKey', 'value', { expires: 2000 }); // Expires in 2s
27
- db.local.remove('shortLivedKey'); // Remove it immediately
28
- const result = db.local.get('shortLivedKey');
29
- expect(result).toBeNull();
30
- });
31
-
32
- test('should remove an expired key', async () => {
33
- db.local.set('expiredKey', 'value', { expires: 500 }); // Expires in 500ms
34
- await new Promise((resolve) => setTimeout(resolve, 600)); // Wait 600ms (ensuring expiration)
35
- db.local.remove('expiredKey');
36
- expect(db.local.has('expiredKey')).toBeFalsy();
37
- });
38
- });
package/webpack.common.js DELETED
@@ -1,26 +0,0 @@
1
- import path from 'path';
2
-
3
- export default {
4
- entry: './src/index.js', // Your main entry point
5
- output: {
6
- path: path.resolve('dist'),
7
- clean: true, // Clean the output directory before every build
8
- },
9
- resolve: {
10
- extensions: ['.js', '.json', '.jsx', '.mjs'], // Ensure proper extensions are resolved
11
- },
12
- module: {
13
- rules: [
14
- {
15
- test: /\.js$/,
16
- exclude: /node_modules/,
17
- use: {
18
- loader: 'babel-loader',
19
- options: {
20
- presets: ['@babel/preset-env'],
21
- },
22
- },
23
- },
24
- ],
25
- },
26
- };
package/webpack.dev.js DELETED
@@ -1,27 +0,0 @@
1
- import { merge } from 'webpack-merge';
2
- import common from './webpack.common.js';
3
- import path from 'path';
4
- import fs from 'fs';
5
-
6
- // Read package.json to get the library name
7
- const pkg = JSON.parse(fs.readFileSync(path.resolve('package.json'), 'utf-8'));
8
- const libraryName = pkg.name;
9
-
10
- export default merge(common, {
11
- mode: 'development',
12
- output: {
13
- filename: `${libraryName}.js`, // Generates opendb.js and opendb.min.js
14
- // library: 'output.db[.name]', // Global variable when used in <script>
15
- libraryTarget: 'module', // Universal module format
16
- // libraryExport: 'default', // Exports "db" as default
17
- // globalObject: 'this', // Ensures compatibility in Node.js
18
- // iife: true,
19
- },
20
- devtool: 'source-map', // Enable source maps for easier debugging
21
- optimization: {
22
- minimize: false, // Disable minification in development mode
23
- },
24
- experiments: {
25
- outputModule: true,
26
- },
27
- });
package/webpack.prod.js DELETED
@@ -1,22 +0,0 @@
1
- import { merge } from 'webpack-merge';
2
- import common from './webpack.common.js';
3
- import path from 'path';
4
- import fs from 'fs';
5
-
6
- // Read package.json to get the library name
7
- const pkg = JSON.parse(fs.readFileSync(path.resolve('package.json'), 'utf-8'));
8
- const libraryName = pkg.name;
9
-
10
- export default merge(common, {
11
- mode: 'production',
12
- output: {
13
- filename: `${libraryName}.min.js`, // Non-minified version for development
14
- library: 'db', // The global variable name for your library
15
- libraryTarget: 'umd',
16
- // globalObject: 'this',
17
- },
18
- devtool: 'source-map', // Enable source maps for easier debugging
19
- optimization: {
20
- minimize: true, // Disable minification in development mode
21
- },
22
- });