@oipage/core.js 1.0.0-alpha.1 → 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.
Files changed (85) hide show
  1. package/CHANGELOG +52 -5
  2. package/LICENSE +20 -20
  3. package/README.md +170 -50
  4. package/dist/core.esm.js +2711 -0
  5. package/dist/core.js +2715 -147
  6. package/dist/core.min.js +2 -6
  7. package/package.json +63 -34
  8. package/src/Array/group.js +35 -0
  9. package/src/Array/index.js +21 -0
  10. package/src/Array/list.js +79 -0
  11. package/src/Array/sort.js +40 -0
  12. package/src/Array/tool.js +20 -0
  13. package/src/Array/unique.js +30 -0
  14. package/src/Cache/driver.js +86 -0
  15. package/src/Cache/expire.js +21 -0
  16. package/src/Cache/index.js +33 -0
  17. package/src/Cache/store.js +113 -0
  18. package/src/Color/adjust.js +67 -0
  19. package/src/Color/convert.js +100 -0
  20. package/src/Color/index.js +19 -0
  21. package/src/Color/tool.js +39 -0
  22. package/src/Digits/compare.js +33 -0
  23. package/src/Digits/format.js +55 -0
  24. package/src/Digits/index.js +32 -0
  25. package/src/Digits/math.js +75 -0
  26. package/src/Digits/precise.js +230 -0
  27. package/src/Digits/tool.js +29 -0
  28. package/src/Id/index.js +17 -0
  29. package/src/Id/nanoid.js +24 -0
  30. package/src/Id/random.js +40 -0
  31. package/src/Id/tool.js +38 -0
  32. package/src/Id/uuid.js +21 -0
  33. package/src/Object/check.js +15 -0
  34. package/src/Object/clone.js +66 -0
  35. package/src/Object/equal.js +63 -0
  36. package/src/Object/index.js +25 -0
  37. package/src/Object/merge.js +35 -0
  38. package/src/Object/path.js +58 -0
  39. package/src/Object/pick.js +34 -0
  40. package/src/Query/index.js +14 -0
  41. package/src/Query/parse.js +40 -0
  42. package/src/Query/stringify.js +45 -0
  43. package/src/Query/tool.js +58 -0
  44. package/src/Query/url.js +63 -0
  45. package/src/String/case.js +35 -0
  46. package/src/String/escape.js +40 -0
  47. package/src/String/index.js +28 -0
  48. package/src/String/mask.js +70 -0
  49. package/src/String/pad.js +23 -0
  50. package/src/String/trim.js +10 -0
  51. package/src/String/truncate.js +36 -0
  52. package/src/String/width.js +27 -0
  53. package/src/Time/arithmetic.js +61 -0
  54. package/src/Time/calendar.js +37 -0
  55. package/src/Time/compare.js +28 -0
  56. package/src/Time/field.js +37 -0
  57. package/src/Time/format.js +28 -0
  58. package/src/Time/index.js +97 -0
  59. package/src/Time/tool.js +20 -0
  60. package/src/Validate/contact.js +14 -0
  61. package/src/Validate/identity.js +57 -0
  62. package/src/Validate/index.js +24 -0
  63. package/src/Validate/network.js +59 -0
  64. package/src/Validate/type.js +28 -0
  65. package/src/index.js +10 -1
  66. package/src/shared/date.js +123 -0
  67. package/src/shared/is.js +63 -0
  68. package/src/tool.js +3 -0
  69. package/types/Array.d.ts +33 -0
  70. package/types/Cache.d.ts +51 -0
  71. package/types/Color.d.ts +43 -0
  72. package/types/Digits.d.ts +92 -0
  73. package/types/Id.d.ts +25 -0
  74. package/types/Object.d.ts +45 -0
  75. package/types/Query.d.ts +35 -0
  76. package/types/String.d.ts +62 -0
  77. package/types/Time.d.ts +136 -0
  78. package/types/Validate.d.ts +39 -0
  79. package/types/index.d.ts +30 -3
  80. package/.github/FUNDING.yml +0 -12
  81. package/.mailmap +0 -1
  82. package/AUTHORS.txt +0 -6
  83. package/src/Dater/index.js +0 -61
  84. package/src/Dater/tool.js +0 -25
  85. package/types/Dater.ts +0 -31
