stringzy 2.2.0 → 3.0.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/.github/workflows/publish.yml +29 -0
- package/.github/workflows/test-on-pr.yml +23 -0
- package/CONTRIBUTING.md +87 -0
- package/LICENSE +21 -21
- package/README.md +952 -723
- package/changelog.txt +110 -102
- package/dist/analyzing/characterCount.d.ts +1 -0
- package/dist/analyzing/characterCount.js +9 -0
- package/dist/analyzing/characterFrequency.d.ts +1 -0
- package/dist/analyzing/characterFrequency.js +16 -0
- package/dist/analyzing/complexity.d.ts +6 -0
- package/dist/analyzing/complexity.js +30 -0
- package/dist/analyzing/index.d.ts +20 -0
- package/dist/analyzing/index.js +29 -0
- package/dist/analyzing/readingDuration.d.ts +10 -0
- package/dist/analyzing/readingDuration.js +17 -0
- package/dist/analyzing/stringSimilarity.d.ts +8 -0
- package/dist/analyzing/stringSimilarity.js +145 -0
- package/dist/analyzing/wordCount.d.ts +1 -0
- package/dist/analyzing/wordCount.js +11 -0
- package/dist/formatting/capitalize.d.ts +1 -0
- package/dist/formatting/capitalize.js +12 -0
- package/dist/formatting/index.d.ts +11 -0
- package/dist/formatting/index.js +17 -0
- package/dist/formatting/number.d.ts +1 -0
- package/dist/formatting/number.js +7 -0
- package/dist/formatting/phone.d.ts +2 -0
- package/dist/formatting/phone.js +25 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +30 -0
- package/dist/tests/analyzing/characterCount.test.d.ts +1 -0
- package/dist/tests/analyzing/characterCount.test.js +19 -0
- package/dist/tests/analyzing/characterFrequency.test.d.ts +1 -0
- package/dist/tests/analyzing/characterFrequency.test.js +22 -0
- package/dist/tests/analyzing/complexity.test.d.ts +1 -0
- package/dist/tests/analyzing/complexity.test.js +28 -0
- package/dist/tests/analyzing/readingDuration.test.d.ts +1 -0
- package/dist/tests/analyzing/readingDuration.test.js +45 -0
- package/dist/tests/analyzing/stringSimilarity.test.d.ts +1 -0
- package/dist/tests/analyzing/stringSimilarity.test.js +61 -0
- package/dist/tests/analyzing/wordCount.test.d.ts +1 -0
- package/dist/tests/analyzing/wordCount.test.js +22 -0
- package/dist/tests/formatting/capitalize.test.d.ts +1 -0
- package/dist/tests/formatting/capitalize.test.js +22 -0
- package/dist/tests/formatting/number.test.d.ts +1 -0
- package/dist/tests/formatting/number.test.js +19 -0
- package/dist/tests/formatting/phone.test.d.ts +1 -0
- package/dist/tests/formatting/phone.test.js +25 -0
- package/dist/tests/transformations/camelCase.test.d.ts +1 -0
- package/dist/tests/transformations/camelCase.test.js +19 -0
- package/dist/tests/transformations/capitalizeWords.test.d.ts +1 -0
- package/dist/tests/transformations/capitalizeWords.test.js +19 -0
- package/dist/tests/transformations/constantCase.test.d.ts +1 -0
- package/dist/tests/transformations/constantCase.test.js +19 -0
- package/dist/tests/transformations/deburr.test.d.ts +1 -0
- package/dist/tests/transformations/deburr.test.js +27 -0
- package/dist/tests/transformations/escapeHTML.test.d.ts +1 -0
- package/dist/tests/transformations/escapeHTML.test.js +46 -0
- package/dist/tests/transformations/initials.test.d.ts +1 -0
- package/dist/tests/transformations/initials.test.js +25 -0
- package/dist/tests/transformations/kebabCase.test.d.ts +1 -0
- package/dist/tests/transformations/kebabCase.test.js +19 -0
- package/dist/tests/transformations/maskSegment.test.d.ts +1 -0
- package/dist/tests/transformations/maskSegment.test.js +30 -0
- package/dist/tests/transformations/pascalCase.test.d.ts +1 -0
- package/dist/tests/transformations/pascalCase.test.js +19 -0
- package/dist/tests/transformations/removeDuplicates.test.d.ts +1 -0
- package/dist/tests/transformations/removeDuplicates.test.js +19 -0
- package/dist/tests/transformations/removeSpecialChars.test.d.ts +1 -0
- package/dist/tests/transformations/removeSpecialChars.test.js +22 -0
- package/dist/tests/transformations/removeWords.test.d.ts +1 -0
- package/dist/tests/transformations/removeWords.test.js +25 -0
- package/dist/tests/transformations/snakeCase.test.d.ts +1 -0
- package/dist/tests/transformations/snakeCase.test.js +19 -0
- package/dist/tests/transformations/titleCase.test.d.ts +1 -0
- package/dist/tests/transformations/titleCase.test.js +19 -0
- package/dist/tests/transformations/toSlug.test.d.ts +1 -0
- package/dist/tests/transformations/toSlug.test.js +22 -0
- package/dist/tests/transformations/truncateText.test.d.ts +1 -0
- package/dist/tests/transformations/truncateText.test.js +31 -0
- package/dist/tests/validations/isDate.test.d.ts +1 -0
- package/dist/tests/validations/isDate.test.js +55 -0
- package/dist/tests/validations/isEmail.test.d.ts +1 -0
- package/dist/tests/validations/isEmail.test.js +17 -0
- package/dist/tests/validations/isEmpty.test.d.ts +1 -0
- package/dist/tests/validations/isEmpty.test.js +19 -0
- package/dist/tests/validations/isHexColor.test.d.ts +1 -0
- package/dist/tests/validations/isHexColor.test.js +32 -0
- package/dist/tests/validations/isIPv4.test.d.ts +1 -0
- package/dist/tests/validations/isIPv4.test.js +59 -0
- package/dist/tests/validations/isSlug.test.d.ts +1 -0
- package/dist/tests/validations/isSlug.test.js +22 -0
- package/dist/tests/validations/isURL.test.d.ts +1 -0
- package/dist/tests/validations/isURL.test.js +18 -0
- package/dist/transformations/camelCase.d.ts +1 -0
- package/dist/transformations/camelCase.js +15 -0
- package/dist/transformations/capitalizeWords.d.ts +1 -0
- package/dist/transformations/capitalizeWords.js +9 -0
- package/dist/transformations/constantCase.d.ts +1 -0
- package/dist/transformations/constantCase.js +15 -0
- package/dist/transformations/deburr.d.ts +7 -0
- package/dist/transformations/deburr.js +16 -0
- package/dist/transformations/escapeHTML.d.ts +1 -0
- package/dist/transformations/escapeHTML.js +14 -0
- package/dist/transformations/index.d.ts +49 -0
- package/dist/transformations/index.js +67 -0
- package/dist/transformations/initials.d.ts +1 -0
- package/dist/transformations/initials.js +19 -0
- package/dist/transformations/kebabCase.d.ts +1 -0
- package/dist/transformations/kebabCase.js +15 -0
- package/dist/transformations/maskSegment.d.ts +9 -0
- package/dist/transformations/maskSegment.js +25 -0
- package/dist/transformations/pascalCase.d.ts +1 -0
- package/dist/transformations/pascalCase.js +15 -0
- package/dist/transformations/removeDuplicates.d.ts +1 -0
- package/dist/transformations/removeDuplicates.js +13 -0
- package/dist/transformations/removeSpecialChars.d.ts +1 -0
- package/dist/transformations/removeSpecialChars.js +12 -0
- package/dist/transformations/removeWords.d.ts +1 -0
- package/dist/transformations/removeWords.js +23 -0
- package/dist/transformations/snakeCase.d.ts +1 -0
- package/dist/transformations/snakeCase.js +15 -0
- package/dist/transformations/titleCase.d.ts +1 -0
- package/dist/transformations/titleCase.js +14 -0
- package/dist/transformations/toSlug.d.ts +1 -0
- package/dist/transformations/toSlug.js +13 -0
- package/dist/transformations/truncateText.d.ts +1 -0
- package/dist/transformations/truncateText.js +19 -0
- package/dist/validations/index.d.ts +23 -0
- package/dist/validations/index.js +33 -0
- package/dist/validations/isDate.d.ts +18 -0
- package/dist/validations/isDate.js +63 -0
- package/dist/validations/isEmail.d.ts +1 -0
- package/dist/validations/isEmail.js +7 -0
- package/dist/validations/isEmpty.d.ts +1 -0
- package/dist/validations/isEmpty.js +6 -0
- package/dist/validations/isHexColor.d.ts +7 -0
- package/dist/validations/isHexColor.js +15 -0
- package/dist/validations/isIPv4.d.ts +1 -0
- package/dist/validations/isIPv4.js +13 -0
- package/dist/validations/isSlug.d.ts +1 -0
- package/dist/validations/isSlug.js +10 -0
- package/dist/validations/isURL.d.ts +1 -0
- package/dist/validations/isURL.js +12 -0
- package/package.json +10 -4
- package/analysis.js +0 -21
- package/assets/stringzy-banner2.jpg +0 -0
- package/formatting.js +0 -37
- package/index.js +0 -75
- package/transformations.js +0 -190
- package/validations.js +0 -80
package/index.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* index.js
|
|
3
|
-
* Main entry point for the srtingzy package
|
|
4
|
-
*
|
|
5
|
-
* This file serves as the public API for the entire library,
|
|
6
|
-
* organizing and exporting all functionality in a structured way.
|
|
7
|
-
*
|
|
8
|
-
* @module stringzy
|
|
9
|
-
* @author Samarth Ruia
|
|
10
|
-
* @version 2.2.0
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import * as transformations from './transformations.js';
|
|
14
|
-
import * as validations from './validations.js';
|
|
15
|
-
import * as analysis from './analysis.js';
|
|
16
|
-
import * as formatting from './formatting.js';
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export const {
|
|
20
|
-
truncateText,
|
|
21
|
-
toSlug,
|
|
22
|
-
capitalizeWords,
|
|
23
|
-
removeSpecialChars,
|
|
24
|
-
camelCase,
|
|
25
|
-
pascalCase,
|
|
26
|
-
snakeCase,
|
|
27
|
-
kebabCase,
|
|
28
|
-
titleCase,
|
|
29
|
-
constantCase,
|
|
30
|
-
removeWords,
|
|
31
|
-
initials,
|
|
32
|
-
removeDuplicates
|
|
33
|
-
} = transformations;
|
|
34
|
-
|
|
35
|
-
export const {
|
|
36
|
-
isURL,
|
|
37
|
-
isEmail,
|
|
38
|
-
isEmpty,
|
|
39
|
-
isDate,
|
|
40
|
-
} = validations;
|
|
41
|
-
|
|
42
|
-
export const {
|
|
43
|
-
wordCount,
|
|
44
|
-
characterCount,
|
|
45
|
-
characterFrequency
|
|
46
|
-
} = analysis;
|
|
47
|
-
|
|
48
|
-
export const {
|
|
49
|
-
capitalize,
|
|
50
|
-
formatNumber,
|
|
51
|
-
formatPhone
|
|
52
|
-
} = formatting;
|
|
53
|
-
|
|
54
|
-
export const transform = transformations;
|
|
55
|
-
export const validate = validations;
|
|
56
|
-
export const analyze = analysis;
|
|
57
|
-
export const format = formatting;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
export default {
|
|
61
|
-
...transformations,
|
|
62
|
-
...validations,
|
|
63
|
-
...analysis,
|
|
64
|
-
...formatting,
|
|
65
|
-
|
|
66
|
-
transform: transformations,
|
|
67
|
-
validate: validations,
|
|
68
|
-
analyze: analysis,
|
|
69
|
-
format: formatting,
|
|
70
|
-
|
|
71
|
-
transform,
|
|
72
|
-
validate,
|
|
73
|
-
analyze,
|
|
74
|
-
format,
|
|
75
|
-
};
|
package/transformations.js
DELETED
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
export function truncateText(text, maxLength, suffix = '...') {
|
|
2
|
-
if (typeof text !== 'string') {
|
|
3
|
-
throw new Error("Input text must be a string.");
|
|
4
|
-
}
|
|
5
|
-
if (typeof maxLength !== 'number' || maxLength < 0) {
|
|
6
|
-
throw new Error("maxLength must be a non-negative number.");
|
|
7
|
-
}
|
|
8
|
-
if (typeof suffix !== 'string') {
|
|
9
|
-
throw new Error("Suffix must be a string.");
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
if (text.length <= maxLength) {
|
|
13
|
-
return text;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const adjustedLength = maxLength - suffix.length;
|
|
17
|
-
return text.slice(0, adjustedLength > 0 ? adjustedLength : 0) + suffix;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
export function toSlug(text) {
|
|
22
|
-
if (typeof text !== "string") {
|
|
23
|
-
throw new Error("Invalid argument. Expected a string.");
|
|
24
|
-
}
|
|
25
|
-
return text
|
|
26
|
-
.toLowerCase()
|
|
27
|
-
.trim()
|
|
28
|
-
.replace(/[\s]+/g, "-")
|
|
29
|
-
.replace(/[^\w-]+/g, "");
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
export function capitalizeWords(text) {
|
|
34
|
-
if (typeof text !== "string") {
|
|
35
|
-
throw new Error("Invalid argument. Expected a string.");
|
|
36
|
-
}
|
|
37
|
-
return text.replace(/\b\w/g, (char) => char.toUpperCase());
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function removeSpecialChars(text, replacement = '') {
|
|
41
|
-
if (typeof text !== "string") {
|
|
42
|
-
throw new Error("Invalid argument. Expected a string.");
|
|
43
|
-
}
|
|
44
|
-
if (typeof replacement !== "string") {
|
|
45
|
-
throw new Error("Replacement must be a string.");
|
|
46
|
-
}
|
|
47
|
-
return text.replace(/[^\w\s]/gi, replacement);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
export function camelCase(text) {
|
|
52
|
-
if (text == null) return '';
|
|
53
|
-
|
|
54
|
-
return text
|
|
55
|
-
.trim()
|
|
56
|
-
.toLowerCase()
|
|
57
|
-
.replace(/[^\w\s]/g, ' ')
|
|
58
|
-
.replace(/_/g, ' ')
|
|
59
|
-
.replace(/\s+/g, ' ')
|
|
60
|
-
.replace(/\s(.)/g, (_, character) => character.toUpperCase())
|
|
61
|
-
.replace(/^(.)/, (_, character) => character.toLowerCase());
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
export function pascalCase(text) {
|
|
66
|
-
if (text == null) return '';
|
|
67
|
-
|
|
68
|
-
return text
|
|
69
|
-
.trim()
|
|
70
|
-
.toLowerCase()
|
|
71
|
-
.replace(/[^\w\s]/g, ' ')
|
|
72
|
-
.replace(/_/g, ' ')
|
|
73
|
-
.replace(/\s+/g, ' ')
|
|
74
|
-
.replace(/(^|\s)(.)/g, (_, prefix, character) => character.toUpperCase())
|
|
75
|
-
.replace(/\s/g, '');
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
export function snakeCase(text) {
|
|
80
|
-
if (text == null) return '';
|
|
81
|
-
|
|
82
|
-
return text
|
|
83
|
-
.trim()
|
|
84
|
-
.replace(/[\s-]+/g, '_')
|
|
85
|
-
.replace(/([a-z])([A-Z])/g, '$1_$2')
|
|
86
|
-
.replace(/[^\w_]/g, '_')
|
|
87
|
-
.toLowerCase()
|
|
88
|
-
.replace(/_+/g, '_')
|
|
89
|
-
.replace(/^_+|_+$/g, '');
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
export function kebabCase(text) {
|
|
94
|
-
if (text == null) return '';
|
|
95
|
-
|
|
96
|
-
return text
|
|
97
|
-
.trim()
|
|
98
|
-
.replace(/[\s_]+/g, '-')
|
|
99
|
-
.replace(/([a-z])([A-Z])/g, '$1-$2')
|
|
100
|
-
.replace(/[^\w-]/g, '-')
|
|
101
|
-
.toLowerCase()
|
|
102
|
-
.replace(/-+/g, '-')
|
|
103
|
-
.replace(/^-+|-+$/g, '');
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export function titleCase(text) {
|
|
107
|
-
if (text == null) return '';
|
|
108
|
-
|
|
109
|
-
return text
|
|
110
|
-
.trim()
|
|
111
|
-
.toLowerCase()
|
|
112
|
-
.replace(/([^\w\s]|_)/g, ' ')
|
|
113
|
-
.replace(/\s+/g, ' ')
|
|
114
|
-
.replace(/(^|\s)(.)/g, (_, prefix, character) => prefix + character.toUpperCase())
|
|
115
|
-
.replace(/\s/g, ' ');
|
|
116
|
-
}
|
|
117
|
-
export function constantCase(text) {
|
|
118
|
-
if (text == null) return '';
|
|
119
|
-
|
|
120
|
-
return text
|
|
121
|
-
.trim()
|
|
122
|
-
.replace(/[\s-]+/g, '_')
|
|
123
|
-
.replace(/([a-z])([A-Z])/g, '$1_$2')
|
|
124
|
-
.replace(/[^\w_]/g, '_')
|
|
125
|
-
.toUpperCase()
|
|
126
|
-
.replace(/_+/g, '_')
|
|
127
|
-
.replace(/^_+|_+$/g, '');
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export function removeWords(str, wordsToRemove) {
|
|
131
|
-
if (str === null || str === undefined) {
|
|
132
|
-
throw new Error('Input string cannot be null or undefined');
|
|
133
|
-
}
|
|
134
|
-
if (typeof str !== 'string') {
|
|
135
|
-
throw new Error('First parameter must be a string');
|
|
136
|
-
}
|
|
137
|
-
if (wordsToRemove === null || wordsToRemove === undefined) {
|
|
138
|
-
throw new Error('Words to remove cannot be null or undefined');
|
|
139
|
-
}
|
|
140
|
-
if (typeof wordsToRemove !== 'string' && !Array.isArray(wordsToRemove)) {
|
|
141
|
-
throw new Error('Second parameter must be a string or an array of strings');
|
|
142
|
-
}
|
|
143
|
-
if (str === '') {
|
|
144
|
-
return '';
|
|
145
|
-
}
|
|
146
|
-
const wordsArray = Array.isArray(wordsToRemove) ? wordsToRemove : [wordsToRemove];
|
|
147
|
-
const regex = new RegExp(`\\b(${wordsArray.join('|')})\\b`, 'gi');
|
|
148
|
-
return str.replace(regex, '').replace(/\s+/g, ' ').trim();
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
export function initials(text, limit) {
|
|
152
|
-
if (typeof text !== "string") {
|
|
153
|
-
throw new Error("Input must be a string");
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (limit !== undefined && (typeof limit !== "number" || isNaN(limit))) {
|
|
157
|
-
throw new Error("Limit must be a valid number");
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
if (limit < 0) {
|
|
161
|
-
throw new Error("Limit must be a non-negative number");
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
const words = text
|
|
165
|
-
.trim()
|
|
166
|
-
.split(/\s+/)
|
|
167
|
-
.filter((word) => word.length > 0);
|
|
168
|
-
|
|
169
|
-
if (words.length === 0) return "";
|
|
170
|
-
|
|
171
|
-
const initialsArray = words
|
|
172
|
-
.map((word) => word.charAt(0))
|
|
173
|
-
.slice(0, limit ?? words.length);
|
|
174
|
-
|
|
175
|
-
return initialsArray.join("");
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
export function removeDuplicates(text) {
|
|
179
|
-
if (typeof text !== "string") {
|
|
180
|
-
throw new Error("Input must be a string");
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
const wordSet = new Set();
|
|
184
|
-
|
|
185
|
-
text.split(" ").forEach((word) => {
|
|
186
|
-
wordSet.add(word);
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
return Array.from(wordSet).join(" ");
|
|
190
|
-
}
|
package/validations.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
export function isURL(str) {
|
|
2
|
-
try {
|
|
3
|
-
new URL(str);
|
|
4
|
-
return true;
|
|
5
|
-
} catch {
|
|
6
|
-
return false;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export function isEmail(str) {
|
|
12
|
-
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
13
|
-
return emailRegex.test(str);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export function isEmpty(str) {
|
|
18
|
-
return str.trim().length === 0;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
export function isDate(input) {
|
|
24
|
-
|
|
25
|
-
//console.log("True")
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (typeof input !== "string") return false;
|
|
30
|
-
|
|
31
|
-
const formats = [
|
|
32
|
-
{
|
|
33
|
-
// Format: YYYY-MM-DD
|
|
34
|
-
regex: /^\d{4}-\d{2}-\d{2}$/,
|
|
35
|
-
split: (s) => s.split("-").map(Number),
|
|
36
|
-
order: ["Y", "M", "D"],
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
// Format: MM-DD-YYYY
|
|
40
|
-
regex: /^\d{2}-\d{2}-\d{4}$/,
|
|
41
|
-
split: (s) => s.split("-").map(Number),
|
|
42
|
-
order: ["M", "D", "Y"],
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
// Format: DD-MM-YYYY
|
|
46
|
-
regex: /^\d{2}-\d{2}-\d{4}$/,
|
|
47
|
-
split: (s) => s.split("-").map(Number),
|
|
48
|
-
order: ["D", "M", "Y"],
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
// Format: DD/MM/YYYY
|
|
52
|
-
regex: /^\d{2}\/\d{2}\/\d{4}$/,
|
|
53
|
-
split: (s) => s.split("/").map(Number),
|
|
54
|
-
order: ["D", "M", "Y"],
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
// Format: YYYY/MM/DD
|
|
58
|
-
regex: /^\d{4}\/\d{2}\/\d{2}$/,
|
|
59
|
-
split: (s) => s.split("/").map(Number),
|
|
60
|
-
order: ["Y", "M", "D"],
|
|
61
|
-
},
|
|
62
|
-
];
|
|
63
|
-
|
|
64
|
-
for (const format of formats) {
|
|
65
|
-
if (format.regex.test(input)) {
|
|
66
|
-
const parts = format.split(input);
|
|
67
|
-
const dateParts = {};
|
|
68
|
-
format.order.forEach((key, i) => {
|
|
69
|
-
dateParts[key] = parts[i];
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
const { Y, M, D } = dateParts;
|
|
73
|
-
const date = new Date(Y, M - 1, D); // JS months are 0-indexed
|
|
74
|
-
return date.getFullYear() === Y && date.getMonth() === M -1 && date.getDate() === D;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
|