├── .eslintignore ├── .prettierignore ├── .coveralls.yml ├── .gitignore ├── .dockerignore ├── images └── nds-work.png ├── src ├── index.ts ├── utils │ ├── next.ts │ ├── error.ts │ ├── matchProperty.ts │ ├── validator.ts │ └── storage.ts └── lib │ └── index.ts ├── .prettierrc ├── .npmignore ├── .editorconfig ├── jest.config.ts ├── .github ├── dependabot.yml └── workflows │ └── codeql-analysis.yml ├── CONTRIBUTING.md ├── Dockerfile ├── tsconfig.json ├── .travis.yml ├── Makefile ├── .eslintrc ├── LICENSE.md ├── package.json ├── __test__ └── index.test.ts ├── CODE_OF_CONDUCT.md ├── README_v2.md └── README.md /.eslintignore: -------------------------------------------------------------------------------- 1 | esm 2 | dist 3 | node_modules 4 | coverage 5 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | esm 2 | dist 3 | node_modules 4 | coverage 5 | -------------------------------------------------------------------------------- /.coveralls.yml: -------------------------------------------------------------------------------- 1 | service_name: travis-pro 2 | repo_token: kHnxgz0L2DtfjatCNAI9DVQcp9rxyXWGK -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | coverage 3 | app 4 | dist 5 | esm 6 | config 7 | index.js -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | esm 2 | dist 3 | node_modules 4 | coverage 5 | images 6 | .github 7 | __test__ 8 | -------------------------------------------------------------------------------- /images/nds-work.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/restuwahyu13/node-disk-storage/HEAD/images/nds-work.png -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * node-disk-storage 3 | * @author Copyright(c) 2021 by Restu wahyu saputra 4 | * MIT Licensed 5 | */ 6 | 7 | export { NDS as NodeDiskStorage } from './lib' 8 | -------------------------------------------------------------------------------- /src/utils/next.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * node-disk-storage 3 | * @author Copyright(c) 2021 by Restu wahyu saputra 4 | * MIT Licensed 5 | */ 6 | 7 | export const next = (): boolean => { 8 | process.nextTick(() => 'next to step') 9 | return true 10 | } 11 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "tabWidth": 2, 3 | "useTabs": true, 4 | "trailingComma": "none", 5 | "singleQuote": true, 6 | "semi": false, 7 | "bracketSpacing": true, 8 | "proseWrap": "always", 9 | "printWidth": 160, 10 | "quoteProps": "consistent" 11 | } 12 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | **/** 2 | __test__ 3 | coverage 4 | dist 5 | esm 6 | config 7 | node_modules 8 | .coveralls.yml 9 | .editorconfig 10 | .eslintignore 11 | .eslintrc 12 | .gitignore 13 | .prettierrc 14 | .travis.yml 15 | config.ts 16 | Dockerfile 17 | jest.config.js 18 | Makefile 19 | tsconfig.json 20 | package-lock.json 21 | kraken.config.json 22 | demo 23 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # Global 2 | [*] 3 | root = true 4 | charset = utf-8 5 | end_of_line = lf 6 | 7 | # Global Indent and Indent Style Specific Ext 8 | [*.{ts,yml,spect.ts,test,ts,json}] 9 | indent_size = 2 10 | indent_style = tab 11 | 12 | # Makefile And Dockerfile Global Indent and Indent Style 13 | [Makefile, Dockerfile] 14 | indent_size = 3 15 | indent_style = tab -------------------------------------------------------------------------------- /src/utils/error.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * node-disk-storage 3 | * @author Copyright(c) 2021 by Restu wahyu saputra 4 | * MIT Licensed 5 | */ 6 | 7 | export class NodeDiskStorageError extends Error { 8 | constructor(message: string) { 9 | super(message) 10 | this.name = this.constructor.name 11 | this.message = message 12 | Error.captureStackTrace(this, this.constructor) 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/utils/matchProperty.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * node-disk-storage 3 | * @author Copyright(c) 2021 by Restu wahyu saputra 4 | * MIT Licensed 5 | */ 6 | 7 | export const matchProperty = (compare: Record): boolean | undefined => { 8 | const defaultProperty = { minSize: undefined, maxSize: undefined } 9 | const compareIn: string[] = Object.keys(compare) 10 | const newInData: boolean[] = compareIn.map((v) => `${v}` in defaultProperty) 11 | return newInData.includes(false) ? undefined : true 12 | } 13 | -------------------------------------------------------------------------------- /jest.config.ts: -------------------------------------------------------------------------------- 1 | const config = { 2 | preset: 'ts-jest', 3 | testEnvironment: 'node', 4 | moduleFileExtensions: ['ts', 'js'], 5 | testMatch: ['/test/**/*.{test.ts, spec.ts}', '/__test__/**/*.{test.ts, spec.ts}'], 6 | collectCoverageFrom: ['src/lib/**/*'], 7 | testPathIgnorePatterns: ['node_modules/', 'dist/', 'esm', 'tsconfig.json', 'coverage/', '.github'], 8 | coveragePathIgnorePatterns: ['node_modules/', 'dist/', 'esm/', 'tsconfig.json', 'coverage/', '.github', 'images'] 9 | } 10 | 11 | export default config 12 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: npm 4 | target-branch: 'main' 5 | directory: '/' 6 | schedule: 7 | interval: weekly 8 | day: monday 9 | time: '19:00' 10 | timezone: 'Asia/Jakarta' 11 | ignore: 12 | - dependency-name: '*.@types' 13 | open-pull-requests-limit: 30 14 | versioning-strategy: 'increase-if-necessary' 15 | commit-message: 16 | prefix: 'dependencies' 17 | prefix-development: 'devDependencies' 18 | include: 'scope' 19 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing 2 | 3 | - Fork it **https://github.com/restuwahyu13/node-disk-storage/fork** 4 | - Create your feature branch `git checkout -b my-new-feature` 5 | - Add changes `git add changed-path` 6 | - Commit your changes `git commit -m 'Add some feature'` 7 | - Push to the branch `git push origin my-new-feature` 8 | - Create a new Pull Request 9 | 10 | ### Important Rules! 11 | 12 | - Please follow the existing standard code 13 | - Please Use Linter And Formatter Like Eslint or Prettier 14 | - Please test your code first before create a new pull request 15 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | ## BUILD STAGE ONE 2 | 3 | FROM node:14-alpine as node-disk-storage 4 | COPY package*.json \ 5 | .coveralls.yml \ 6 | .editorconfig \ 7 | .gitignore \ 8 | .npmignore \ 9 | .prettierignore \ 10 | .prettierrc \ 11 | .eslintignore \ 12 | .eslintrc \ 13 | .travis.yml \ 14 | config.ts \ 15 | jest.config.ts \ 16 | Makefile ./ 17 | COPY . ./ 18 | RUN apk add make \ 19 | && make install 20 | 21 | ## BUILD STAGE TWO 22 | 23 | FROM node-disk-storage 24 | WORKDIR /usr/src/app 25 | COPY --from=node-disk-storage ./ /usr/src/app 26 | RUN make build 27 | CMD docker images -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "dist", 4 | "target": "ESNext", 5 | "module": "UMD", 6 | "moduleResolution": "Node", 7 | "esModuleInterop": true, 8 | "allowSyntheticDefaultImports": true, 9 | "emitDecoratorMetadata": true, 10 | "experimentalDecorators": true, 11 | "allowUmdGlobalAccess": true, 12 | "downlevelIteration": true, 13 | "skipLibCheck": true, 14 | "declaration": true, 15 | "noEmitOnError": true, 16 | "strict": true, 17 | "noImplicitAny": false, 18 | "typeRoots": ["node_modules/@types"] 19 | }, 20 | "include": ["src/**/*.ts"], 21 | "exclude": ["node_modules", "dist", "__test__/**/*.{test.ts,spec.ts}", "coverage", ".github"] 22 | } 23 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - node 4 | - 14 5 | - 12 6 | env: 7 | global: 8 | - COVERALLS_PARALLEL=true 9 | - COVERALLS_SERVICE_NAME=travis-pro 10 | - COVERALLS_REPO_TOKEN=kHnxgz0L2DtfjatCNAI9DVQcp9rxyXWGK 11 | - COVERALLS_GIT_BRANCH=main 12 | addons: 13 | apt: 14 | packages: 15 | - make 16 | before_install: 17 | - echo -e "machine github.com\n login $GITHUB_TOKEN" > ~/.netrc 18 | - git lfs pull 19 | branches: 20 | only: 21 | - main 22 | git: 23 | lfs_skip_smudge: true 24 | script: make build 25 | cache: 26 | - npm 27 | - packages 28 | dist: xenial 29 | os: 30 | - linux 31 | jobs: 32 | fast_finish: true 33 | notifications: 34 | webhooks: https://coveralls.io/webhook?repo_token=kHnxgz0L2DtfjatCNAI9DVQcp9rxyXWGK 35 | email: restuwahyu13@gmail.com 36 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | NPM := npm 2 | NPM_FLAGS := run 3 | DOCKER := docker 4 | 5 | ######################### 6 | ## BUILD WITH DOCKER 7 | ######################### 8 | 9 | dkb: 10 | 11 | ifdef tag 12 | ${DOCKER} build -t ${tag} . 13 | endif 14 | 15 | ######################### 16 | ## BUILD APPLICATION PROD 17 | ######################### 18 | 19 | prod: 20 | ${NPM} ${NPM_FLAGS} build 21 | 22 | ######################### 23 | ## FORMATTER 24 | ######################### 25 | 26 | lfx: 27 | ${NPM} ${NPM_FLAGS} lint:fix 28 | 29 | ######################### 30 | ## TTD TEST APPLICATION 31 | ######################### 32 | 33 | test: 34 | ${NPM} test 35 | 36 | testw: 37 | ${NPM} ${NPM_FLAGS} test:watch 38 | 39 | testc: 40 | ${NPM} ${NPM_FLAGS} test:coverage 41 | 42 | ######################### 43 | ## NPM INSTALL AND FIX 44 | ######################### 45 | 46 | install: 47 | ${NPM} install && ${NPM} audit fix 48 | 49 | ######################### 50 | ## BUILD AUTOMATION 51 | ######################### 52 | 53 | build: 54 | ${NPM} ${NPM_FLAGS} build -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "parserOptions": { 3 | "ecmaVersion": 2018, 4 | "sourceType": "module" 5 | }, 6 | "parser": "@typescript-eslint/parser", 7 | "extends": [ 8 | "plugin:@typescript-eslint/recommended", 9 | "plugin:prettier/recommended", 10 | "plugin:jest/recommended", 11 | "standard" 12 | ], 13 | "rules": { 14 | "prettier/prettier": 0, 15 | "no-tabs": 0, 16 | "indent": 0, 17 | "space-before-function-paren": 0, 18 | "@typescript-eslint/no-explicit-any": 0, 19 | "@typescript-eslint/no-inferrable-types": 0, 20 | "no-prototype-builtins": 0, 21 | "quote-props": 0, 22 | "no-async-promise-executor": 0, 23 | "prefer-const": 0, 24 | "camelcase": 0, 25 | "@typescript-eslint/no-namespace": 0, 26 | "jest/no-done-callback": 0, 27 | "eqeqeq": 1, 28 | "@typescript-eslint/no-this-alias": 1, 29 | "jest/valid-expect-in-promise": 1, 30 | "jest/no-conditional-expect": 1, 31 | "no-unneeded-ternary": 0, 32 | "no-multiple-empty-lines": 0 33 | }, 34 | "env": { 35 | "node": true, 36 | "jest/globals": true 37 | }, 38 | "settings": { 39 | "jest": { 40 | "version": 26 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2021 Restu Wahyu Saputra 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files 6 | (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, 7 | merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 11 | 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 13 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 14 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 15 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 | -------------------------------------------------------------------------------- /src/utils/validator.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * node-disk-storage 3 | * @author Copyright(c) 2021 by Restu wahyu saputra 4 | * MIT Licensed 5 | */ 6 | 7 | import { assert } from 'is-any-type' 8 | import reqSize from 'human-size' 9 | import { next } from './next' 10 | import { NodeDiskStorageError } from './error' 11 | import { matchProperty } from './matchProperty' 12 | 13 | interface NodeDiskStorageOptions { 14 | minSize: number 15 | maxSize: number 16 | } 17 | 18 | export const validatorKeyVal = (...data: Record[]): any => { 19 | const res = data.map((v) => { 20 | if ( 21 | assert.isFunction(v.key) || 22 | assert.isFunction(v.value) || 23 | assert.isPromise(v.key) || 24 | assert.isPromise(v.value) || 25 | assert.isNull(v.key) || 26 | assert.isNull(v.value) || 27 | assert.isUndefined(v.key) || 28 | assert.isUndefined(v.value) 29 | ) { 30 | return Promise.reject(new NodeDiskStorageError('key or value format not supported')) 31 | } else { 32 | return true 33 | } 34 | }) 35 | return res.includes(true) ? next() : res 36 | } 37 | 38 | export const validatorKey = (...keys: string[]): any => { 39 | const res = keys.map((v: any) => { 40 | if (assert.isFunction(v) || assert.isPromise(v) || assert.isNull(v) || assert.isUndefined(v)) { 41 | return Promise.reject(new NodeDiskStorageError('key format not supported')) 42 | } else { 43 | return true 44 | } 45 | }) 46 | return res.includes(true) ? next() : res 47 | } 48 | 49 | export const sizeValidator = (options: NodeDiskStorageOptions, value: string): boolean | Promise => { 50 | let toJSON: string = JSON.stringify({ data: value }) 51 | 52 | const bodySize: string = reqSize(toJSON.length) 53 | const sizeMatch: string[] = [] 54 | let MB: string = '' 55 | for (let i = options.minSize + 1; i <= options.maxSize; i++) { 56 | MB = i + 'MB' 57 | sizeMatch.push(MB) 58 | } 59 | if (sizeMatch.length < 1) { 60 | return Promise.reject(new NodeDiskStorageError('maximal size under 25 MB')) 61 | } else { 62 | const isCheckSize = sizeMatch.includes(bodySize) 63 | if (!isCheckSize) { 64 | return next() 65 | } else { 66 | return Promise.reject(new NodeDiskStorageError('maximal size under 25 MB')) 67 | } 68 | } 69 | } 70 | 71 | export const propertyValidator = (options: Record): any => { 72 | if (assert.isBoolean(matchProperty(options) as boolean)) return true 73 | else return Promise.reject(new NodeDiskStorageError('Options property not valid')) 74 | } 75 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ main ] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ main ] 20 | schedule: 21 | - cron: '23 2 * * 4' 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | runs-on: ubuntu-latest 27 | permissions: 28 | actions: read 29 | contents: read 30 | security-events: write 31 | 32 | strategy: 33 | fail-fast: false 34 | matrix: 35 | language: [ 'javascript' ] 36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] 37 | # Learn more about CodeQL language support at https://git.io/codeql-language-support 38 | 39 | steps: 40 | - name: Checkout repository 41 | uses: actions/checkout@v2 42 | 43 | # Initializes the CodeQL tools for scanning. 44 | - name: Initialize CodeQL 45 | uses: github/codeql-action/init@v1 46 | with: 47 | languages: ${{ matrix.language }} 48 | # If you wish to specify custom queries, you can do so here or in a config file. 49 | # By default, queries listed here will override any specified in a config file. 50 | # Prefix the list here with "+" to use these queries and those in the config file. 51 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 52 | 53 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 54 | # If this step fails, then you should remove it and run the build manually (see below) 55 | - name: Autobuild 56 | uses: github/codeql-action/autobuild@v1 57 | 58 | # ℹ️ Command-line programs to run using the OS shell. 59 | # 📚 https://git.io/JvXDl 60 | 61 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 62 | # and modify them (or add more) to build your code if your project 63 | # uses a compiled language 64 | 65 | #- run: | 66 | # make bootstrap 67 | # make release 68 | 69 | - name: Perform CodeQL Analysis 70 | uses: github/codeql-action/analyze@v1 71 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-disk-storage", 3 | "version": "0.0.6", 4 | "description": "fast and secure local storage persistent data for node js", 5 | "main": "./dist/index.js", 6 | "files": [ 7 | "/dist/**" 8 | ], 9 | "scripts": { 10 | "clean": "rimraf dist", 11 | "compiler": "npm run clean && tsc --pretty", 12 | "build": "npm run compiler", 13 | "test": "jest", 14 | "test:coverage": "jest --coverage", 15 | "test:watch": "jest --watchAll", 16 | "test:coveralls": "npm run build && jest --coverage && coveralls < coverage/lcov.info", 17 | "lint": "eslint src/**/*.ts --fix", 18 | "format": "prettier src/**/*.ts --write", 19 | "lint:fix": "npm run format && npm run lint" 20 | }, 21 | "author": { 22 | "name": "Restu Wahyu Saputra", 23 | "email": "restuwahyu13@gmail.com", 24 | "url": "https://github.com/restuwahyu13" 25 | }, 26 | "repository": { 27 | "url": "https://github.com/restuwahyu13/node-disk-storage" 28 | }, 29 | "homepage": "https://github.com/restuwahyu13/node-disk-storage#readme", 30 | "bugs": { 31 | "url": "https://github.com/restuwahyu13/node-disk-storage/issues" 32 | }, 33 | "license": "MIT", 34 | "engines": { 35 | "node": ">=12", 36 | "npm": ">=6" 37 | }, 38 | "keywords": [ 39 | "nds", 40 | "node-disk-storage", 41 | "nodejs", 42 | "local", 43 | "localstorage", 44 | "session", 45 | "local-storage", 46 | "data-store", 47 | "persistent-data", 48 | "cache-storage", 49 | "persistent", 50 | "persistent-storage", 51 | "cache-storage", 52 | "persist", 53 | "keyvalue", 54 | "keyvaluestore", 55 | "store", 56 | "session-storage", 57 | "disk-storage", 58 | "node", 59 | "node-storage", 60 | "node-cache" 61 | ], 62 | "dependencies": { 63 | "human-size": "^1.1.0", 64 | "is-any-type": "^0.0.4", 65 | "nds-core": "^2.0.9" 66 | }, 67 | "devDependencies": { 68 | "@types/jest": "^27.5.2", 69 | "@types/node": "^16.0.0", 70 | "@typescript-eslint/eslint-plugin": "^4.12.0", 71 | "@typescript-eslint/parser": "^4.12.0", 72 | "coveralls": "^3.1.0", 73 | "eslint": "^7.17.0", 74 | "eslint-config-prettier": "^8.0.0", 75 | "eslint-config-standard": "^16.0.2", 76 | "eslint-plugin-import": "^2.22.1", 77 | "eslint-plugin-jest": "^26.5.3", 78 | "eslint-plugin-node": "^11.1.0", 79 | "eslint-plugin-prettier": "^4.0.0", 80 | "eslint-plugin-promise": "^5.1.0", 81 | "husky": "^7.0.2", 82 | "jest": "^26.6.3", 83 | "prettier": "^2.2.1", 84 | "rimraf": "^3.0.2", 85 | "ts-jest": "^26.4.4", 86 | "ts-node": "^10.2.0", 87 | "typescript": "^4.1.3" 88 | }, 89 | "husky": { 90 | "hooks": { 91 | "pre-commit": "npm run lint:fix" 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/utils/storage.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * node-disk-storage 3 | * @author Copyright(c) 2021 by Restu wahyu saputra 4 | * MIT Licensed 5 | */ 6 | 7 | import { assert } from 'is-any-type' 8 | import { NDSCore } from 'nds-core' 9 | import { propertyValidator } from './validator' 10 | 11 | let storage: InstanceType = new NDSCore() 12 | 13 | export const setItem = async (items: Record, options: Record): Promise => { 14 | if (assert.isBoolean(propertyValidator(options))) { 15 | if (assert.isArray(items as any)) { 16 | const matchItem: boolean = await storage.match() 17 | if (matchItem === false) { 18 | return Promise.resolve(await storage.set(items)) 19 | } else { 20 | return Promise.resolve(await storage.set(items)) 21 | } 22 | } else { 23 | return Promise.resolve(false) 24 | } 25 | } 26 | } 27 | 28 | export const getItem = async (key: string, options: Record): Promise => { 29 | if (assert.isBoolean(propertyValidator(options))) { 30 | const getItem: any = await storage.get(key) 31 | if (!assert.isFunction(getItem) || !assert.isPromise(getItem) || !assert.isNull(getItem) || !assert.isUndefined(getItem)) { 32 | return Promise.resolve(getItem) 33 | } else { 34 | return Promise.resolve(undefined) 35 | } 36 | } 37 | } 38 | 39 | export const removeItem = async (key: string, options: Record): Promise => { 40 | if (assert.isBoolean(propertyValidator(options))) { 41 | const removeItem: boolean = await storage.remove(key) 42 | if (removeItem) { 43 | return Promise.resolve(removeItem) 44 | } else { 45 | return Promise.resolve(false) 46 | } 47 | } 48 | } 49 | 50 | export const clearItem = async (options: Record): Promise => { 51 | if (assert.isBoolean(propertyValidator(options))) { 52 | const clearItem: boolean = await storage.clear() 53 | if (clearItem) { 54 | return Promise.resolve(clearItem) 55 | } else { 56 | return Promise.resolve(false) 57 | } 58 | } 59 | } 60 | 61 | export const allKeysItem = async (options: Record): Promise => { 62 | if (assert.isBoolean(propertyValidator(options))) { 63 | const allKeysItem: string[] = await storage.allKeys() 64 | if (allKeysItem.length > 0) { 65 | return Promise.resolve(allKeysItem) 66 | } else { 67 | return Promise.resolve([]) 68 | } 69 | } 70 | } 71 | 72 | export const keysItem = async (key: string, options: Record): Promise => { 73 | if (assert.isBoolean(propertyValidator(options))) { 74 | const keyItem: any = await storage.keys(key) 75 | if (!assert.isFunction(keyItem) || !assert.isPromise(keyItem) || !assert.isNull(keyItem) || !assert.isUndefined(keyItem)) { 76 | return Promise.resolve(keyItem) 77 | } else { 78 | return Promise.resolve(undefined) 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /__test__/index.test.ts: -------------------------------------------------------------------------------- 1 | import { NodeDiskStorage } from '../dist' 2 | 3 | describe('Node Disk Storage Group Testing', function () { 4 | let nds 5 | 6 | beforeAll(() => { 7 | nds = new NodeDiskStorage() 8 | }) 9 | 10 | afterAll(async () => { 11 | await nds.clear() 12 | }) 13 | 14 | it('Should be nds cleanup is failed', async (): Promise => { 15 | expect(nds.clear).toBeDefined() 16 | expect(await nds.clear()).toBeFalsy() 17 | }) 18 | 19 | it('Should be nds get is failed', async (): Promise => { 20 | expect(nds.get).toBeDefined() 21 | expect(await nds.get('string')).toBeFalsy() 22 | expect(await nds.get('number')).toBeFalsy() 23 | expect(await nds.get('boolean')).toBeFalsy() 24 | expect(await nds.get('array')).toBeFalsy() 25 | expect(await nds.get('object')).toBeFalsy() 26 | }) 27 | 28 | it('Should be nds key is failed', async (): Promise => { 29 | expect(nds.key).toBeDefined() 30 | expect(await nds.key('string')).toBeFalsy() 31 | expect(await nds.key('number')).toBeFalsy() 32 | expect(await nds.key('boolean')).toBeFalsy() 33 | expect(await nds.key('array')).toBeFalsy() 34 | expect(await nds.key('object')).toBeFalsy() 35 | }) 36 | 37 | it('Should be nds all keys is failed', async (): Promise => { 38 | expect(nds.keys).toBeDefined() 39 | expect(await nds.keys()).toBeInstanceOf(Array) 40 | expect((await nds.keys()).length).toBe(0) 41 | }) 42 | 43 | it('Should be nds remove is failed', async (): Promise => { 44 | expect(nds.remove).toBeDefined() 45 | expect(await nds.remove('string')).toBeFalsy() 46 | expect(await nds.remove('number')).toBeFalsy() 47 | expect(await nds.remove('boolean')).toBeFalsy() 48 | expect(await nds.remove('array')).toBeFalsy() 49 | expect(await nds.remove('object')).toBeFalsy() 50 | }) 51 | 52 | it('Should be nds set is success', async (): Promise => { 53 | expect(nds.set).toBeDefined() 54 | expect(await nds.set('string', 'john doe')).toBeTruthy() 55 | expect(await nds.set('number', 23)).toBeTruthy() 56 | expect(await nds.set('boolean', true)).toBeTruthy() 57 | expect(await nds.set('array', [1,2,3,4,5])).toBeTruthy() 58 | expect(await nds.set('object', {name: "john doe"})).toBeTruthy() 59 | }) 60 | 61 | it('Should be nds get is success', async (): Promise => { 62 | expect(nds.get).toBeDefined() 63 | expect(await nds.get('string')).toEqual('john doe') 64 | expect(await nds.get('number')).toEqual(23) 65 | expect(await nds.get('boolean')).toEqual(true) 66 | expect(await nds.get('array')).toEqual([1,2,3,4,5]) 67 | expect(await nds.get('object')).toEqual({name: "john doe"}) 68 | }) 69 | 70 | it('Should be nds key is success', async (): Promise => { 71 | expect(nds.get).toBeDefined() 72 | expect(await nds.key('string')).toEqual('string') 73 | expect(await nds.key('number')).toEqual('number') 74 | expect(await nds.key('boolean')).toEqual('boolean') 75 | expect(await nds.key('array')).toEqual('array') 76 | expect(await nds.key('object')).toEqual('object') 77 | }) 78 | 79 | it('Should be nds all keys is success', async (): Promise => { 80 | expect(nds.keys).toBeDefined() 81 | expect(await nds.keys()).toBeInstanceOf(Array) 82 | expect((await nds.keys()).length).toBe(5) 83 | }) 84 | 85 | it('Should be nds remove is success', async (): Promise => { 86 | expect(nds.remove).toBeDefined() 87 | expect(await nds.remove('string')).toBeTruthy() 88 | expect(await nds.remove('number')).toBeTruthy() 89 | expect(await nds.remove('boolean')).toBeTruthy() 90 | expect(await nds.remove('array')).toBeTruthy() 91 | expect(await nds.remove('object')).toBeTruthy() 92 | }) 93 | }) 94 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 26 | * Trolling, insulting/derogatory comments, and personal or political attacks 27 | * Public or private harassment 28 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 29 | * Other conduct which could reasonably be considered inappropriate in a professional setting 30 | 31 | ## Our Responsibilities 32 | 33 | Project maintainers are responsible for clarifying the standards of acceptable 34 | behavior and are expected to take appropriate and fair corrective action in 35 | response to any instances of unacceptable behavior. 36 | 37 | Project maintainers have the right and responsibility to remove, edit, or 38 | reject comments, commits, code, wiki edits, issues, and other contributions 39 | that are not aligned to this Code of Conduct, or to ban temporarily or 40 | permanently any contributor for other behaviors that they deem inappropriate, 41 | threatening, offensive, or harmful. 42 | 43 | ## Scope 44 | 45 | This Code of Conduct applies both within project spaces and in public spaces 46 | when an individual is representing the project or its community. Examples of 47 | representing a project or community include using an official project e-mail 48 | address, posting via an official social media account, or acting as an appointed 49 | representative at an online or offline event. Representation of a project may be 50 | further defined and clarified by project maintainers. 51 | 52 | ## Enforcement 53 | 54 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 55 | reported by contacting to my email at restuwahyu13@gmail.com.com. All 56 | complaints will be reviewed and investigated and will result in a response that 57 | is deemed necessary and appropriate to the circumstances. The project team is 58 | obligated to maintain confidentiality with regard to the reporter of an incident. 59 | Further details of specific enforcement policies may be posted separately. 60 | 61 | Project maintainers who do not follow or enforce the Code of Conduct in good 62 | faith may face temporary or permanent repercussions as determined by other 63 | members of the project's leadership. 64 | 65 | ## Attribution 66 | 67 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 68 | available at 69 | 70 | homepage: 71 | 72 | For answers to common questions about this code of conduct, see 73 | 74 | -------------------------------------------------------------------------------- /src/lib/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * node-disk-storage 3 | * @author Copyright(c) 2021 by Restu wahyu saputra 4 | * MIT Licensed 5 | */ 6 | 7 | import { assert } from 'is-any-type' 8 | import * as store from '../utils/storage' 9 | import { validatorKey, sizeValidator, validatorKeyVal } from '../utils/validator' 10 | 11 | interface NodeDiskStorageOptions { 12 | readonly minSize?: number 13 | readonly maxSize?: number 14 | } 15 | 16 | interface NodeDiskStorage { 17 | set(key: string, value: any): Promise 18 | get(key: string): Promise 19 | remove(key: string): Promise 20 | key(key: string): Promise 21 | clear(): Promise 22 | keys(): Promise 23 | } 24 | 25 | export class NDS implements NodeDiskStorage { 26 | protected minSize: number 27 | protected maxSize: number 28 | protected items: Record[] = [] 29 | protected options: Record 30 | 31 | constructor(options: Partial = {}) { 32 | this.options = options 33 | this.minSize = (options.minSize as number) || 1 34 | this.maxSize = (options.maxSize as number) || 26 35 | } 36 | 37 | /** 38 | * set data using key and value, into disk 39 | * 40 | * @param { String } input - required 41 | * @param { any } value - required 42 | * @return Promise 43 | */ 44 | 45 | async set(key: string, value: any): Promise { 46 | if (assert.isBoolean(validatorKeyVal({ key, value }))) { 47 | const options: any = { 48 | minSize: this.minSize, 49 | maxSize: this.maxSize 50 | } 51 | 52 | if (assert.isBoolean(sizeValidator(options, value) as boolean)) { 53 | this.items.push({ key, value }) 54 | return Promise.resolve(await store.setItem(this.items, this.options)) 55 | } 56 | } 57 | } 58 | 59 | /** 60 | * get specific data using key, after saving data into disk 61 | * 62 | * @param { String } key - required 63 | * @return Promise 64 | */ 65 | 66 | async get(key: string): Promise { 67 | if (assert.isBoolean(validatorKey(key))) { 68 | return Promise.resolve(await store.getItem(key, this.options)) 69 | } 70 | } 71 | 72 | /** 73 | * remove specific data already exist using key, after saving data into disk 74 | * 75 | * @param { String } key - required 76 | * @return Promise 77 | */ 78 | 79 | async remove(key: string): Promise { 80 | if (assert.isBoolean(validatorKey(key))) { 81 | return Promise.resolve(await store.removeItem(key, this.options)) 82 | } 83 | } 84 | 85 | /** 86 | * get specific keys exist, after saving data into disk 87 | * @param { String } key - required 88 | * @return Promise 89 | */ 90 | 91 | async key(key: string): Promise { 92 | if (assert.isBoolean(validatorKey(key))) { 93 | return Promise.resolve(await store.keysItem(key, this.options)) 94 | } 95 | } 96 | 97 | /** 98 | * clear all keys exist, after saving data into disk 99 | * 100 | * @return Promise 101 | */ 102 | 103 | async clear(): Promise { 104 | return Promise.resolve(await store.clearItem(this.options)) 105 | } 106 | 107 | /** 108 | * get all keys exist, after saving data into disk 109 | * 110 | * @return Promise 111 | */ 112 | 113 | async keys(): Promise { 114 | return Promise.resolve(await store.allKeysItem(this.options)) 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /README_v2.md: -------------------------------------------------------------------------------- 1 | # Node Disk Storage (NDS) 2 | 3 | [![Build Status](https://app.travis-ci.com/restuwahyu13/node-disk-storage.svg?token=TJCjdtb3tZAkAUnGPRjB&branch=main)](https://app.travis-ci.com/restuwahyu13/node-disk-storage) [![Coverage Status](https://coveralls.io/repos/github/restuwahyu13/node-disk-storage/badge.svg?branch=main)](https://coveralls.io/github/restuwahyu13/node-disk-storage?branch=main) [![CodeFactor](https://www.codefactor.io/repository/github/restuwahyu13/node-disk-storage/badge)](https://www.codefactor.io/repository/github/restuwahyu13/node-disk-storage) [![codebeat badge](https://codebeat.co/badges/5611b53e-e00a-40c1-bab2-b9a8f5592b33)](https://codebeat.co/projects/github-com-restuwahyu13-node-disk-storage-main) [![Codacy Badge](https://app.codacy.com/project/badge/Grade/d74af409b71641fb96484df3dc582365)](https://www.codacy.com/gh/restuwahyu13/node-disk-storage/dashboard?utm_source=github.com&utm_medium=referral&utm_content=restuwahyu13/node-disk-storage&utm_campaign=Badge_Grade)![node-current](https://img.shields.io/node/v/node-disk-storage?style=flat-square) ![npm](https://img.shields.io/npm/dm/node-disk-storage) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://github.com/restuwahyu13/node-disk-storage/blob/main/CONTRIBUTING.md) 4 | 5 | **node-disk-storage** a simple fast and secure `local storage` for `nodejs`, you can store any data using key and value. 6 | 7 | example-nds-work 8 | 9 | - [Node Disk Storage (NDS)](#node-disk-storage-nds) 10 | - [Installation](#installation) 11 | - [API Reference](#api-reference) 12 | - [Example Usage](#example-usage) 13 | - [Testing](#testing) 14 | - [Bugs](#bugs) 15 | - [Contributing](#contributing) 16 | - [License](#license) 17 | 18 | ## Installation 19 | 20 | ```bash 21 | $ npm install node-disk-storage -S or yarn add node-disk-storage -S 22 | ``` 23 | ## API Reference 24 | 25 | - #### Node Disk Storage Options Property 26 | 27 | + **minSize** limit data size, before saving into disk, default value to **1MB** 28 | + **maxSize** limit data size, before saving into disk, default value to **25MB** 29 | + **compress** compress data using gzip, before saving into disk, default value to false 30 | 31 | - #### set(key: string, value: string): boolean | undefined 32 | set data using key and value, into disk 33 | 34 | - #### get(key: string): any | undefined 35 | get specific data using key, after saving data into disk 36 | 37 | - #### remove(key: string): boolean | undefined 38 | remove specific data already exist using key, after saving data into disk 39 | 40 | - #### clear(): boolean | undefined 41 | clear all keys exist, after saving data into disk 42 | 43 | - #### keys(): boolean | undefined 44 | get all keys exist, after saving data into disk 45 | 46 | ## Example Usage 47 | 48 | - ##### Example Usage Using CommonJs With JavaScript 49 | 50 | ```javascript 51 | const { NodeDiskStorage } = require('node-disk-storage') 52 | 53 | const nds = new NodeDiskStorage() 54 | 55 | nds.set("name", "joh doe") 56 | nds.get("name") 57 | nds.keys() 58 | nds.remove("name") 59 | nds.clear() 60 | ``` 61 | - ##### Example Usage Using CommonJs With JavaScript And Options 62 | 63 | ```javascript 64 | const { NodeDiskStorage } = require('node-disk-storage') 65 | 66 | const nds = new NodeDiskStorage({ minSize: 5, maxSize: 30, compress: true }) 67 | 68 | nds.set("name", "joh doe") 69 | nds.get("name") 70 | nds.keys() 71 | nds.remove("name") 72 | nds.clear() 73 | ``` 74 | 75 | - ##### Example Usage Using ESM With JavaScript 76 | 77 | ```javascript 78 | import { NodeDiskStorage } from 'node-disk-storage' 79 | 80 | const nds = new NodeDiskStorage() 81 | 82 | nds.set("name", "joh doe") 83 | nds.get("name") 84 | nds.keys() 85 | nds.remove("name") 86 | nds.clear() 87 | ``` 88 | 89 | - ##### Example Usage Using ESM With JavaScript And Options 90 | 91 | ```javascript 92 | import { NodeDiskStorage } from 'node-disk-storage' 93 | 94 | const nds = new NodeDiskStorage({ minSize: 5, maxSize: 30, compress: true }) 95 | 96 | nds.set("name", "joh doe") 97 | nds.get("name") 98 | nds.keys() 99 | nds.remove("name") 100 | nds.clear() 101 | ``` 102 | 103 | ## Testing 104 | 105 | - Testing Via Local 106 | 107 | ```sh 108 | npm test or make test 109 | ``` 110 | 111 | - Testing Via Local And Build 112 | 113 | ```sh 114 | make build 115 | ``` 116 | 117 | - Testing Via Docker 118 | 119 | ```sh 120 | docker build -t node-disk-storage or make dkb tag=node-disk-storage 121 | ``` 122 | 123 | ## Bugs 124 | 125 | For information on bugs related to package libraries, please visit [here](https://github.com/restuwahyu13/node-disk-storage/issues) 126 | 127 | ## Contributing 128 | 129 | Want to make **node-disk-storage** more perfect ? Let's contribute and follow the [contribution guide.](https://github.com/restuwahyu13/node-disk-storage/blob/main/CONTRIBUTING.md) 130 | 131 | ## License 132 | 133 | - [MIT License](https://github.com/restuwahyu13/node-disk-storage/blob/main/LICENSE.md) 134 | 135 |

136 | BACK TO TOP 137 |

138 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Node Disk Storage (NDS) 2 | 3 | [![Build Status](https://scrutinizer-ci.com/g/restuwahyu13/node-disk-storage/badges/build.png?b=main)](https://scrutinizer-ci.com/g/restuwahyu13/node-disk-storage/build-status/main) 4 | [![Coverage Status](https://coveralls.io/repos/github/restuwahyu13/node-disk-storage/badge.svg?branch=main)](https://coveralls.io/github/restuwahyu13/node-disk-storage?branch=main) 5 | [![CodeFactor](https://www.codefactor.io/repository/github/restuwahyu13/node-disk-storage/badge)](https://www.codefactor.io/repository/github/restuwahyu13/node-disk-storage) 6 | [![codebeat badge](https://codebeat.co/badges/5611b53e-e00a-40c1-bab2-b9a8f5592b33)](https://codebeat.co/projects/github-com-restuwahyu13-node-disk-storage-main) 7 | [![Codacy Badge](https://app.codacy.com/project/badge/Grade/d74af409b71641fb96484df3dc582365)](https://www.codacy.com/gh/restuwahyu13/node-disk-storage/dashboard?utm_source=github.com&utm_medium=referral&utm_content=restuwahyu13/node-disk-storage&utm_campaign=Badge_Grade)![node-current](https://img.shields.io/node/v/node-disk-storage?style=flat-square) 8 | ![npm](https://img.shields.io/npm/dm/node-disk-storage) 9 | [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://github.com/restuwahyu13/node-disk-storage/blob/main/CONTRIBUTING.md) 10 | 11 | **node-disk-storage** a simple fast and secure `local storage` for `nodejs`, you can store any data using key and value, and then your data will be **encrypt** 12 | to be like this `�+�)data|ZGF0YXxqb2huK2RvZV5eXiQwfDFd^^^$0|1`. 13 | 14 | example-nds-work 15 | 16 | - [Node Disk Storage (NDS)](#node-disk-storage-nds) 17 | - [Installation](#installation) 18 | - [API Reference](#api-reference) 19 | - [Example Usage](#example-usage) 20 | - [Testing](#testing) 21 | - [Bugs](#bugs) 22 | - [Contributing](#contributing) 23 | - [License](#license) 24 | 25 | ## Installation 26 | 27 | ```bash 28 | $ npm install node-disk-storage -S or yarn add node-disk-storage -S 29 | ``` 30 | 31 | ## API Reference 32 | 33 | - #### Node Disk Storage Options Property 34 | 35 | - **minSize** limit data size, before saving into disk, default value to **1MB** 36 | - **maxSize** limit data size, before saving into disk, default value to **25MB** 37 | 38 | - #### set(key: string, value: any): Promise 39 | 40 | set data using key and value, into disk 41 | 42 | - #### get(key: string): Promise 43 | 44 | get specific data using key, after saving data into disk 45 | 46 | - #### key(key: string): Promise 47 | 48 | get specific key, after saving data into disk 49 | 50 | - #### remove(key: string): Promise 51 | 52 | remove specific data already exist using key, after saving data into disk 53 | 54 | - #### clear(): Promise 55 | 56 | clear all keys exist, after saving data into disk 57 | 58 | - #### keys(): Promise 59 | get all keys exist, after saving data into disk 60 | 61 | ## Example Usage 62 | 63 | - ##### Example Usage Using CommonJs With JavaScript 64 | 65 | ```javascript 66 | const { NodeDiskStorage } = require('node-disk-storage') 67 | 68 | const nds = new NodeDiskStorage() 69 | 70 | ;(async () => { 71 | await nds.set('user', { 72 | id: 1, 73 | name: 'Leanne Graham', 74 | username: 'Bret', 75 | email: 'Sincere@april.biz', 76 | address: { 77 | street: 'Kulas Light', 78 | suite: 'Apt. 556', 79 | city: 'Gwenborough', 80 | zipcode: '92998-3874', 81 | geo: { lat: '-37.3159', lng: '81.1496' } 82 | }, 83 | phone: '1-770-736-8031 x56442', 84 | website: 'hildegard.org', 85 | company: { 86 | name: 'Romaguera-Crona', 87 | catchPhrase: 'Multi-layered client-server neural-net', 88 | bs: 'harness real-time e-markets' 89 | } 90 | }) 91 | await nds.get('user') 92 | await nds.key('user') 93 | await nds.keys() 94 | await nds.remove('user') 95 | await nds.clear() 96 | })() 97 | ``` 98 | 99 | - ##### Example Usage Using CommonJs With JavaScript And Options 100 | 101 | ```javascript 102 | const { NodeDiskStorage } = require('node-disk-storage') 103 | 104 | const nds = new NodeDiskStorage({ minSize: 5, maxSize: 30 }) 105 | 106 | ;(async () => { 107 | await nds.set("user", { 108 | id: 1, 109 | name: 'Leanne Graham', 110 | username: 'Bret', 111 | email: 'Sincere@april.biz', 112 | address: { 113 | street: 'Kulas Light', 114 | suite: 'Apt. 556', 115 | city: 'Gwenborough', 116 | zipcode: '92998-3874', 117 | geo: { lat: '-37.3159', lng: '81.1496' } 118 | }, 119 | phone: '1-770-736-8031 x56442', 120 | website: 'hildegard.org', 121 | company: { 122 | name: 'Romaguera-Crona', 123 | catchPhrase: 'Multi-layered client-server neural-net', 124 | bs: 'harness real-time e-markets' 125 | } 126 | }) 127 | await nds.get("user") 128 | await nds.key('user') 129 | await nds.keys() 130 | await nds.remove("user") 131 | await nds.clear() 132 | ``` 133 | 134 | - ##### Example Usage Using ESM With JavaScript 135 | 136 | ```javascript 137 | import { NodeDiskStorage } from 'node-disk-storage' 138 | 139 | const nds = new NodeDiskStorage() 140 | 141 | ;(async () => { 142 | await nds.set("user", { 143 | id: 1, 144 | name: 'Leanne Graham', 145 | username: 'Bret', 146 | email: 'Sincere@april.biz', 147 | address: { 148 | street: 'Kulas Light', 149 | suite: 'Apt. 556', 150 | city: 'Gwenborough', 151 | zipcode: '92998-3874', 152 | geo: { lat: '-37.3159', lng: '81.1496' } 153 | }, 154 | phone: '1-770-736-8031 x56442', 155 | website: 'hildegard.org', 156 | company: { 157 | name: 'Romaguera-Crona', 158 | catchPhrase: 'Multi-layered client-server neural-net', 159 | bs: 'harness real-time e-markets' 160 | } 161 | }) 162 | await nds.get("user") 163 | await nds.key('user') 164 | await nds.keys() 165 | await nds.remove("user") 166 | await nds.clear() 167 | ``` 168 | 169 | - ##### Example Usage Using ESM With JavaScript And Options 170 | 171 | ```javascript 172 | import { NodeDiskStorage } from 'node-disk-storage' 173 | 174 | const nds = new NodeDiskStorage({ minSize: 5, maxSize: 30 }) 175 | 176 | ;(async () => { 177 | await nds.set("user", { 178 | id: 1, 179 | name: 'Leanne Graham', 180 | username: 'Bret', 181 | email: 'Sincere@april.biz', 182 | address: { 183 | street: 'Kulas Light', 184 | suite: 'Apt. 556', 185 | city: 'Gwenborough', 186 | zipcode: '92998-3874', 187 | geo: { lat: '-37.3159', lng: '81.1496' } 188 | }, 189 | phone: '1-770-736-8031 x56442', 190 | website: 'hildegard.org', 191 | company: { 192 | name: 'Romaguera-Crona', 193 | catchPhrase: 'Multi-layered client-server neural-net', 194 | bs: 'harness real-time e-markets' 195 | } 196 | }) 197 | await nds.get("user") 198 | await nds.key('user') 199 | await nds.keys() 200 | await nds.remove("user") 201 | await nds.clear() 202 | ``` 203 | 204 | ## Testing 205 | 206 | - Testing Via Local 207 | 208 | ```sh 209 | npm test or make test 210 | ``` 211 | 212 | - Testing Via Local And Build 213 | 214 | ```sh 215 | make build 216 | ``` 217 | 218 | - Testing Via Docker 219 | 220 | ```sh 221 | docker build -t node-disk-storage or make dkb tag=node-disk-storage 222 | ``` 223 | 224 | ## Bugs 225 | 226 | For information on bugs related to package libraries, please visit [here](https://github.com/restuwahyu13/node-disk-storage/issues) 227 | 228 | ## Contributing 229 | 230 | Want to make **node-disk-storage** more perfect ? Let's contribute and follow the 231 | [contribution guide.](https://github.com/restuwahyu13/node-disk-storage/blob/main/CONTRIBUTING.md) 232 | 233 | ## License 234 | 235 | - [MIT License](https://github.com/restuwahyu13/node-disk-storage/blob/main/LICENSE.md) 236 | 237 |

238 | BACK TO TOP 239 |

240 | --------------------------------------------------------------------------------