Skip to content

Commit

Permalink
release v5.16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
saqqdy committed Jan 21, 2024
1 parent 9d11b62 commit 9204069
Show file tree
Hide file tree
Showing 10 changed files with 1,407 additions and 998 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change logs

## 2024.01.21 v5.16.0

1. new `safeParse` `safeStringify` function
2. upgrade all packages

## 2023.11.13 v5.15.2

1. move `awaitTo` to `await-to-done` function, see: [await-to-done](https://github.com/saqqdy/await-to-done)
Expand Down
2 changes: 2 additions & 0 deletions README-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ const functionList = {
compareVersion, // 版本号大小对比
parseUrlParam, // 解析url参数(key1=value1&key2=value2)
spliceUrlParam, // 拼接URL参数(仅支持单层)
safeParse, // 安全解析JSON字符串
safeStringify, // 安全转换JSON对象为字符串
getDirParam, // 获取目录形式URL参数
getQueryParam, // 获取query参数(#后面)
getQueryParams, // 获取所有query参数(#后面)
Expand Down
84 changes: 81 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ Collection of common JavaScript / TypeScript utilities
- [compareVersion](#compareversion) - Version number size comparison, tag version: `rc` > `beta` > `alpha` > `other`
- [parseUrlParam](#parseurlparam) - parse url params. (If covert is passed true: Scientific notation, binary, octal and hexadecimal types of data are not converted, like: 0b111, 0o13, 0xFF, 1e3, -1e-2)
- [spliceUrlParam](#spliceurlparam) - Splice URL parameters (single layer only)
- [safeParse](#safeparse) - Secure parsing of JSON strings
- [safeStringify](#safestringify) - Secure stringify of JSON Object
- [getDirParam](#getdirparam) - Get the URL parameter in the form of a directory
- [getQueryParam](#getqueryparam) - Get a single query parameter (behind "#")
- [getQueryParams](#getqueryparams) - Get all query parameters (behind "#"). (If covert is passed true: Scientific notation, binary, octal and hexadecimal types of data are not converted, like: 0b111, 0o13, 0xFF, 1e3, -1e-2)
Expand Down Expand Up @@ -1525,9 +1527,14 @@ Splice URL parameters (single layer only)
- Example:

```ts
spliceUrlParam({ key1: '100', key2: 'true', key3: 'null', key4: 'undefined', key4: '测试' }) // ?key1=100&key2=true&key3=null&key4=undefined&key5=%E6%B5%8B%E8%AF%95
spliceUrlParam({ key1: '100', key2: 'true', key3: 'null', key4: 'undefined' }, true) // ?key1=100&key2=true&key3=&key4=
spliceUrlParam({ key1: '100', key2: 'true', key3: 'null', key4: 'undefined' }, true, false) // key1=100&key2=true&key3=&key4=
spliceUrlParam({ key1: '100', key2: 'true', key3: 'null', key4: 'undefined', key4: '测试' })
// ?key1=100&key2=true&key3=null&key4=undefined&key5=%E6%B5%8B%E8%AF%95
spliceUrlParam({ key1: '100', key2: 'true', key3: 'null', key4: 'undefined' }, true)
// ?key1=100&key2=true&key3=&key4=
spliceUrlParam({ key1: '100', key2: 'true', key3: 'null', key4: 'undefined' }, true, false)
// key1=100&key2=true&key3=&key4=
```

- Types:
Expand All @@ -1540,6 +1547,77 @@ declare function spliceUrlParam(
): string | null
```

#### safeParse

Secure parsing of JSON strings

- Since: `5.16.0`

- Arguments:

| Parameters | Description | Type | Optional | Required | Default |
| ---------- | ----------------------- | --------- | -------------- | -------- | ------- |
| data | JSON string | `string` | - | `true` | - |
| covert | Whether to convert data | `boolean` | `true`/`false` | `false` | `true` |

- Returns: `Object`

- Example:

```ts
safeParse('100')
// 100
safeParse('{"a":"undefined","b":"NaN","c":"Infinity"}')
// { b: NaN, c: Infinity }
```

- Types:

```ts
declare function safeParse(data: string, covert?: boolean): any
```

#### safeStringify

Secure stringify of JSON Object

- Since: `5.16.0`

- Arguments:

| Parameters | Description | Type | Optional | Required | Default |
| ---------- | ----------------------- | --------- | -------------- | -------- | ------- |
| data | JSON Object | `any` | - | `true` | - |
| covert | Whether to convert data | `boolean` | `true`/`false` | `false` | `true` |

- Returns: `string`

- Example:

```ts
safeStringify(100)
// "100"
safeStringify(undefined)
// "undefined"
safeStringify(NaN)
// "NaN"
safeStringify(Infinity)
// "Infinity"
safeStringify({ a: undefined, b: NaN, c: Infinity })
// {"a":"undefined","b":"NaN","c":"Infinity"}
```

- Types:

```ts
declare function safeStringify(data: any, covert?: boolean): string
```

#### getDirParam

Get the URL parameter in the form of a directory
Expand Down
48 changes: 24 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "js-cool",
"description": "Collection of common JavaScript / TypeScript utilities",
"version": "5.15.2",
"version": "5.16.0",
"packageManager": "pnpm@8.9.2",
"main": "dist/index.cjs.js",
"module": "dist/index.esm-bundler.js",
Expand Down Expand Up @@ -56,47 +56,47 @@
"mount-style": "^1.2.0",
"os-lang": "^3.2.0",
"tslib": "^2.6.2",
"use-downloads": "^1.5.0"
"use-downloads": "^1.5.1"
},
"devDependencies": {
"@babel/core": "^7.23.2",
"@babel/plugin-transform-runtime": "^7.23.2",
"@babel/preset-env": "^7.23.2",
"@babel/preset-typescript": "^7.23.2",
"@eslint-sets/eslint-config-ts": "^5.10.0",
"@microsoft/api-extractor": "^7.38.1",
"@rollup/plugin-alias": "^5.0.1",
"@babel/core": "^7.23.7",
"@babel/plugin-transform-runtime": "^7.23.7",
"@babel/preset-env": "^7.23.8",
"@babel/preset-typescript": "^7.23.3",
"@eslint-sets/eslint-config-ts": "^5.11.0",
"@microsoft/api-extractor": "^7.39.1",
"@rollup/plugin-alias": "^5.1.0",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-json": "^6.0.1",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-replace": "^5.0.5",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.5",
"@types/activex-excel": "^14.0.8",
"@types/babel__core": "^7.20.3",
"@types/node": "^20.8.9",
"@rollup/plugin-typescript": "^11.1.6",
"@types/activex-excel": "^14.0.10",
"@types/babel__core": "^7.20.5",
"@types/node": "^20.11.5",
"babel-loader": "^9.1.3",
"core-js": "^3.33.2",
"core-js": "^3.35.1",
"cross-env": "^7.0.3",
"eslint": "^8.52.0",
"fast-glob": "^3.3.1",
"eslint": "^8.56.0",
"fast-glob": "^3.3.2",
"load-yml": "^1.4.0",
"madge": "^6.1.0",
"npm-run-all": "^4.1.5",
"prettier": "^3.0.3",
"prettier": "^3.2.4",
"prettier-config-common": "^1.4.0",
"reinstaller": "^3.0.2",
"rm-all": "^1.1.1",
"rollup": "^4.1.5",
"rollup": "^4.9.6",
"rollup-plugin-cleanup": "^3.2.1",
"rollup-plugin-filesize": "^10.0.0",
"rollup-plugin-polyfill-node": "^0.12.0",
"rollup-plugin-visualizer": "^5.9.2",
"rollup-plugin-polyfill-node": "^0.13.0",
"rollup-plugin-visualizer": "^5.12.0",
"tsnd": "^1.1.0",
"typedoc": "^0.25.3",
"typedoc-plugin-markdown": "^3.16.0",
"typescript": "^5.2.2",
"typedoc": "^0.25.7",
"typedoc-plugin-markdown": "^3.17.1",
"typescript": "^5.3.3",
"zx": "^7.2.3"
},
"engines": {
Expand Down
Loading

0 comments on commit 9204069

Please sign in to comment.