@@ -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,3 +1,30 @@
1
- import DaterType from "./Dater"
2
-
3
- export let Dater: DaterType
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"
@@ -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
@@ -1,6 +0,0 @@
1
- Authors ordered by first contribution.
2
-
3
- zxl20070701 <1904314465@qq.com> <https://github.com/zxl20070701>
4
-
5
- -----------------------------------------------------
6
- We thank all of them for their contributions!
@@ -1,61 +0,0 @@
1
- import { dateFormat } from "oipage/web/format"
2
-
3
- export function Dater(date, format = {}) {
4
- this.inputFormat = format.input || "yyyy/MM/dd"
5
- this.outputFormat = format.output || "yyyy/MM/dd"
6
-
7
- // 字符串
8
- if (date && typeof date === "string") {
9
- let temp = dateFormat(date, {
10
- inputFormat: this.inputFormat
11
- }).split("/")
12
-
13
- this.year = +temp[0]
14
- this.month = +temp[1]
15
- this.day = +temp[2]
16
- }
17
-
18
- else {
19
- // 不是Date对象
20
- if (!(date && typeof date === "object" && date.constructor === Date)) date = new Date()
21
-
22
- this.year = date.getFullYear()
23
- this.month = date.getMonth() + 1
24
- this.day = date.getDate()
25
- }
26
- }
27
-
28
- Dater.prototype.valueOf = function () {
29
- return dateFormat(`${this.year}/${this.month}/${this.day}`, {
30
- format: this.outputFormat
31
- })
32
- }
33
-
34
- Dater.prototype.addYear = function (year) {
35
- this.year += year
36
- return this
37
- }
38
-
39
- Dater.prototype.addMonth = function (month) {
40
- let month1 = month % 12 // 零碎的月份
41
- this.year += (month - month1) / 12 // 整齐的年份
42
-
43
- if (month1 > 0) {
44
- let month2 = 12 - this.month // 新增月份剩余空间
45
- if (month2 >= month1) {
46
- this.month += month1
47
- } else {
48
- this.year += 1
49
- this.month = month1 - month2
50
- }
51
- } else if (month1 < 0) {
52
- if (this.month + month1 > 0) {
53
- this.month += month1
54
- } else {
55
- this.year -= 1
56
- this.month += 12 + month1
57
- }
58
- }
59
-
60
- return this
61
- }
package/src/Dater/tool.js DELETED
@@ -1,25 +0,0 @@
1
- // 计算某年多少天
2
- export let calcYearDays = function () {
3
- if ((year % 4 != 0) || (year % 100 == 0 && year % 400 != 0)) {
4
- return 365
5
- } else {
6
- return 366
7
- }
8
- }
9
-
10
- // 计算某月多少天
11
- export let calcMonthDays = function (year, month) {
12
-
13
- if (month == 2) {
14
-
15
- if ((year % 4 != 0) || (year % 100 == 0 && year % 400 != 0)) {
16
- return 28
17
- } else {
18
- return 29
19
- }
20
-
21
- } else {
22
- return [31, -1, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month - 1]
23
- }
24
-
25
- }
package/types/Dater.ts DELETED
@@ -1,31 +0,0 @@
1
- export default interface DaterType {
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
- * 按照format.outout格式返回当前维护的日期
17
- */
18
- valueOf(): string
19
-
20
- /**
21
- * 新增year年后的日期(如果year为负数,就是减少)
22
- * @param year
23
- */
24
- addYear(year: number): this
25
-
26
- /**
27
- * 新增month月后的日期(如果month为负数,就是减少)
28
- * @param month
29
- */
30
- addMonth(month: number): this
31
- }