@polyv/utils 2.0.0-beta.1 → 2.0.0-beta.4
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/README.md +8 -8
- package/dist/cjs/boolean.d.ts +7 -1
- package/dist/cjs/date.d.ts +3 -3
- package/dist/cjs/date.js +1 -1
- package/dist/es/boolean.d.ts +7 -1
- package/dist/es/date.d.ts +3 -3
- package/dist/es/date.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
## 安装
|
|
6
6
|
|
|
7
7
|
```
|
|
8
|
-
npm install @polyv/utils
|
|
8
|
+
npm install @polyv/utils@next
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
NPM 包同时提供了 ES 模块以及 CommonJS 模块,分别位于 `dist/es` 和 `dist/cjs` 两个文件夹。它们使用上的区别和优缺点在于:
|
|
@@ -86,19 +86,19 @@ import { Countdown } from '@utils/countdown';
|
|
|
86
86
|
- Android >= 5 (未测试更低版本)
|
|
87
87
|
|
|
88
88
|
## 其他
|
|
89
|
-
- [API 文档(1.
|
|
89
|
+
- [API 文档(1.x)](https://polyv.github.io/fed-common-utils/1.x/index.html)
|
|
90
90
|
- [API 文档(2.x)](https://polyv.github.io/fed-common-utils/2.x/index.html)
|
|
91
91
|
|
|
92
92
|
## 2.0.0 版本的变更
|
|
93
93
|
|
|
94
94
|
2.0.0 与 1.x 相比有较大的变更,如需升级,请参阅下方变更说明:
|
|
95
95
|
|
|
96
|
-
-
|
|
97
|
-
- 原 lang
|
|
98
|
-
- 原 browser
|
|
99
|
-
- 原 cookie
|
|
100
|
-
- 原 polling
|
|
101
|
-
- 原 storage
|
|
96
|
+
- 模块变更:
|
|
97
|
+
- 原 lang 模块已移除,可以使用 [@just4/util](https://www.npmjs.com/package/@just4/util) 或 [lodash-es](https://www.npmjs.com/package/lodash-es) 代替。
|
|
98
|
+
- 原 browser 模块已移除,可以使用 [@just4/ua-info](https://www.npmjs.com/package/@just4/ua-info) 代替。
|
|
99
|
+
- 原 cookie 模块已移除,可以使用 [@just4/cookie](https://www.npmjs.com/package/@just4/cookie) 代替。
|
|
100
|
+
- 原 polling 模块已移除,可以使用 [@just4/polling](https://www.npmjs.com/package/@just4/polling) 代替。
|
|
101
|
+
- 原 storage 模块已移除,可以使用 [@just4/storage](https://www.npmjs.com/package/@just4/storage) 代替。
|
|
102
102
|
- 部分 API 的变更:
|
|
103
103
|
- boolean 模块的 `ynToBool` 支持指定默认值。
|
|
104
104
|
- countdown 模块的 `Countdown` 类增加 `pause` 方法。
|
package/dist/cjs/boolean.d.ts
CHANGED
|
@@ -15,10 +15,16 @@ export declare function boolToYN(value: boolean): YOrN;
|
|
|
15
15
|
/**
|
|
16
16
|
* Y 或者 N 转换为布尔值。
|
|
17
17
|
* @param value Y 或者 N。
|
|
18
|
+
* @return 布尔值。
|
|
19
|
+
*/
|
|
20
|
+
export declare function ynToBool(value: YOrN): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Y 或者 N 转换为布尔值。
|
|
23
|
+
* @param value Y 或 N 为合法值,其他为非法值。
|
|
18
24
|
* @param defaultValue 当 value 为非法值时的默认值。
|
|
19
25
|
* @return 布尔值。
|
|
20
26
|
*/
|
|
21
|
-
export declare function ynToBool(value:
|
|
27
|
+
export declare function ynToBool(value: unknown, defaultValue?: YOrN): boolean;
|
|
22
28
|
/**
|
|
23
29
|
* 检查指定数组元素的值是否都为 Y。
|
|
24
30
|
* @param values 指定数组。
|
package/dist/cjs/date.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export interface FormatSecondsOptions {
|
|
|
20
20
|
/**
|
|
21
21
|
* 段数,2 或者 3。
|
|
22
22
|
* 为 3 时,格式化样式为「时:分:秒」。
|
|
23
|
-
* 为 2
|
|
23
|
+
* 为 2 时,格式化样式为「分:秒」。
|
|
24
24
|
*/
|
|
25
25
|
segments?: number;
|
|
26
26
|
/**
|
|
@@ -35,10 +35,10 @@ export interface FormatSecondsOptions {
|
|
|
35
35
|
* @return 格式化结果。
|
|
36
36
|
* @example
|
|
37
37
|
* ```javascript
|
|
38
|
-
* formatSeconds(3682); // '
|
|
38
|
+
* formatSeconds(3682); // '61:22'
|
|
39
39
|
* formatSeconds(82); // '01:22'
|
|
40
40
|
* formatSeconds(82, { segments: 3 }); // '00:01:22'
|
|
41
|
-
* formatSeconds(3682, { digits: 1 }); // '1:1:22'
|
|
41
|
+
* formatSeconds(3682, { segments: 3, digits: 1 }); // '1:1:22'
|
|
42
42
|
* ```
|
|
43
43
|
*/
|
|
44
44
|
export declare function formatSeconds(secs: number, options?: FormatSecondsOptions): string;
|
package/dist/cjs/date.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function ensureDate(e){return"object"!=typeof e&&(e=new Date(e)),e}function formatDate(e,t){var r={Y:(e=ensureDate(e)).getFullYear(),M:e.getMonth()+1,D:e.getDate(),h:e.getHours(),m:e.getMinutes(),s:e.getSeconds()};return t.replace(/([YMDhms])\1*/g,(function(e){var t=r[e[0]].toString(),n=e.length;return n>t.length&&(t=new Array(n-t.length+1).join("0")+t),t}))}function formatSeconds(e,t){if(void 0===t&&(t={segments:2,digits:2}),e=Number(e),isNaN(e)||e<0)throw new Error('"secs" must be a positive integer');var r=0|(t.segments||2),n=0|(t.digits||2);n=Math.max(1,n),-1===[2,3].indexOf(r)&&(r=2);var o=new Array(n+1).join("0"),a=[
|
|
1
|
+
"use strict";function ensureDate(e){return"object"!=typeof e&&(e=new Date(e)),e}function formatDate(e,t){var r={Y:(e=ensureDate(e)).getFullYear(),M:e.getMonth()+1,D:e.getDate(),h:e.getHours(),m:e.getMinutes(),s:e.getSeconds()};return t.replace(/([YMDhms])\1*/g,(function(e){var t=r[e[0]].toString(),n=e.length;return n>t.length&&(t=new Array(n-t.length+1).join("0")+t),t}))}function formatSeconds(e,t){if(void 0===t&&(t={segments:2,digits:2}),e=Number(e),isNaN(e)||e<0)throw new Error('"secs" must be a positive integer');var r=0|(t.segments||2),n=0|(t.digits||2);n=Math.max(1,n),-1===[2,3].indexOf(r)&&(r=2);var o=new Array(n+1).join("0"),a=[60,1];return 3===t.segments&&a.unshift(3600),a.map((function(t){var r=Math.floor(e/t),a=r.toString().length;return e%=t,(o+r).slice(-Math.max(a,n))})).join(":")}Object.defineProperty(exports,"__esModule",{value:!0}),exports.formatSeconds=exports.formatDate=void 0,exports.formatDate=formatDate,exports.formatSeconds=formatSeconds;
|
package/dist/es/boolean.d.ts
CHANGED
|
@@ -15,10 +15,16 @@ export declare function boolToYN(value: boolean): YOrN;
|
|
|
15
15
|
/**
|
|
16
16
|
* Y 或者 N 转换为布尔值。
|
|
17
17
|
* @param value Y 或者 N。
|
|
18
|
+
* @return 布尔值。
|
|
19
|
+
*/
|
|
20
|
+
export declare function ynToBool(value: YOrN): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Y 或者 N 转换为布尔值。
|
|
23
|
+
* @param value Y 或 N 为合法值,其他为非法值。
|
|
18
24
|
* @param defaultValue 当 value 为非法值时的默认值。
|
|
19
25
|
* @return 布尔值。
|
|
20
26
|
*/
|
|
21
|
-
export declare function ynToBool(value:
|
|
27
|
+
export declare function ynToBool(value: unknown, defaultValue?: YOrN): boolean;
|
|
22
28
|
/**
|
|
23
29
|
* 检查指定数组元素的值是否都为 Y。
|
|
24
30
|
* @param values 指定数组。
|
package/dist/es/date.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export interface FormatSecondsOptions {
|
|
|
20
20
|
/**
|
|
21
21
|
* 段数,2 或者 3。
|
|
22
22
|
* 为 3 时,格式化样式为「时:分:秒」。
|
|
23
|
-
* 为 2
|
|
23
|
+
* 为 2 时,格式化样式为「分:秒」。
|
|
24
24
|
*/
|
|
25
25
|
segments?: number;
|
|
26
26
|
/**
|
|
@@ -35,10 +35,10 @@ export interface FormatSecondsOptions {
|
|
|
35
35
|
* @return 格式化结果。
|
|
36
36
|
* @example
|
|
37
37
|
* ```javascript
|
|
38
|
-
* formatSeconds(3682); // '
|
|
38
|
+
* formatSeconds(3682); // '61:22'
|
|
39
39
|
* formatSeconds(82); // '01:22'
|
|
40
40
|
* formatSeconds(82, { segments: 3 }); // '00:01:22'
|
|
41
|
-
* formatSeconds(3682, { digits: 1 }); // '1:1:22'
|
|
41
|
+
* formatSeconds(3682, { segments: 3, digits: 1 }); // '1:1:22'
|
|
42
42
|
* ```
|
|
43
43
|
*/
|
|
44
44
|
export declare function formatSeconds(secs: number, options?: FormatSecondsOptions): string;
|
package/dist/es/date.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function ensureDate(t){return"object"!=typeof t&&(t=new Date(t)),t}export function formatDate(t,e){const n={Y:(t=ensureDate(t)).getFullYear(),M:t.getMonth()+1,D:t.getDate(),h:t.getHours(),m:t.getMinutes(),s:t.getSeconds()};return e.replace(/([YMDhms])\1*/g,(function(t){let e=n[t[0]].toString();const r=t.length;return r>e.length&&(e=new Array(r-e.length+1).join("0")+e),e}))}export function formatSeconds(t,e={segments:2,digits:2}){if(t=Number(t),isNaN(t)||t<0)throw new Error('"secs" must be a positive integer');let n=0|(e.segments||2),r=0|(e.digits||2);r=Math.max(1,r),-1===[2,3].indexOf(n)&&(n=2);const o=new Array(r+1).join("0"),s=[
|
|
1
|
+
function ensureDate(t){return"object"!=typeof t&&(t=new Date(t)),t}export function formatDate(t,e){const n={Y:(t=ensureDate(t)).getFullYear(),M:t.getMonth()+1,D:t.getDate(),h:t.getHours(),m:t.getMinutes(),s:t.getSeconds()};return e.replace(/([YMDhms])\1*/g,(function(t){let e=n[t[0]].toString();const r=t.length;return r>e.length&&(e=new Array(r-e.length+1).join("0")+e),e}))}export function formatSeconds(t,e={segments:2,digits:2}){if(t=Number(t),isNaN(t)||t<0)throw new Error('"secs" must be a positive integer');let n=0|(e.segments||2),r=0|(e.digits||2);r=Math.max(1,r),-1===[2,3].indexOf(n)&&(n=2);const o=new Array(r+1).join("0"),s=[60,1];return 3===e.segments&&s.unshift(3600),s.map((e=>{const n=Math.floor(t/e),s=n.toString().length;return t%=e,(o+n).slice(-Math.max(s,r))})).join(":")}
|