opendb-store 1.0.0

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.
Files changed (57) hide show
  1. package/.babelrc +3 -0
  2. package/.github/workflows/release.yml +72 -0
  3. package/.husky/pre-commit +1 -0
  4. package/.nvmrc +1 -0
  5. package/.prettierignore +3 -0
  6. package/.prettierrc +7 -0
  7. package/.releaserc +10 -0
  8. package/CHANGELOG.md +36 -0
  9. package/README.md +73 -0
  10. package/dist/opendb.esm.js +222 -0
  11. package/dist/opendb.esm.js.map +1 -0
  12. package/eslint.config.js +40 -0
  13. package/jest.config.js +24 -0
  14. package/package.json +79 -0
  15. package/public/index.html +67 -0
  16. package/public/main.dev.js +12 -0
  17. package/public/main.js +32 -0
  18. package/rollup.common.js +27 -0
  19. package/rollup.config.js +12 -0
  20. package/src/config/config.js +34 -0
  21. package/src/config/index.js +22 -0
  22. package/src/config/version.js +1 -0
  23. package/src/core/index.js +1 -0
  24. package/src/core/storage.js +11 -0
  25. package/src/core/support.js +13 -0
  26. package/src/errors/index.js +5 -0
  27. package/src/errors/isInvalidArg.js +6 -0
  28. package/src/index.js +1 -0
  29. package/src/modules/clear.js +3 -0
  30. package/src/modules/count.js +0 -0
  31. package/src/modules/from.js +7 -0
  32. package/src/modules/get.js +26 -0
  33. package/src/modules/getFormattedData.js +17 -0
  34. package/src/modules/has.js +3 -0
  35. package/src/modules/index.js +25 -0
  36. package/src/modules/key.js +3 -0
  37. package/src/modules/keys.js +9 -0
  38. package/src/modules/operations.js +11 -0
  39. package/src/modules/remove.js +7 -0
  40. package/src/modules/set.js +15 -0
  41. package/src/modules/setFormattedData.js +11 -0
  42. package/src/modules/trim.js +3 -0
  43. package/src/utils/expiry.js +3 -0
  44. package/src/utils/extend.js +10 -0
  45. package/src/utils/index.js +9 -0
  46. package/src/utils/isNull.js +4 -0
  47. package/src/utils/isUndefined.js +4 -0
  48. package/src/utils/parse.js +7 -0
  49. package/tests/clear.test.js +40 -0
  50. package/tests/expire.test.js +44 -0
  51. package/tests/get.test.js +58 -0
  52. package/tests/has.test.js +62 -0
  53. package/tests/opendb.test.js +118 -0
  54. package/tests/remove.test.js +38 -0
  55. package/webpack.common.js +26 -0
  56. package/webpack.dev.js +27 -0
  57. package/webpack.prod.js +22 -0
