@rainte/js 0.0.12 → 0.0.13

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.
package/lib/index.ts CHANGED
@@ -2,4 +2,5 @@ export * as date from '../src/date'
2
2
  export * as fast from '../src/fast'
3
3
  export * as file from '../src/file'
4
4
  export * as http from '../src/http'
5
+ export * as json from '../src/json'
5
6
  export * as storage from '../src/storage'
package/package.json CHANGED
@@ -1,25 +1,25 @@
1
- {
2
- "name": "@rainte/js",
3
- "version": "0.0.12",
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": "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.13",
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": "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
+ }
package/src/http/axios.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import Axios from 'axios'
2
- import * as storage from '../storage'
2
+ import { local } from '../storage'
3
3
 
4
4
  export const ACCESS_TOKEN = 'access_token'
5
5
 
@@ -15,7 +15,7 @@ export const axios = Axios.create({
15
15
 
16
16
  export const tokenRequestInterceptor = () => {
17
17
  return axios.interceptors.request.use((config) => {
18
- const token = storage.session.get(ACCESS_TOKEN)
18
+ const token = local.get(ACCESS_TOKEN)
19
19
  token && (config.headers.Authorization = `Bearer ${token}`)
20
20
  return config
21
21
  })
@@ -0,0 +1,14 @@
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
+ }
@@ -1,4 +1,4 @@
1
- import jsan from 'jsan'
1
+ import * as json from '../json'
2
2
 
3
3
  const cache = (storage?: Storage) => {
4
4
  return {
@@ -10,11 +10,10 @@ const cache = (storage?: Storage) => {
10
10
  },
11
11
  get: (key: string, defaultValue: any = null) => {
12
12
  const res = storage?.getItem(key)
13
- return res ? jsan.parse(res) : defaultValue
13
+ return res ? json.parse(res) : defaultValue
14
14
  },
15
15
  set: (key: string, value: any) => {
16
- const serialize = jsan.stringify(value, undefined, undefined, true)
17
- storage?.setItem(key, serialize)
16
+ storage?.setItem(key, json.stringify(value))
18
17
  },
19
18
  del: (key: string) => {
20
19
  storage?.removeItem(key)