extra-utils 5.3.0 → 5.5.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/LICENSE +0 -0
- package/README.md +22 -2
- package/lib/array/index.d.ts +2 -2
- package/lib/array/index.js +2 -2
- package/lib/array/is-array.d.ts +2 -2
- package/lib/array/is-array.js +6 -6
- package/lib/array/is-empty-array.d.ts +3 -3
- package/lib/array/is-empty-array.js +6 -6
- package/lib/array-like/first.d.ts +1 -1
- package/lib/array-like/first.js +5 -5
- package/lib/array-like/index.d.ts +2 -2
- package/lib/array-like/index.js +2 -2
- package/lib/array-like/last.d.ts +1 -1
- package/lib/array-like/last.js +5 -5
- package/lib/boolean/index.d.ts +2 -2
- package/lib/boolean/index.js +2 -2
- package/lib/boolean/is-boolean.d.ts +2 -2
- package/lib/boolean/is-boolean.js +6 -6
- package/lib/boolean/is-falsy.d.ts +3 -3
- package/lib/boolean/is-falsy.js +6 -6
- package/lib/enum/enum-entries.d.ts +3 -0
- package/lib/enum/enum-entries.js +5 -0
- package/lib/enum/enum-entries.js.map +1 -0
- package/lib/enum/enum-keys.d.ts +1 -0
- package/lib/enum/enum-keys.js +5 -0
- package/lib/enum/enum-keys.js.map +1 -0
- package/lib/enum/enum-values.d.ts +1 -0
- package/lib/enum/enum-values.js +6 -0
- package/lib/enum/enum-values.js.map +1 -0
- package/lib/enum/in-enum.d.ts +2 -0
- package/lib/enum/in-enum.js +8 -0
- package/lib/enum/in-enum.js.map +1 -0
- package/lib/enum/index.d.ts +4 -0
- package/lib/enum/index.js +5 -0
- package/lib/enum/index.js.map +1 -0
- package/lib/index.d.ts +15 -15
- package/lib/index.js +15 -15
- package/lib/index.js.map +1 -1
- package/lib/is-date.d.ts +2 -2
- package/lib/is-date.js +6 -6
- package/lib/is-function.d.ts +2 -2
- package/lib/is-function.js +6 -6
- package/lib/is-regexp.d.ts +2 -2
- package/lib/is-regexp.js +6 -6
- package/lib/is-symbol.d.ts +2 -2
- package/lib/is-symbol.js +6 -6
- package/lib/json/index.d.ts +2 -2
- package/lib/json/index.js +2 -2
- package/lib/json/is-json-serializable.d.ts +3 -3
- package/lib/json/is-json-serializable.js +10 -10
- package/lib/json/is-json-value.d.ts +3 -3
- package/lib/json/is-json-value.js +17 -17
- package/lib/nullish/index.d.ts +3 -3
- package/lib/nullish/index.js +3 -3
- package/lib/nullish/is-null.d.ts +2 -2
- package/lib/nullish/is-null.js +6 -6
- package/lib/nullish/is-nullish.d.ts +3 -3
- package/lib/nullish/is-nullish.js +9 -9
- package/lib/nullish/is-undefined.d.ts +2 -2
- package/lib/nullish/is-undefined.js +6 -6
- package/lib/number/index.d.ts +5 -5
- package/lib/number/index.js +5 -5
- package/lib/number/is-bigint.d.ts +2 -2
- package/lib/number/is-bigint.js +6 -6
- package/lib/number/is-finite.d.ts +1 -1
- package/lib/number/is-finite.js +3 -3
- package/lib/number/is-infinity.d.ts +2 -2
- package/lib/number/is-infinity.js +6 -6
- package/lib/number/is-nan.d.ts +2 -2
- package/lib/number/is-nan.js +6 -6
- package/lib/number/is-number.d.ts +2 -2
- package/lib/number/is-number.js +6 -6
- package/lib/object/index.d.ts +6 -3
- package/lib/object/index.js +6 -3
- package/lib/object/index.js.map +1 -1
- package/lib/object/is-deep-equal.d.ts +1 -0
- package/lib/object/is-deep-equal.js +21 -0
- package/lib/object/is-deep-equal.js.map +1 -0
- package/lib/object/is-empty-object.d.ts +2 -2
- package/lib/object/is-empty-object.js +6 -6
- package/lib/object/is-object.d.ts +2 -2
- package/lib/object/is-object.js +7 -7
- package/lib/object/is-plain-object.d.ts +2 -2
- package/lib/object/is-plain-object.js +7 -7
- package/lib/object/is-reference-equal.d.ts +1 -0
- package/lib/object/is-reference-equal.js +4 -0
- package/lib/object/is-reference-equal.js.map +1 -0
- package/lib/object/is-shallow-equal.d.ts +1 -0
- package/lib/object/is-shallow-equal.js +21 -0
- package/lib/object/is-shallow-equal.js.map +1 -0
- package/lib/pipe-async.d.ts +44 -44
- package/lib/pipe-async.js +7 -7
- package/lib/pipe.d.ts +43 -43
- package/lib/pipe.js +7 -7
- package/lib/string/index.d.ts +8 -8
- package/lib/string/index.js +8 -8
- package/lib/string/is-char.d.ts +2 -2
- package/lib/string/is-char.js +8 -8
- package/lib/string/is-string.d.ts +2 -2
- package/lib/string/is-string.js +6 -6
- package/lib/string/is-url-string.d.ts +2 -2
- package/lib/string/is-url-string.js +12 -12
- package/lib/string/remove-blank-lines.d.ts +1 -1
- package/lib/string/remove-blank-lines.js +7 -7
- package/lib/string/remove-extra-indents.d.ts +3 -3
- package/lib/string/remove-extra-indents.js +20 -20
- package/lib/string/remove-leading-blank-lines.d.ts +1 -1
- package/lib/string/remove-leading-blank-lines.js +12 -12
- package/lib/string/remove-trailing-blank-lines.d.ts +1 -1
- package/lib/string/remove-trailing-blank-lines.js +12 -12
- package/lib/string/to-string.d.ts +1 -1
- package/lib/string/to-string.js +3 -3
- package/lib/string/utils.d.ts +2 -2
- package/lib/string/utils.js +6 -6
- package/package.json +1 -1
- package/src/enum/enum-entries.ts +7 -0
- package/src/enum/enum-keys.ts +6 -0
- package/src/enum/enum-values.ts +8 -0
- package/src/enum/in-enum.ts +16 -0
- package/src/enum/index.ts +4 -0
- package/src/index.ts +1 -1
- package/src/object/index.ts +3 -0
- package/src/object/is-deep-equal.ts +26 -0
- package/src/object/is-reference-equal.ts +3 -0
- package/src/object/is-shallow-equal.ts +26 -0
- package/CHANGELOG.md +0 -538
- package/lib/in-enum.d.ts +0 -2
- package/lib/in-enum.js +0 -7
- package/lib/in-enum.js.map +0 -1
- package/src/in-enum.ts +0 -10
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { isntBlankLine } from './utils.js';
|
|
2
|
-
export function removeBlankLines(text) {
|
|
3
|
-
return text
|
|
4
|
-
.split('\n')
|
|
5
|
-
.filter(line => isntBlankLine(line))
|
|
6
|
-
.join('\n');
|
|
7
|
-
}
|
|
1
|
+
import { isntBlankLine } from './utils.js';
|
|
2
|
+
export function removeBlankLines(text) {
|
|
3
|
+
return text
|
|
4
|
+
.split('\n')
|
|
5
|
+
.filter(line => isntBlankLine(line))
|
|
6
|
+
.join('\n');
|
|
7
|
+
}
|
|
8
8
|
//# sourceMappingURL=remove-blank-lines.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare function removeExtraIndents(text: string, { ignoreBlankLines }?: {
|
|
2
|
-
ignoreBlankLines?: boolean;
|
|
3
|
-
}): string;
|
|
1
|
+
export declare function removeExtraIndents(text: string, { ignoreBlankLines }?: {
|
|
2
|
+
ignoreBlankLines?: boolean;
|
|
3
|
+
}): string;
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { isntBlankLine } from './utils.js';
|
|
2
|
-
export function removeExtraIndents(text, { ignoreBlankLines = false } = {}) {
|
|
3
|
-
const lines = text.split('\n');
|
|
4
|
-
const commonIndentLength = lines
|
|
5
|
-
.filter(line => ignoreBlankLines ? isntBlankLine(line) : true)
|
|
6
|
-
.reduce((acc, cur) => {
|
|
7
|
-
const indent = cur.match(/^(\s+)/);
|
|
8
|
-
if (indent) {
|
|
9
|
-
return Math.min(acc, indent[1].length);
|
|
10
|
-
}
|
|
11
|
-
else {
|
|
12
|
-
return 0;
|
|
13
|
-
}
|
|
14
|
-
}, Infinity);
|
|
15
|
-
if (commonIndentLength === 0 || commonIndentLength === Infinity) {
|
|
16
|
-
return text;
|
|
17
|
-
}
|
|
18
|
-
const newLines = lines.map(x => x.slice(commonIndentLength));
|
|
19
|
-
return newLines.join('\n');
|
|
20
|
-
}
|
|
1
|
+
import { isntBlankLine } from './utils.js';
|
|
2
|
+
export function removeExtraIndents(text, { ignoreBlankLines = false } = {}) {
|
|
3
|
+
const lines = text.split('\n');
|
|
4
|
+
const commonIndentLength = lines
|
|
5
|
+
.filter(line => ignoreBlankLines ? isntBlankLine(line) : true)
|
|
6
|
+
.reduce((acc, cur) => {
|
|
7
|
+
const indent = cur.match(/^(\s+)/);
|
|
8
|
+
if (indent) {
|
|
9
|
+
return Math.min(acc, indent[1].length);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
return 0;
|
|
13
|
+
}
|
|
14
|
+
}, Infinity);
|
|
15
|
+
if (commonIndentLength === 0 || commonIndentLength === Infinity) {
|
|
16
|
+
return text;
|
|
17
|
+
}
|
|
18
|
+
const newLines = lines.map(x => x.slice(commonIndentLength));
|
|
19
|
+
return newLines.join('\n');
|
|
20
|
+
}
|
|
21
21
|
//# sourceMappingURL=remove-extra-indents.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function removeLeadingBlankLines(text: string, maxRemovals?: number): string;
|
|
1
|
+
export declare function removeLeadingBlankLines(text: string, maxRemovals?: number): string;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { isBlankLine } from './utils.js';
|
|
2
|
-
export function removeLeadingBlankLines(text, maxRemovals = Infinity) {
|
|
3
|
-
const lines = text.split('\n');
|
|
4
|
-
let removals = 0;
|
|
5
|
-
while (removals < maxRemovals &&
|
|
6
|
-
lines.length > 0 &&
|
|
7
|
-
isBlankLine(lines[0])) {
|
|
8
|
-
lines.shift();
|
|
9
|
-
removals++;
|
|
10
|
-
}
|
|
11
|
-
return lines.join('\n');
|
|
12
|
-
}
|
|
1
|
+
import { isBlankLine } from './utils.js';
|
|
2
|
+
export function removeLeadingBlankLines(text, maxRemovals = Infinity) {
|
|
3
|
+
const lines = text.split('\n');
|
|
4
|
+
let removals = 0;
|
|
5
|
+
while (removals < maxRemovals &&
|
|
6
|
+
lines.length > 0 &&
|
|
7
|
+
isBlankLine(lines[0])) {
|
|
8
|
+
lines.shift();
|
|
9
|
+
removals++;
|
|
10
|
+
}
|
|
11
|
+
return lines.join('\n');
|
|
12
|
+
}
|
|
13
13
|
//# sourceMappingURL=remove-leading-blank-lines.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function removeTrailingBlankLines(text: string, maxRemovals?: number): string;
|
|
1
|
+
export declare function removeTrailingBlankLines(text: string, maxRemovals?: number): string;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { isBlankLine } from './utils.js';
|
|
2
|
-
export function removeTrailingBlankLines(text, maxRemovals = Infinity) {
|
|
3
|
-
const lines = text.split('\n');
|
|
4
|
-
let removals = 0;
|
|
5
|
-
while (removals < maxRemovals &&
|
|
6
|
-
lines.length > 0 &&
|
|
7
|
-
isBlankLine(lines[lines.length - 1])) {
|
|
8
|
-
lines.pop();
|
|
9
|
-
removals++;
|
|
10
|
-
}
|
|
11
|
-
return lines.join('\n');
|
|
12
|
-
}
|
|
1
|
+
import { isBlankLine } from './utils.js';
|
|
2
|
+
export function removeTrailingBlankLines(text, maxRemovals = Infinity) {
|
|
3
|
+
const lines = text.split('\n');
|
|
4
|
+
let removals = 0;
|
|
5
|
+
while (removals < maxRemovals &&
|
|
6
|
+
lines.length > 0 &&
|
|
7
|
+
isBlankLine(lines[lines.length - 1])) {
|
|
8
|
+
lines.pop();
|
|
9
|
+
removals++;
|
|
10
|
+
}
|
|
11
|
+
return lines.join('\n');
|
|
12
|
+
}
|
|
13
13
|
//# sourceMappingURL=remove-trailing-blank-lines.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function toString(val: unknown): string;
|
|
1
|
+
export declare function toString(val: unknown): string;
|
package/lib/string/to-string.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export function toString(val) {
|
|
2
|
-
return `${val}`;
|
|
3
|
-
}
|
|
1
|
+
export function toString(val) {
|
|
2
|
+
return `${val}`;
|
|
3
|
+
}
|
|
4
4
|
//# sourceMappingURL=to-string.js.map
|
package/lib/string/utils.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function isBlankLine(line: string): boolean;
|
|
2
|
-
export declare function isntBlankLine(line: string): boolean;
|
|
1
|
+
export declare function isBlankLine(line: string): boolean;
|
|
2
|
+
export declare function isntBlankLine(line: string): boolean;
|
package/lib/string/utils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export function isBlankLine(line) {
|
|
2
|
-
return line.trim() === '';
|
|
3
|
-
}
|
|
4
|
-
export function isntBlankLine(line) {
|
|
5
|
-
return !isBlankLine(line);
|
|
6
|
-
}
|
|
1
|
+
export function isBlankLine(line) {
|
|
2
|
+
return line.trim() === '';
|
|
3
|
+
}
|
|
4
|
+
export function isntBlankLine(line) {
|
|
5
|
+
return !isBlankLine(line);
|
|
6
|
+
}
|
|
7
7
|
//# sourceMappingURL=utils.js.map
|
package/package.json
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { enumValues } from './enum-values.js'
|
|
2
|
+
|
|
3
|
+
export function inEnum<T extends Record<string | number, string | number>>(
|
|
4
|
+
val: string | number
|
|
5
|
+
, _enum: T
|
|
6
|
+
): val is T[keyof T] {
|
|
7
|
+
return enumValues(_enum).includes(val as T[keyof T])
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// 由于TypeScript无法从string | number里精确排除掉枚举类型, 因此返回值为boolean.
|
|
11
|
+
export function notInEnum(
|
|
12
|
+
val: string | number
|
|
13
|
+
, _enum: Record<string | number, string | number>
|
|
14
|
+
): boolean {
|
|
15
|
+
return !inEnum(val, _enum)
|
|
16
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ export * from './object/index.js'
|
|
|
6
6
|
export * from './json/index.js'
|
|
7
7
|
export * from './string/index.js'
|
|
8
8
|
export * from './nullish/index.js'
|
|
9
|
-
export * from './
|
|
9
|
+
export * from './enum/index.js'
|
|
10
10
|
export * from './is-regexp.js'
|
|
11
11
|
export * from './is-symbol.js'
|
|
12
12
|
export * from './is-date.js'
|
package/src/object/index.ts
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { isReferenceEqual } from './is-reference-equal.js'
|
|
2
|
+
import { isObject } from './is-object.js'
|
|
3
|
+
|
|
4
|
+
export function isDeepEqual(a: unknown, b: unknown): boolean {
|
|
5
|
+
if (isReferenceEqual(a, b)) return true
|
|
6
|
+
|
|
7
|
+
if (isObject(a) && isObject(b)) {
|
|
8
|
+
const keysA = Reflect.ownKeys(a)
|
|
9
|
+
const keysB = Reflect.ownKeys(b)
|
|
10
|
+
|
|
11
|
+
if (keysA.length === keysB.length) {
|
|
12
|
+
for (const key of keysA) {
|
|
13
|
+
if (
|
|
14
|
+
!Object.prototype.hasOwnProperty.call(b, key) ||
|
|
15
|
+
!isDeepEqual(a[key], b[key])
|
|
16
|
+
) {
|
|
17
|
+
return false
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return true
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return false
|
|
26
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { isReferenceEqual } from './is-reference-equal.js'
|
|
2
|
+
import { isObject } from './is-object.js'
|
|
3
|
+
|
|
4
|
+
export function isShallowEqual(a: unknown, b: unknown): boolean {
|
|
5
|
+
if (isReferenceEqual(a, b)) return true
|
|
6
|
+
|
|
7
|
+
if (isObject(a) && isObject(b)) {
|
|
8
|
+
const keysA = Reflect.ownKeys(a)
|
|
9
|
+
const keysB = Reflect.ownKeys(b)
|
|
10
|
+
|
|
11
|
+
if (keysA.length === keysB.length) {
|
|
12
|
+
for (const key of keysA) {
|
|
13
|
+
if (
|
|
14
|
+
!Object.prototype.hasOwnProperty.call(b, key) ||
|
|
15
|
+
a[key] !== b[key]
|
|
16
|
+
) {
|
|
17
|
+
return false
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return true
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return false
|
|
26
|
+
}
|