package/.babelrc ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "presets": ["@babel/preset-env"]
3
+ }
@@ -0,0 +1,72 @@
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"
@@ -0,0 +1 @@
1
+ npx lint-staged && npm test
package/.nvmrc ADDED
@@ -0,0 +1 @@
1
+ v21.7.3
@@ -0,0 +1,3 @@
1
+ dist/*
2
+ coverage/*
3
+ public/*
package/.prettierrc ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "tabWidth": 2,
3
+ "useTabs": false,
4
+ "semi": true,
5
+ "singleQuote": true,
6
+ "trailingComma": "es5"
7
+ }
package/.releaserc ADDED
@@ -0,0 +1,10 @@
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 ADDED
@@ -0,0 +1,36 @@
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
package/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # OpenDB
2
+
3
+ ## What is OpenDB?
4
+
5
+ > A lightweight utility to manage browser storage (localStorage, sessionStorage, and cookies) with advanced features. Easily configure namespaces, key trimming, and data expiry.
6
+
7
+ ## Core Database Object Method
8
+
9
+ local - Contain localStorage methods
10
+ session - Contain sessionStorage methods
11
+
12
+ ## Local Storage
13
+
14
+ > LocalStorage is a web storage that allows websites to store data persistently on a user's browser.
15
+
16
+ ```
17
+ db.local.methodname
18
+ ```
19
+
20
+ ## Session Storage
21
+
22
+ > SessionStorage is a web storage that stores data for the duration of a page session and is cleared when the browser or tab is closed.
23
+
24
+ ```
25
+ db.session.methodname
26
+ ```
27
+
28
+ ## Browser Support
29
+
30
+ Supports modern browsers including Chrome, Firefox, Safari, and Edge.
31
+
32
+ ## Demonstrating LocalStorage and SessionStorage with an Example
33
+
34
+ ```
35
+ <!DOCTYPE html>
36
+ <html lang="en">
37
+ <head>
38
+ <title>OpenDB</title>
39
+ </head>
40
+ <body>
41
+ <script src="opendb.js"></script>
42
+ <script>
43
+ (function () {
44
+ db.local.set('name', 'openDB');
45
+ console.log(db.local.get('name'));
46
+ }());
47
+ </script>
48
+ </body>
49
+ </html>
50
+ ```
51
+
52
+ ## Key Changes from the Old Approach
53
+
54
+ - Powerful Method: Enhanced functionality.
55
+ - ES6: Modern JavaScript features.
56
+ - Modular: Reusable and maintainable code.
57
+ - Namespacing: Organized and conflict-free.
58
+
59
+ For further details, see the [old-approach](https://github.com/pankajbisht/openDB/tree/v1-opendb) documentation.
60
+
61
+ ## List of Local and Session Storage Methods
62
+
63
+ ```
64
+ - set(key, value) :- stores data in local or session storage with a key and value
65
+
66
+ - get(key, defaultValue) :- retrieve data from local or session storage by key.
67
+
68
+ - has(key) :- check whether a specified key exists in local or session storage
69
+
70
+ - remove(key) :- remove a specific item from local or session storage
71
+
72
+ - clear() :- Empty the entire storage.
73
+ ```
@@ -0,0 +1,222 @@
1
+ const config$1 = {
2
+ namespace: 'app',
3
+ separator: '.',
4
+ trimKeys: true,
5
+ expiry: true,
6
+ };
7
+
8
+ function createNamespace(namespace) {
9
+ config$1.namespace = namespace;
10
+ }
11
+
12
+ function switchNamespace(namespace) {
13
+ config$1.namespace = namespace;
14
+ }
15
+
16
+ function getCurrentNamespace() {
17
+ return config$1.namespace;
18
+ }
19
+
20
+ function get$1() {
21
+ return config$1;
22
+ }
23
+
24
+ function setSeparator(separator) {
25
+ config$1.separator = separator;
26
+ }
27
+
28
+ function getSeparator() {
29
+ return config$1.separator;
30
+ }
31
+
32
+ function generateKey(key) {
33
+ return `${config$1.namespace}${config$1.separator}${key}`;
34
+ }
35
+
36
+ const version = '1.0.0';
37
+
38
+ var config = {
39
+ version,
40
+ createNamespace,
41
+ getCurrentNamespace,
42
+ switchNamespace,
43
+ get: get$1,
44
+ setSeparator,
45
+ getSeparator,
46
+ generateKey,
47
+ };
48
+
49
+ function from(namespace) {
50
+ if (namespace) {
51
+ switchNamespace(namespace);
52
+ }
53
+ }
54
+
55
+ function parse(value) {
56
+ try {
57
+ return JSON.parse(value);
58
+ } catch {
59
+ return value;
60
+ }
61
+ }
62
+
63
+ // Is a given variable undefined?
64
+ function isUndefined(obj) {
65
+ return obj === void 0;
66
+ }
67
+
68
+ // Is a given value equal to null?
69
+ function isNull(obj) {
70
+ return obj === null || obj === 'null';
71
+ }
72
+
73
+ var util = {
74
+ parse,
75
+ isUndefined,
76
+ isNull,
77
+ };
78
+
79
+ function isInvalidArg(key) {
80
+ return isUndefined(key) || isNull(key);
81
+ }
82
+
83
+ function get(key, defaultValue = null) {
84
+ if (isInvalidArg(key)) return null;
85
+ const namespacedKey = config.generateKey(key);
86
+ const value = this.storage.getItem(namespacedKey);
87
+
88
+ if (util.isNull(value)) {
89
+ return null;
90
+ }
91
+
92
+ try {
93
+ let parsedData = util.parse(value);
94
+
95
+ if (parsedData.expire && Date.now() > parsedData.expire) {
96
+ this.remove(key);
97
+ return defaultValue;
98
+ }
99
+
100
+ return parsedData.value;
101
+ } catch {
102
+ return defaultValue;
103
+ }
104
+ }
105
+
106
+ function set(key, value, options = {}) {
107
+ if (isInvalidArg(key)) return null;
108
+ const namespacedKey = config.generateKey(key);
109
+ const { expire } = options;
110
+
111
+ let items = {
112
+ value,
113
+ ...(expire ? { expire: Date.now() + expire } : {}),
114
+ };
115
+
116
+ this.storage.setItem(namespacedKey, JSON.stringify(items));
117
+ }
118
+
119
+ function has(key) {
120
+ return !!this.get(key);
121
+ }
122
+
123
+ function remove(key) {
124
+ const namespacedKey = config.generateKey(key);
125
+
126
+ return this.storage.removeItem(namespacedKey);
127
+ }
128
+
129
+ function clear() {
130
+ return this.storage.clear();
131
+ }
132
+
133
+ function key(index) {
134
+ return this.storage.key(index);
135
+ }
136
+
137
+ function keys() {
138
+ const keys = [];
139
+
140
+ for (let index = 0; index < this.storage.length; index++) {
141
+ keys.push(this.storage.key(index));
142
+ }
143
+
144
+ return keys;
145
+ }
146
+
147
+ function trim(key) {
148
+ return this.storage.get(key).trim();
149
+ }
150
+
151
+ function setFormattedData(key, obj) {
152
+ const seprator = getSeparator();
153
+
154
+ for (let k in obj) {
155
+ if (k in obj) {
156
+ this.set(`${key}${seprator}${k}`, obj[k]);
157
+ }
158
+ }
159
+ }
160
+
161
+ function getFormattedData(key) {
162
+ const result = {};
163
+ const seprator = getSeparator();
164
+
165
+ for (let i = 0, size = this.storage.length; i < size; i++) {
166
+ const completkey = this.key(i);
167
+ const [, objectkey, currentkey] = completkey.split(`${seprator}`, 3);
168
+
169
+ if (objectkey === key && currentkey) {
170
+ result[currentkey] = this.get(`${objectkey}${seprator}${currentkey}`);
171
+ }
172
+ }
173
+
174
+ return result;
175
+ }
176
+
177
+ var storageMethods = {
178
+ from,
179
+ get,
180
+ set,
181
+ has,
182
+ remove,
183
+ clear,
184
+ key,
185
+ keys,
186
+ trim,
187
+ getFormattedData,
188
+ setFormattedData,
189
+ };
190
+
191
+ function storageoperations(storage) {
192
+ return {
193
+ storage,
194
+ get count() {
195
+ return storage.length;
196
+ },
197
+ ...storageMethods,
198
+ };
199
+ }
200
+
201
+ function ensureSupport(storage) {
202
+ if (!storage) {
203
+ throw new Error('Storage is not supported in this environment.');
204
+ }
205
+ return storage;
206
+ }
207
+
208
+ function working(storage) {
209
+ if (!storage) {
210
+ return false;
211
+ }
212
+ return true;
213
+ }
214
+
215
+ const db = {
216
+ config,
217
+ local: storageoperations(ensureSupport(window.localStorage)),
218
+ session: storageoperations(ensureSupport(window.sessionStorage)),
219
+ };
220
+
221
+ export { db as default };
222
+ //# sourceMappingURL=opendb.esm.js.map
@@ -0,0 +1 @@
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,QAA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AgB;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;;;;"}
@@ -0,0 +1,40 @@
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 ADDED
@@ -0,0 +1,24 @@
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/package.json ADDED
@@ -0,0 +1,79 @@
1
+ {
2
+ "name": "opendb-store",
3
+ "version": "1.0.0",
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",
6
+ "type": "module",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "scripts": {
11
+ "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
+ "lint:fix": "eslint \"src/**/*.js\" \"tests/*.js\" \"public/*.js\" --fix",
19
+ "format": "prettier --write .",
20
+ "lint": "eslint \"src/**/*.js\" \"tests/*.js\" \"public/*.js\"",
21
+ "semantic-release": "semantic-release",
22
+ "prepare": "husky"
23
+ },
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/pankajbisht/openDB.git"
27
+ },
28
+ "keywords": [
29
+ "opendb"
30
+ ],
31
+ "author": "Pankaj Bisht",
32
+ "license": "ISC",
33
+ "bugs": {
34
+ "url": "https://github.com/pankajbisht/openDB/issues"
35
+ },
36
+ "homepage": "https://github.com/pankajbisht/openDB#readme",
37
+ "devDependencies": {
38
+ "@babel/plugin-transform-runtime": "^7.25.9",
39
+ "@babel/preset-env": "^7.26.7",
40
+ "@babel/runtime": "^7.26.7",
41
+ "@rollup/plugin-babel": "^6.0.4",
42
+ "@rollup/plugin-commonjs": "^28.0.2",
43
+ "@rollup/plugin-node-resolve": "^16.0.0",
44
+ "@semantic-release/changelog": "^6.0.3",
45
+ "@semantic-release/commit-analyzer": "^13.0.1",
46
+ "@semantic-release/git": "^10.0.1",
47
+ "@semantic-release/github": "^11.0.1",
48
+ "@semantic-release/release-notes-generator": "^14.0.3",
49
+ "babel-jest": "^29.7.0",
50
+ "babel-loader": "^9.2.1",
51
+ "eslint": "^9.19.0",
52
+ "eslint-config-prettier": "^10.0.1",
53
+ "eslint-plugin-prettier": "^5.2.3",
54
+ "husky": "^9.1.7",
55
+ "jest": "^29.7.0",
56
+ "jest-environment-jsdom": "^29.7.0",
57
+ "jest-html-reporter": "^3.10.2",
58
+ "lint-staged": "^15.4.3",
59
+ "prettier": "^3.4.2",
60
+ "rollup": "^4.34.0",
61
+ "semantic-release": "^24.2.1",
62
+ "terser-webpack-plugin": "^5.3.11",
63
+ "webpack": "^5.97.1",
64
+ "webpack-cli": "^6.0.1",
65
+ "webpack-merge": "^6.0.1"
66
+ },
67
+ "lint-staged": {
68
+ "src/**/*.js": [
69
+ "eslint --fix",
70
+ "prettier --write",
71
+ "git add"
72
+ ],
73
+ "tests/**/*.js": [
74
+ "eslint --fix",
75
+ "prettier --write",
76
+ "git add"
77
+ ]
78
+ }
79
+ }
@@ -0,0 +1,67 @@
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>
@@ -0,0 +1,12 @@
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
+ })()