@rainte/js 0.0.17 → 0.0.19

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.
@@ -0,0 +1,9 @@
1
+ export * as date from '@/date';
2
+ export * as db from '@/db';
3
+ export * as fast from '@/fast';
4
+ export * as file from '@/file';
5
+ export * as hash from '@/hash';
6
+ export * as http from '@/http';
7
+ export * as json from '@/json';
8
+ export * as storage from '@/storage';
9
+ export * as url from '@/url';
@@ -9,3 +9,16 @@ export declare const FORMAT: {
9
9
  HOUR: string;
10
10
  MINUTE: string;
11
11
  };
12
+ declare const _default: {
13
+ dayjs: typeof dayjs;
14
+ FORMAT: {
15
+ DATETIME: string;
16
+ DATE: string;
17
+ TIME: string;
18
+ YEAR: string;
19
+ MONTH: string;
20
+ HOUR: string;
21
+ MINUTE: string;
22
+ };
23
+ };
24
+ export default _default;
@@ -11,3 +11,8 @@ export declare class SubDexie extends Dexie {
11
11
  export declare const db: SubDexie;
12
12
  export declare const get: (key: string, value?: boolean) => import("dexie").PromiseExtended<any>;
13
13
  export declare const set: (key: string, value: any) => Promise<void>;
14
+ declare const _default: {
15
+ get: (key: string, value?: boolean) => import("dexie").PromiseExtended<any>;
16
+ set: (key: string, value: any) => Promise<void>;
17
+ };
18
+ export default _default;
@@ -1,8 +1,11 @@
1
- export declare const find: (list: any[], value: any, label?: string) => any;
2
- export declare const url: {
3
- search: () => URLSearchParams;
4
- open: (url?: string | URL, target?: string, features?: string) => void;
5
- };
1
+ export declare const findByValue: (list: any[], value: any) => any;
6
2
  export declare const sleep: (ms: number) => Promise<unknown>;
7
3
  export declare const log: (message: any, type?: string) => void;
8
4
  export declare const fail: (message: string) => never;
5
+ declare const _default: {
6
+ findByValue: (list: any[], value: any) => any;
7
+ sleep: (ms: number) => Promise<unknown>;
8
+ log: (message: any, type?: string) => void;
9
+ fail: (message: string) => never;
10
+ };
11
+ export default _default;
@@ -1,3 +1,9 @@
1
1
  export declare const toBase64: (blob: Blob) => Promise<string>;
2
2
  export declare const toBlob: (base64: string) => Blob;
3
3
  export declare const download: (filename: string, obj: Blob | MediaSource) => void;
4
+ declare const _default: {
5
+ toBase64: (blob: Blob) => Promise<string>;
6
+ toBlob: (base64: string) => Blob;
7
+ download: (filename: string, obj: Blob | MediaSource) => void;
8
+ };
9
+ export default _default;
@@ -1 +1,5 @@
1
1
  export declare const SHA256: (input: unknown, toJson?: Boolean) => Promise<any>;
2
+ declare const _default: {
3
+ SHA256: (input: unknown, toJson?: Boolean) => Promise<any>;
4
+ };
5
+ export default _default;
@@ -4,3 +4,4 @@ export declare const axios: import("axios").AxiosInstance;
4
4
  export declare const tokenRequestInterceptor: () => number;
5
5
  export declare const responseInterceptor: (onRejected?: ((error: any) => any) | null) => number;
6
6
  export declare const retry: (error: any, refreshURL: string, refreshRequest: () => Promise<any>) => Promise<unknown>;
7
+ export default axios;
@@ -4,3 +4,10 @@ export declare const get: (url: string, params?: Record<string, any>) => Promise
4
4
  export declare const post: (url: string, data?: Record<string, any>) => Promise<import("axios").AxiosResponse<any, any>>;
5
5
  export declare const download: (config: AxiosRequestConfig) => Promise<import("axios").AxiosResponse<any, any>>;
6
6
  export declare const request: (config: AxiosRequestConfig) => Promise<import("axios").AxiosResponse<any, any>>;
7
+ declare const _default: {
8
+ get: (url: string, params?: Record<string, any>) => Promise<import("axios").AxiosResponse<any, any>>;
9
+ post: (url: string, data?: Record<string, any>) => Promise<import("axios").AxiosResponse<any, any>>;
10
+ download: (config: AxiosRequestConfig) => Promise<import("axios").AxiosResponse<any, any>>;
11
+ request: (config: AxiosRequestConfig) => Promise<import("axios").AxiosResponse<any, any>>;
12
+ };
13
+ export default _default;
@@ -1,3 +1,8 @@
1
1
  import { Options } from 'jsan';
2
2
  export declare const stringify: (value?: unknown, replacer?: (key: string, value: unknown) => unknown | Array<number | string> | null, space?: string | number, _options?: Options | boolean) => string;
3
3
  export declare const parse: (text: string, reviver?: (key: string, value: unknown) => unknown) => unknown;
4
+ declare const _default: {
5
+ stringify: (value?: unknown, replacer?: (key: string, value: unknown) => unknown | Array<number | string> | null, space?: string | number, _options?: Options | boolean) => string;
6
+ parse: (text: string, reviver?: (key: string, value: unknown) => unknown) => unknown;
7
+ };
8
+ export default _default;
@@ -1,16 +1,17 @@
1
- export declare const session: {
2
- getRaw: (key: string, defaultValue?: any) => any;
3
- setRaw: (key: string, value: string) => void;
4
- get: (key: string, defaultValue?: any) => any;
5
- set: (key: string, value: any) => void;
6
- del: (key: string) => void;
7
- clear: () => void;
8
- };
9
- export declare const local: {
10
- getRaw: (key: string, defaultValue?: any) => any;
11
- setRaw: (key: string, value: string) => void;
12
- get: (key: string, defaultValue?: any) => any;
13
- set: (key: string, value: any) => void;
14
- del: (key: string) => void;
15
- clear: () => void;
1
+ declare class Cache {
2
+ private storage;
3
+ constructor(storage: Storage);
4
+ getRaw(key: string, defaultValue?: any): any;
5
+ setRaw(key: string, value: string): void;
6
+ get(key: string, defaultValue?: any): any;
7
+ set(key: string, value: any): void;
8
+ del(key: string): void;
9
+ clear(): void;
10
+ }
11
+ export declare const local: Cache;
12
+ export declare const session: Cache;
13
+ declare const _default: {
14
+ local: Cache;
15
+ session: Cache;
16
16
  };
17
+ export default _default;
@@ -0,0 +1,9 @@
1
+ export declare const search: () => URLSearchParams;
2
+ export declare const all: () => ObjectProps;
3
+ export declare const open: (url?: string | URL, target?: string, features?: string) => void;
4
+ declare const _default: {
5
+ search: () => URLSearchParams;
6
+ all: () => ObjectProps;
7
+ open: (url?: string | URL, target?: string, features?: string) => void;
8
+ };
9
+ export default _default;
package/package.json CHANGED
@@ -1,26 +1,33 @@
1
1
  {
2
2
  "name": "@rainte/js",
3
- "version": "0.0.17",
3
+ "version": "0.0.19",
4
4
  "type": "module",
5
- "main": "dist/index.umd.cjs",
6
- "module": "dist/index.js",
7
- "typings": "dist/types/lib/index.d.ts",
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "main": "./dist/index.umd.cjs",
9
+ "module": "./dist/index.js",
10
+ "types": "./dist/types/lib/index.d.ts",
11
+ "exports": {
12
+ "types": "./dist/types/lib/index.d.ts",
13
+ "import": "./dist/index.js",
14
+ "require": "./dist/index.umd.cjs"
15
+ },
8
16
  "scripts": {
9
17
  "dev": "vite",
10
18
  "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
+ "release": "pnpm build && npm version patch && npm publish --access public --registry=https://registry.npmjs.org"
19
20
  },
20
21
  "dependencies": {
21
- "axios": "^1.7.9",
22
+ "axios": "^1.8.3",
22
23
  "dayjs": "^1.11.13",
23
24
  "dexie": "^4.0.11",
24
25
  "jsan": "^3.1.14"
26
+ },
27
+ "devDependencies": {
28
+ "@types/jsan": "^3.1.5",
29
+ "@types/node": "^22.13.10",
30
+ "typescript": "^5.8.2",
31
+ "vite": "^6.2.2"
25
32
  }
26
33
  }
package/.prettierrc.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "$schema": "https://json.schemastore.org/prettierrc",
3
- "semi": false,
4
- "tabWidth": 2,
5
- "singleQuote": true,
6
- "printWidth": 100,
7
- "trailingComma": "none"
8
- }
@@ -1,8 +0,0 @@
1
- export * as date from '../src/date';
2
- export * as db from '../src/db';
3
- export * as fast from '../src/fast';
4
- export * as file from '../src/file';
5
- export * as hash from '../src/hash';
6
- export * as http from '../src/http';
7
- export * as json from '../src/json';
8
- export * as storage from '../src/storage';
package/index.html DELETED
@@ -1,13 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <link rel="icon" type="image/svg+xml" href="/vite.svg" />
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
- <title>Rainte</title>
8
- </head>
9
- <body>
10
- <div id="app"></div>
11
- <script type="module" src="/src/main.ts"></script>
12
- </body>
13
- </html>
package/lib/index.ts DELETED
@@ -1,8 +0,0 @@
1
- export * as date from '../src/date'
2
- export * as db from '../src/db'
3
- export * as fast from '../src/fast'
4
- export * as file from '../src/file'
5
- export * as hash from '../src/hash'
6
- export * as http from '../src/http'
7
- export * as json from '../src/json'
8
- export * as storage from '../src/storage'
package/public/vite.svg DELETED
@@ -1 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
package/src/date/index.ts DELETED
@@ -1,19 +0,0 @@
1
- import dayjs from 'dayjs'
2
- import customParseFormat from 'dayjs/plugin/customParseFormat'
3
- import duration from 'dayjs/plugin/duration'
4
- import utc from 'dayjs/plugin/utc'
5
-
6
- dayjs.extend(customParseFormat)
7
- dayjs.extend(duration)
8
- dayjs.extend(utc)
9
-
10
- export { dayjs }
11
- export const FORMAT = {
12
- DATETIME: 'YYYY-MM-DD HH:mm:ss',
13
- DATE: 'YYYY-MM-DD',
14
- TIME: 'HH:mm:ss',
15
- YEAR: 'YYYY',
16
- MONTH: 'YYYY-MM',
17
- HOUR: 'YYYY-MM-DD HH',
18
- MINUTE: 'YYYY-MM-DD HH:mm'
19
- }
package/src/db/index.ts DELETED
@@ -1,36 +0,0 @@
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/fast/index.ts DELETED
@@ -1,27 +0,0 @@
1
- export const find = (list: any[], value: any, label = '') => {
2
- return (
3
- list.find((item: any) => {
4
- return item.value == (Array.isArray(value) ? value[0] : value)
5
- })?.label ?? label
6
- )
7
- }
8
-
9
- export const url = {
10
- search: () => new URLSearchParams(location.search),
11
- open: (url?: string | URL, target?: string, features?: string) => {
12
- target = target || '_blank'
13
- window.open(url, target, features)
14
- }
15
- }
16
-
17
- export const sleep = (ms: number) => {
18
- return new Promise((resolve) => setTimeout(resolve, ms))
19
- }
20
-
21
- export const log = (message: any, type?: string) => {
22
- type ? console.log(type, message) : console.log(message)
23
- }
24
-
25
- export const fail = (message: string) => {
26
- throw new Error(message)
27
- }
package/src/file/index.ts DELETED
@@ -1,25 +0,0 @@
1
- export const toBase64 = (blob: Blob) => {
2
- return new Promise((resolve, reject) => {
3
- const reader = new FileReader()
4
- reader.onload = (event) => resolve(event.target?.result)
5
- reader.onerror = (event) => reject(event.target?.error)
6
- reader.readAsDataURL(blob)
7
- }).then((res) => res as string)
8
- }
9
-
10
- export const toBlob = (base64: string) => {
11
- const character = atob(base64.split(',')[1] || base64)
12
- const bytes = new Uint8Array(character.length)
13
- for (let i = 0; i < character.length; i++) {
14
- bytes[i] = character.charCodeAt(i)
15
- }
16
- return new Blob([bytes])
17
- }
18
-
19
- export const download = (filename: string, obj: Blob | MediaSource) => {
20
- const link = document.createElement('a')
21
- link.href = URL.createObjectURL(obj)
22
- link.download = filename
23
- link.click()
24
- URL.revokeObjectURL(link.href)
25
- }
package/src/hash/index.ts DELETED
@@ -1,24 +0,0 @@
1
- import * as json from '../json'
2
-
3
- let crypto: any
4
-
5
- if (typeof window === 'undefined') {
6
- crypto = require('crypto')
7
- }
8
-
9
- export const SHA256 = async (input: unknown, toJson: Boolean = true) => {
10
- const text = toJson ? json.stringify(input) : input
11
-
12
- if (typeof window !== 'undefined') {
13
- const encoder = new TextEncoder()
14
- const data = encoder.encode(text as string)
15
- const hashBuffer = await crypto.subtle.digest('SHA-256', data)
16
- const hashArray = Array.from(new Uint8Array(hashBuffer))
17
- const hashHex = hashArray.map((byte) => byte.toString(16).padStart(2, '0')).join('')
18
- return hashHex
19
- } else {
20
- const hash = crypto.createHash('sha256')
21
- hash.update(text)
22
- return hash.digest('hex')
23
- }
24
- }
package/src/http/axios.ts DELETED
@@ -1,66 +0,0 @@
1
- import Axios from 'axios'
2
- import { local } from '../storage'
3
-
4
- export const ACCESS_TOKEN = 'access_token'
5
-
6
- export const message = (data: any, text = '请求异常.') => {
7
- return data.message || data.msg || text
8
- }
9
-
10
- export const axios = Axios.create({
11
- baseURL: '',
12
- timeout: 3000,
13
- headers: { 'Content-Type': 'application/json' }
14
- })
15
-
16
- export const tokenRequestInterceptor = () => {
17
- return axios.interceptors.request.use((config) => {
18
- const token = local.get(ACCESS_TOKEN)
19
- token && (config.headers.Authorization = `Bearer ${token}`)
20
- return config
21
- })
22
- }
23
-
24
- export const responseInterceptor = (onRejected?: ((error: any) => any) | null) => {
25
- return axios.interceptors.response.use(
26
- (response) => {
27
- const data = response.data
28
- if (response.status === 200) {
29
- return data.data
30
- }
31
-
32
- const error = new Error(message(data))
33
- return onRejected ? onRejected(error) : Promise.reject(error)
34
- },
35
- (error) => {
36
- return onRejected ? onRejected(error) : Promise.reject(error)
37
- }
38
- )
39
- }
40
-
41
- let isRefreshing = false
42
- let requests: any[] = []
43
-
44
- export const retry = (error: any, refreshURL: string, refreshRequest: () => Promise<any>) => {
45
- const { response } = error
46
-
47
- if (response.config.url == refreshURL) {
48
- isRefreshing = false
49
- requests = []
50
- return Promise.reject(error)
51
- } else {
52
- if (!isRefreshing) {
53
- isRefreshing = true
54
- refreshRequest()
55
- .then(() => requests.forEach((cb) => cb()))
56
- .finally(() => {
57
- isRefreshing = false
58
- requests = []
59
- })
60
- }
61
-
62
- return new Promise((resolve) => {
63
- requests.push(() => resolve(axios(response.config)))
64
- })
65
- }
66
- }
package/src/http/index.ts DELETED
@@ -1,21 +0,0 @@
1
- import { axios } from './axios'
2
- import { AxiosRequestConfig } from 'axios'
3
-
4
- export * from './axios'
5
-
6
- export const get = (url: string, params?: Record<string, any>) => {
7
- return request({ url, method: 'GET', params })
8
- }
9
-
10
- export const post = (url: string, data?: Record<string, any>) => {
11
- return request({ url, method: 'POST', data })
12
- }
13
-
14
- export const download = (config: AxiosRequestConfig) => {
15
- config.responseType = config.responseType || 'blob'
16
- return request(config)
17
- }
18
-
19
- export const request = (config: AxiosRequestConfig) => {
20
- return axios.request(config)
21
- }
package/src/json/index.ts DELETED
@@ -1,14 +0,0 @@
1
- import jsan, { Options } from 'jsan'
2
-
3
- export const stringify = (
4
- value: unknown = null,
5
- replacer?: (key: string, value: unknown) => unknown | Array<number | string> | null,
6
- space?: string | number,
7
- _options: Options | boolean = true
8
- ) => {
9
- return jsan.stringify(value, replacer, space, _options)
10
- }
11
-
12
- export const parse = (text: string, reviver?: (key: string, value: unknown) => unknown) => {
13
- return jsan.parse(text, reviver)
14
- }
package/src/main.ts DELETED
@@ -1,21 +0,0 @@
1
- import * as date from './date'
2
- import * as fast from './fast'
3
-
4
- const make = (content: string, tag: keyof HTMLElementTagNameMap = 'li') => {
5
- const ele = document.createElement(tag)
6
- ele.textContent = content
7
- return ele
8
- }
9
-
10
- const list = [
11
- { label: 'label1', value: 'value1' },
12
- { label: 'label2', value: 'value2' },
13
- { label: 'label3', value: 'value3' }
14
- ]
15
-
16
- document
17
- .querySelector<HTMLDivElement>('#app')
18
- ?.appendChild(document.createElement('ul'))
19
- ?.appendChild(make(date.dayjs().format(date.FORMAT.DATETIME)))
20
- ?.appendChild(make(fast.find(list, 'value3', '无知')))
21
- ?.appendChild(make(fast.find(list, 'value0', '无知')))
@@ -1,28 +0,0 @@
1
- import * as json from '../json'
2
-
3
- const cache = (storage?: Storage) => {
4
- return {
5
- getRaw: (key: string, defaultValue: any = null) => {
6
- return storage?.getItem(key) || defaultValue
7
- },
8
- setRaw: (key: string, value: string) => {
9
- storage?.setItem(key, value)
10
- },
11
- get: (key: string, defaultValue: any = null) => {
12
- const res = storage?.getItem(key)
13
- return res ? json.parse(res) : defaultValue
14
- },
15
- set: (key: string, value: any) => {
16
- storage?.setItem(key, json.stringify(value))
17
- },
18
- del: (key: string) => {
19
- storage?.removeItem(key)
20
- },
21
- clear: () => {
22
- storage?.clear()
23
- }
24
- }
25
- }
26
-
27
- export const session = cache(sessionStorage)
28
- export const local = cache(localStorage)
package/src/vite-env.d.ts DELETED
@@ -1 +0,0 @@
1
- /// <reference types="vite/client" />
package/tsconfig.json DELETED
@@ -1,26 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "useDefineForClassFields": true,
5
- "module": "ESNext",
6
- "lib": ["ES2020", "DOM", "DOM.Iterable"],
7
- "skipLibCheck": true,
8
- "declaration": true, // 自动生成声明文件.
9
- "declarationDir": "dist/types", // 声明文件输出的目录.
10
- "emitDeclarationOnly": true, // 只输出声明文件,不转译ts文件.
11
-
12
- /* Bundler mode */
13
- "moduleResolution": "bundler",
14
- "allowImportingTsExtensions": true,
15
- "isolatedModules": true,
16
- "moduleDetection": "force",
17
- // "noEmit": true,
18
-
19
- /* Linting */
20
- "strict": true,
21
- "noUnusedLocals": true,
22
- "noUnusedParameters": true,
23
- "noFallthroughCasesInSwitch": true
24
- },
25
- "include": ["src", "lib", "vite.config.ts"]
26
- }
package/vite.config.ts DELETED
@@ -1,12 +0,0 @@
1
- import { defineConfig } from 'vite'
2
- import { resolve } from 'path'
3
-
4
- export default defineConfig({
5
- build: {
6
- lib: {
7
- entry: resolve(__dirname, 'lib/index.ts'),
8
- name: '@rainte/js',
9
- fileName: 'index'
10
- }
11
- }
12
- })