@rainte/js 0.0.15 → 0.0.17

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.
@@ -1,4 +1,5 @@
1
1
  export * as date from '../src/date';
2
+ export * as db from '../src/db';
2
3
  export * as fast from '../src/fast';
3
4
  export * as file from '../src/file';
4
5
  export * as hash from '../src/hash';
@@ -0,0 +1,13 @@
1
+ import Dexie, { Table } from 'dexie';
2
+ export interface DexieRow {
3
+ id?: number;
4
+ key: string;
5
+ value: any;
6
+ }
7
+ export declare class SubDexie extends Dexie {
8
+ rows: Table<DexieRow>;
9
+ constructor();
10
+ }
11
+ export declare const db: SubDexie;
12
+ export declare const get: (key: string, value?: boolean) => import("dexie").PromiseExtended<any>;
13
+ export declare const set: (key: string, value: any) => Promise<void>;
@@ -1,4 +1 @@
1
- declare const _default: {
2
- SHA256: (input: unknown, toJson?: Boolean) => Promise<any>;
3
- };
4
- export default _default;
1
+ export declare const SHA256: (input: unknown, toJson?: Boolean) => Promise<any>;
package/lib/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * as date from '../src/date'
2
+ export * as db from '../src/db'
2
3
  export * as fast from '../src/fast'
3
4
  export * as file from '../src/file'
4
5
  export * as hash from '../src/hash'
package/package.json CHANGED
@@ -1,25 +1,26 @@
1
- {
2
- "name": "@rainte/js",
3
- "version": "0.0.15",
4
- "type": "module",
5
- "main": "dist/index.umd.cjs",
6
- "module": "dist/index.js",
7
- "typings": "dist/types/lib/index.d.ts",
8
- "scripts": {
9
- "dev": "vite",
10
- "build": "vite build && tsc",
11
- "release": "pnpm build && npm version patch && npm publish --access public --registry=https://registry.npmjs.org",
12
- "preview": "vite preview"
13
- },
14
- "devDependencies": {
15
- "@types/jsan": "^3.1.5",
16
- "@types/node": "^22.13.5",
17
- "typescript": "^5.7.3",
18
- "vite": "^6.1.1"
19
- },
20
- "dependencies": {
21
- "axios": "^1.7.9",
22
- "dayjs": "^1.11.13",
23
- "jsan": "^3.1.14"
24
- }
25
- }
1
+ {
2
+ "name": "@rainte/js",
3
+ "version": "0.0.17",
4
+ "type": "module",
5
+ "main": "dist/index.umd.cjs",
6
+ "module": "dist/index.js",
7
+ "typings": "dist/types/lib/index.d.ts",
8
+ "scripts": {
9
+ "dev": "vite",
10
+ "build": "vite build && tsc",
11
+ "release": "pnpm build && npm version patch && npm publish --access public --registry=https://registry.npmjs.org",
12
+ "preview": "vite preview"
13
+ },
14
+ "devDependencies": {
15
+ "@types/jsan": "^3.1.5",
16
+ "@types/node": "^22.13.5",
17
+ "typescript": "^5.7.3",
18
+ "vite": "^6.1.1"
19
+ },
20
+ "dependencies": {
21
+ "axios": "^1.7.9",
22
+ "dayjs": "^1.11.13",
23
+ "dexie": "^4.0.11",
24
+ "jsan": "^3.1.14"
25
+ }
26
+ }
@@ -0,0 +1,36 @@
1
+ import Dexie, { Table } from 'dexie'
2
+
3
+ export interface DexieRow {
4
+ id?: number
5
+ key: string
6
+ value: any
7
+ }
8
+
9
+ export class SubDexie extends Dexie {
10
+ rows!: Table<DexieRow>
11
+
12
+ constructor() {
13
+ super('db')
14
+ this.version(1).stores({
15
+ rows: '++id, key'
16
+ })
17
+ }
18
+ }
19
+
20
+ export const db = new SubDexie()
21
+
22
+ export const get = (key: string, value = true) => {
23
+ return db.rows
24
+ .where({ key })
25
+ .first()
26
+ .then((res) => (value ? res?.value : res))
27
+ }
28
+
29
+ export const set = async (key: string, value: any) => {
30
+ const ok = await get(key, false)
31
+ if (ok) {
32
+ await db.rows.where({ key }).modify({ value })
33
+ } else {
34
+ await db.rows.add({ key, value })
35
+ }
36
+ }
package/src/hash/index.ts CHANGED
@@ -6,7 +6,7 @@ if (typeof window === 'undefined') {
6
6
  crypto = require('crypto')
7
7
  }
8
8
 
9
- const SHA256 = async (input: unknown, toJson: Boolean = true) => {
9
+ export const SHA256 = async (input: unknown, toJson: Boolean = true) => {
10
10
  const text = toJson ? json.stringify(input) : input
11
11
 
12
12
  if (typeof window !== 'undefined') {
@@ -22,7 +22,3 @@ const SHA256 = async (input: unknown, toJson: Boolean = true) => {
22
22
  return hash.digest('hex')
23
23
  }
24
24
  }
25
-
26
- export default {
27
- SHA256: SHA256
28
- }