@oipage/core.js 1.0.0 → 1.1.0-alpha.0
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/CHANGELOG +52 -6
- package/LICENSE +20 -20
- package/README.md +170 -51
- package/dist/core.esm.js +2711 -0
- package/dist/core.js +2709 -208
- package/dist/core.min.js +2 -6
- package/package.json +63 -34
- package/src/Array/group.js +35 -0
- package/src/Array/index.js +21 -0
- package/src/Array/list.js +79 -0
- package/src/Array/sort.js +40 -0
- package/src/Array/tool.js +20 -0
- package/src/Array/unique.js +30 -0
- package/src/Cache/driver.js +86 -0
- package/src/Cache/expire.js +21 -0
- package/src/Cache/index.js +33 -0
- package/src/Cache/store.js +113 -0
- package/src/Color/adjust.js +67 -0
- package/src/Color/convert.js +100 -0
- package/src/Color/index.js +19 -0
- package/src/Color/tool.js +39 -0
- package/src/Digits/compare.js +33 -0
- package/src/Digits/format.js +55 -0
- package/src/Digits/index.js +32 -9
- package/src/Digits/math.js +75 -0
- package/src/Digits/precise.js +230 -0
- package/src/Digits/tool.js +29 -0
- package/src/Id/index.js +17 -0
- package/src/Id/nanoid.js +24 -0
- package/src/Id/random.js +40 -0
- package/src/Id/tool.js +38 -0
- package/src/Id/uuid.js +21 -0
- package/src/Object/check.js +15 -0
- package/src/Object/clone.js +66 -0
- package/src/Object/equal.js +63 -0
- package/src/Object/index.js +25 -0
- package/src/Object/merge.js +35 -0
- package/src/Object/path.js +58 -0
- package/src/Object/pick.js +34 -0
- package/src/Query/index.js +14 -0
- package/src/Query/parse.js +40 -0
- package/src/Query/stringify.js +45 -0
- package/src/Query/tool.js +58 -0
- package/src/Query/url.js +63 -0
- package/src/String/case.js +35 -0
- package/src/String/escape.js +40 -0
- package/src/String/index.js +28 -0
- package/src/String/mask.js +70 -0
- package/src/String/pad.js +23 -0
- package/src/String/trim.js +10 -0
- package/src/String/truncate.js +36 -0
- package/src/String/width.js +27 -0
- package/src/Time/arithmetic.js +61 -0
- package/src/Time/calendar.js +37 -0
- package/src/Time/compare.js +28 -0
- package/src/Time/field.js +37 -0
- package/src/Time/format.js +28 -0
- package/src/Time/index.js +97 -74
- package/src/Time/tool.js +20 -16
- package/src/Validate/contact.js +14 -0
- package/src/Validate/identity.js +57 -0
- package/src/Validate/index.js +24 -0
- package/src/Validate/network.js +59 -0
- package/src/Validate/type.js +28 -0
- package/src/index.js +10 -2
- package/src/shared/date.js +123 -0
- package/src/shared/is.js +63 -0
- package/src/tool.js +2 -2
- package/types/Array.d.ts +33 -0
- package/types/Cache.d.ts +51 -0
- package/types/Color.d.ts +43 -0
- package/types/Digits.d.ts +92 -0
- package/types/Id.d.ts +25 -0
- package/types/Object.d.ts +45 -0
- package/types/Query.d.ts +35 -0
- package/types/String.d.ts +62 -0
- package/types/Time.d.ts +136 -0
- package/types/Validate.d.ts +39 -0
- package/types/index.d.ts +30 -5
- package/.github/FUNDING.yml +0 -12
- package/.mailmap +0 -1
- package/AUTHORS.txt +0 -6
- package/types/Digits.ts +0 -13
- package/types/Time.ts +0 -52
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export interface DeepMergeOption {
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 数组合并策略:replace(默认)或 concat
|
|
5
|
+
*/
|
|
6
|
+
array?: "replace" | "concat"
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type Path = string | Array<string | number>
|
|
10
|
+
|
|
11
|
+
export interface ObjectType {
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 深拷贝,支持 Date、RegExp、Map、Set、ArrayBuffer 与循环引用
|
|
15
|
+
*/
|
|
16
|
+
deepClone<T>(value: T): T
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 深合并,返回新对象
|
|
20
|
+
*/
|
|
21
|
+
deepMerge<T extends object, S extends object>(target: T, source: S, options?: DeepMergeOption): T & S
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 把 a.b[0].c 解析成键名数组
|
|
25
|
+
*/
|
|
26
|
+
toPath(path: Path): string[]
|
|
27
|
+
|
|
28
|
+
get<T = any>(target: any, path: Path, defaultValue?: T): T
|
|
29
|
+
|
|
30
|
+
set<T extends object>(target: T, path: Path, value: any): T
|
|
31
|
+
|
|
32
|
+
pick<T extends object, K extends keyof T>(target: T, keys: K[] | K): Pick<T, K>
|
|
33
|
+
|
|
34
|
+
omit<T extends object, K extends keyof T>(target: T, keys: K[] | K): Omit<T, K>
|
|
35
|
+
|
|
36
|
+
isEmpty(value: any): boolean
|
|
37
|
+
|
|
38
|
+
isPlainObject(value: any): boolean
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 深比较
|
|
42
|
+
*/
|
|
43
|
+
equal(a: any, b: any): boolean
|
|
44
|
+
}
|
|
45
|
+
|
package/types/Query.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface ParsedUrl {
|
|
2
|
+
|
|
3
|
+
protocol: string
|
|
4
|
+
|
|
5
|
+
host: string
|
|
6
|
+
|
|
7
|
+
hostname: string
|
|
8
|
+
|
|
9
|
+
port: string
|
|
10
|
+
|
|
11
|
+
username: string
|
|
12
|
+
|
|
13
|
+
password: string
|
|
14
|
+
|
|
15
|
+
path: string
|
|
16
|
+
|
|
17
|
+
query: string
|
|
18
|
+
|
|
19
|
+
hash: string
|
|
20
|
+
|
|
21
|
+
params: Record<string, any>
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface QueryType {
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 解析查询串,支持 a=1&a=2、a[]=1、a[b]=1
|
|
28
|
+
*/
|
|
29
|
+
parseQuery(query: string): Record<string, any>
|
|
30
|
+
|
|
31
|
+
stringifyQuery(target: Record<string, any>): string
|
|
32
|
+
|
|
33
|
+
parseUrl(url: string): ParsedUrl
|
|
34
|
+
}
|
|
35
|
+
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export interface MaskOption {
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 保留首部字符数
|
|
5
|
+
*/
|
|
6
|
+
head?: number
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 保留尾部字符数
|
|
10
|
+
*/
|
|
11
|
+
tail?: number
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 替代字符,默认 *
|
|
15
|
+
*/
|
|
16
|
+
char?: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface StringType {
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 去掉首尾空白(包含全角空格与不换行空格)
|
|
23
|
+
*/
|
|
24
|
+
trim(str: string): string
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 显示宽度,中文等宽字符按 2 计算
|
|
28
|
+
*/
|
|
29
|
+
width(str: string): number
|
|
30
|
+
|
|
31
|
+
widthOf(char: string): number
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 按字符数截断
|
|
35
|
+
*/
|
|
36
|
+
truncate(str: string, maxLength: number, suffix?: string): string
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 按显示宽度截断
|
|
40
|
+
*/
|
|
41
|
+
cutByWidth(str: string, maxWidth: number, suffix?: string): string
|
|
42
|
+
|
|
43
|
+
pad(str: string, length: number, char?: string, position?: "start" | "end"): string
|
|
44
|
+
|
|
45
|
+
camelCase(str: string): string
|
|
46
|
+
|
|
47
|
+
kebabCase(str: string): string
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 按 Unicode 码位反转,不会拆坏 emoji
|
|
51
|
+
*/
|
|
52
|
+
reverse(str: string): string
|
|
53
|
+
|
|
54
|
+
mask(str: string, type?: "mobile" | "idcard" | "bankcard" | "email" | "name" | "custom", option?: MaskOption): string
|
|
55
|
+
|
|
56
|
+
maskMiddle(str: string, head: number, tail: number, char?: string): string
|
|
57
|
+
|
|
58
|
+
escapeHTML(str: string): string
|
|
59
|
+
|
|
60
|
+
unescapeHTML(str: string): string
|
|
61
|
+
}
|
|
62
|
+
|
package/types/Time.d.ts
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
export interface TimeFormat {
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 字符串输入格式,默认 yyyy/MM/dd
|
|
5
|
+
* 支持 yyyy、yy、MM、M、dd、d、HH、mm、ss
|
|
6
|
+
*/
|
|
7
|
+
input?: string
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 输出格式,默认 yyyy/MM/dd
|
|
11
|
+
*/
|
|
12
|
+
output?: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface TimeInstance {
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 年
|
|
19
|
+
*/
|
|
20
|
+
year: number
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 月
|
|
24
|
+
*/
|
|
25
|
+
month: number
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 日
|
|
29
|
+
*/
|
|
30
|
+
day: number
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 当前维护的年月日是否合法(手动修改 year/month/day 后可能非法)
|
|
34
|
+
*/
|
|
35
|
+
isValid(): boolean
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 复制一个内容相同、格式相同的新对象
|
|
39
|
+
*/
|
|
40
|
+
clone(): TimeInstance
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 本地时间零点对应的时间戳
|
|
44
|
+
*/
|
|
45
|
+
getTime(): number
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 转成 Date 对象(本地时间零点)
|
|
49
|
+
*/
|
|
50
|
+
toDate(): Date
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 按指定格式返回日期字符串,不传时用 outputFormat
|
|
54
|
+
*/
|
|
55
|
+
format(format?: string): string
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 按 outputFormat 返回日期字符串
|
|
59
|
+
*/
|
|
60
|
+
valueOf(): string
|
|
61
|
+
|
|
62
|
+
toString(): string
|
|
63
|
+
|
|
64
|
+
toJSON(): string
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 新增 year 年(负数即减少),闰日会夹取到当月最后一天
|
|
68
|
+
*/
|
|
69
|
+
addYear(year: number): TimeInstance
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 新增 month 月(负数即减少),月末日期会夹取
|
|
73
|
+
*/
|
|
74
|
+
addMonth(month: number): TimeInstance
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* 新增 day 天(负数即减少)
|
|
78
|
+
*/
|
|
79
|
+
addDay(day: number): TimeInstance
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 新增 week 周(负数即减少)
|
|
83
|
+
*/
|
|
84
|
+
addWeek(week: number): TimeInstance
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 与另一个日期相差的天数
|
|
88
|
+
*/
|
|
89
|
+
diffDays(other: string | Date | number | TimeInstance): number
|
|
90
|
+
|
|
91
|
+
isBefore(other: string | Date | number | TimeInstance): boolean
|
|
92
|
+
|
|
93
|
+
isAfter(other: string | Date | number | TimeInstance): boolean
|
|
94
|
+
|
|
95
|
+
isSame(other: string | Date | number | TimeInstance): boolean
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* 调整到当月第一天
|
|
99
|
+
*/
|
|
100
|
+
startOfMonth(): TimeInstance
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* 调整到当月最后一天
|
|
104
|
+
*/
|
|
105
|
+
endOfMonth(): TimeInstance
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* 星期几:0 表示周日
|
|
109
|
+
*/
|
|
110
|
+
getWeekDay(): number
|
|
111
|
+
|
|
112
|
+
isLeapYear(): boolean
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* 当月天数
|
|
116
|
+
*/
|
|
117
|
+
daysInMonth(): number
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface TimeConstructor {
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* 传入非法字符串或非法日期会抛错
|
|
124
|
+
*/
|
|
125
|
+
new(date?: string | Date | number, format?: TimeFormat): TimeInstance
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* 今天
|
|
129
|
+
*/
|
|
130
|
+
today(format?: TimeFormat): TimeInstance
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* 按指定格式解析日期字符串
|
|
134
|
+
*/
|
|
135
|
+
parse(input: string, format?: string): TimeInstance
|
|
136
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export interface ValidateType {
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 中国大陆手机号(13-19 号段)
|
|
5
|
+
*/
|
|
6
|
+
isMobile(value: string | number): boolean
|
|
7
|
+
|
|
8
|
+
isEmail(value: string): boolean
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 身份证号:15 位或 18 位,会校验出生日期与末位校验码
|
|
12
|
+
*/
|
|
13
|
+
isIdCard(value: string): boolean
|
|
14
|
+
|
|
15
|
+
isUrl(value: string): boolean
|
|
16
|
+
|
|
17
|
+
isIPv4(value: string): boolean
|
|
18
|
+
|
|
19
|
+
isIPv6(value: string): boolean
|
|
20
|
+
|
|
21
|
+
isIp(value: string): boolean
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 银行卡号,Luhn 校验
|
|
25
|
+
*/
|
|
26
|
+
isBankCard(value: string): boolean
|
|
27
|
+
|
|
28
|
+
isInteger(value: number | string): boolean
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 小数,不接受科学计数法
|
|
32
|
+
*/
|
|
33
|
+
isDecimal(value: string | number): boolean
|
|
34
|
+
|
|
35
|
+
isChinese(value: string): boolean
|
|
36
|
+
|
|
37
|
+
isPostCode(value: string | number): boolean
|
|
38
|
+
}
|
|
39
|
+
|
package/types/index.d.ts
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import type { TimeConstructor } from "./Time"
|
|
2
|
+
import type { DigitsConstructor } from "./Digits"
|
|
3
|
+
import type { StringType } from "./String"
|
|
4
|
+
import type { ValidateType } from "./Validate"
|
|
5
|
+
import type { ObjectType } from "./Object"
|
|
6
|
+
import type { ArrayType } from "./Array"
|
|
7
|
+
import type { QueryType } from "./Query"
|
|
8
|
+
import type { IdType } from "./Id"
|
|
9
|
+
import type { ColorType } from "./Color"
|
|
10
|
+
import type { CacheConstructor } from "./Cache"
|
|
11
|
+
|
|
12
|
+
export const Time: TimeConstructor
|
|
13
|
+
export const Digits: DigitsConstructor
|
|
14
|
+
export const String: StringType
|
|
15
|
+
export const Validate: ValidateType
|
|
16
|
+
export const Object: ObjectType
|
|
17
|
+
export const Array: ArrayType
|
|
18
|
+
export const Query: QueryType
|
|
19
|
+
export const Id: IdType
|
|
20
|
+
export const Color: ColorType
|
|
21
|
+
export const Cache: CacheConstructor
|
|
22
|
+
|
|
23
|
+
export type { TimeFormat, TimeInstance } from "./Time"
|
|
24
|
+
export type { DigitsInput, FormatOptions, DivideOptions, Rounding, DigitsInstance } from "./Digits"
|
|
25
|
+
export type { DeepMergeOption, Path } from "./Object"
|
|
26
|
+
export type { Iteratee, SortKey } from "./Array"
|
|
27
|
+
export type { MaskOption } from "./String"
|
|
28
|
+
export type { ParsedUrl } from "./Query"
|
|
29
|
+
export type { Rgb, Hsl } from "./Color"
|
|
30
|
+
export type { CacheDriver, CacheOptions, CacheInstance } from "./Cache"
|
package/.github/FUNDING.yml
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
# These are supported funding model platforms
|
|
2
|
-
|
|
3
|
-
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
|
4
|
-
patreon: # Replace with a single Patreon username
|
|
5
|
-
open_collective: # Replace with a single Open Collective username
|
|
6
|
-
ko_fi: # Replace with a single Ko-fi username
|
|
7
|
-
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
|
8
|
-
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
|
9
|
-
liberapay: # Replace with a single Liberapay username
|
|
10
|
-
issuehunt: # Replace with a single IssueHunt username
|
|
11
|
-
otechie: # Replace with a single Otechie username
|
|
12
|
-
custom: ['https://zxl20070701.github.io/notebook/home.html']
|
package/.mailmap
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
zxl20070701 <1904314465@qq.com>
|
package/AUTHORS.txt
DELETED
package/types/Digits.ts
DELETED
package/types/Time.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
export default interface TimeType {
|
|
2
|
-
new(date?: string | Date, format?: {
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 输入格式
|
|
6
|
-
*/
|
|
7
|
-
input?: "string"
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 输出格式
|
|
11
|
-
*/
|
|
12
|
-
outout?: "string"
|
|
13
|
-
}): this
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* 年
|
|
17
|
-
*/
|
|
18
|
-
year: number
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* 月
|
|
22
|
-
*/
|
|
23
|
-
month: number
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* 日
|
|
27
|
-
*/
|
|
28
|
-
day: number
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* 按照format.outout格式返回当前维护的日期
|
|
32
|
-
*/
|
|
33
|
-
valueOf(): string
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* 新增year年后的日期(如果year为负数,就是减少)
|
|
37
|
-
* @param year
|
|
38
|
-
*/
|
|
39
|
-
addYear(year: number): this
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* 新增month月后的日期(如果month为负数,就是减少)
|
|
43
|
-
* @param month
|
|
44
|
-
*/
|
|
45
|
-
addMonth(month: number): this
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* 新增day天后的日期(如果day为负数,就是减少)
|
|
49
|
-
* @param day
|
|
50
|
-
*/
|
|
51
|
-
addDay(day: number): this
|
|
52
|
-
}
|