Skip to content

Commit

Permalink
feat(pet-shop): smart
Browse files Browse the repository at this point in the history
  • Loading branch information
Airkro committed Nov 24, 2023
1 parent 7cf91a1 commit 160dea3
Show file tree
Hide file tree
Showing 7 changed files with 551 additions and 434 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/bring-it.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ jobs:
- windows-latest
- ubuntu-latest
node:
- 18.0.0
- 16.15.0
- current
- lts/*
- lts/-1
exclude:
- os: ubuntu-latest
node: 16.15.0
node: lts/*
runs-on: ${{ matrix.os }}
steps:
- name: Run
Expand Down
918 changes: 512 additions & 406 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@
"packages/*"
],
"devDependencies": {
"@bring-it/npm": "^0.2.10",
"@nice-move/cli": "^0.10.11",
"@nice-move/eslint-config-base": "^0.9.18",
"@nice-move/prettier-config": "^0.9.3",
"@bring-it/npm": "^0.3.9",
"@nice-move/cli": "^0.10.14",
"@nice-move/eslint-config-base": "^0.9.24",
"@nice-move/prettier-config": "^0.9.8",
"ava": "^5.3.1",
"eslint": "^8.47.0",
"eslint": "^8.54.0",
"eslint-plugin-ava": "^14.0.0",
"garou": "^0.6.12",
"garou": "^0.6.19",
"node-storage-shim": "^2.0.1",
"prettier": "^3.0.2"
"prettier": "^3.1.0"
},
"engines": {
"node": ">=16.13.0"
Expand Down
19 changes: 15 additions & 4 deletions packages/pet-shop/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ export function PetShop({ storage, namespace, json = false }) {
if (value === undefined || value === null) {
this.remove(key);
} else {
if (typeof value !== 'string') {
throw new TypeError('The Value should be a string');
}

storage.setItem(`${namespace}.${key}`, value);
}
},
Expand Down Expand Up @@ -120,3 +116,18 @@ export function PetShop({ storage, namespace, json = false }) {
},
);
}

export function smart(store, key) {
return {
get() {
return store.get(key);
},
set(value) {
if (value !== null && value !== undefined) {
store.set(key, value);
} else {
store.remove(key);
}
},
};
}
8 changes: 6 additions & 2 deletions packages/pet-shop/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pet-shop",
"version": "0.1.2",
"version": "0.1.4",
"description": "A simple wrapper of Web Storage API",
"license": "MIT",
"author": {
Expand Down Expand Up @@ -28,5 +28,9 @@
"url": "https://github.com/airkro/frontend-toolkit/issues"
},
"main": "index.js",
"type": "module"
"type": "module",
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
}
}
8 changes: 6 additions & 2 deletions packages/slash-to-regexp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@
"bugs": {
"url": "https://github.com/airkro/frontend-toolkit/issues"
},
"main": "index.cjs",
"types": "index.d.ts",
"main": "index.cjs",
"engines": {
"node": ">=8.10"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
}
}
}
11 changes: 1 addition & 10 deletions tests/pet-shop.test.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @ts-nocheck
import test from 'ava';
import StorageShim from 'node-storage-shim';

import { PetShop } from 'pet-shop';

const storage = new StorageShim();
Expand All @@ -23,16 +24,6 @@ test('Base Usage', (t) => {
},
);

t.throws(
() => {
store.set('xyz', 123);
},
{
instanceOf: TypeError,
message: 'The Value should be a string',
},
);

t.snapshot(store.get('abc'));

store.set('efg', '456');
Expand Down

0 comments on commit 160dea3

Please sign in to comment.