extra-utils 5.1.1 → 5.3.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 (104) hide show
  1. package/CHANGELOG.md +538 -0
  2. package/LICENSE +0 -0
  3. package/README.md +8 -0
  4. package/lib/array/index.d.ts +2 -2
  5. package/lib/array/index.js +2 -2
  6. package/lib/array/is-array.d.ts +2 -2
  7. package/lib/array/is-array.js +6 -6
  8. package/lib/array/is-empty-array.d.ts +3 -3
  9. package/lib/array/is-empty-array.js +6 -6
  10. package/lib/array-like/first.d.ts +1 -0
  11. package/lib/array-like/first.js +6 -0
  12. package/lib/array-like/first.js.map +1 -0
  13. package/lib/array-like/index.d.ts +2 -0
  14. package/lib/array-like/index.js +3 -0
  15. package/lib/array-like/index.js.map +1 -0
  16. package/lib/array-like/last.d.ts +1 -0
  17. package/lib/array-like/last.js +6 -0
  18. package/lib/array-like/last.js.map +1 -0
  19. package/lib/boolean/index.d.ts +2 -2
  20. package/lib/boolean/index.js +2 -2
  21. package/lib/boolean/is-boolean.d.ts +2 -2
  22. package/lib/boolean/is-boolean.js +6 -6
  23. package/lib/boolean/is-falsy.d.ts +3 -3
  24. package/lib/boolean/is-falsy.js +6 -6
  25. package/lib/in-enum.d.ts +2 -2
  26. package/lib/in-enum.js +6 -6
  27. package/lib/index.d.ts +15 -14
  28. package/lib/index.js +15 -14
  29. package/lib/index.js.map +1 -1
  30. package/lib/is-date.d.ts +2 -2
  31. package/lib/is-date.js +6 -6
  32. package/lib/is-function.d.ts +2 -2
  33. package/lib/is-function.js +6 -6
  34. package/lib/is-regexp.d.ts +2 -2
  35. package/lib/is-regexp.js +6 -6
  36. package/lib/is-symbol.d.ts +2 -2
  37. package/lib/is-symbol.js +6 -6
  38. package/lib/json/index.d.ts +2 -2
  39. package/lib/json/index.js +2 -2
  40. package/lib/json/is-json-serializable.d.ts +3 -3
  41. package/lib/json/is-json-serializable.js +10 -10
  42. package/lib/json/is-json-value.d.ts +3 -3
  43. package/lib/json/is-json-value.js +17 -17
  44. package/lib/nullish/index.d.ts +3 -3
  45. package/lib/nullish/index.js +3 -3
  46. package/lib/nullish/is-null.d.ts +2 -2
  47. package/lib/nullish/is-null.js +6 -6
  48. package/lib/nullish/is-nullish.d.ts +3 -3
  49. package/lib/nullish/is-nullish.js +9 -9
  50. package/lib/nullish/is-undefined.d.ts +2 -2
  51. package/lib/nullish/is-undefined.js +6 -6
  52. package/lib/number/index.d.ts +5 -5
  53. package/lib/number/index.js +5 -5
  54. package/lib/number/is-bigint.d.ts +2 -2
  55. package/lib/number/is-bigint.js +6 -6
  56. package/lib/number/is-finite.d.ts +1 -1
  57. package/lib/number/is-finite.js +3 -3
  58. package/lib/number/is-infinity.d.ts +2 -2
  59. package/lib/number/is-infinity.js +6 -6
  60. package/lib/number/is-nan.d.ts +2 -2
  61. package/lib/number/is-nan.js +6 -6
  62. package/lib/number/is-number.d.ts +2 -2
  63. package/lib/number/is-number.js +6 -6
  64. package/lib/object/index.d.ts +3 -3
  65. package/lib/object/index.js +3 -3
  66. package/lib/object/is-empty-object.d.ts +2 -2
  67. package/lib/object/is-empty-object.js +6 -6
  68. package/lib/object/is-object.d.ts +2 -2
  69. package/lib/object/is-object.js +7 -7
  70. package/lib/object/is-plain-object.d.ts +2 -2
  71. package/lib/object/is-plain-object.js +7 -7
  72. package/lib/pipe-async.d.ts +44 -44
  73. package/lib/pipe-async.js +7 -7
  74. package/lib/pipe.d.ts +43 -43
  75. package/lib/pipe.js +7 -7
  76. package/lib/string/index.d.ts +8 -7
  77. package/lib/string/index.js +8 -7
  78. package/lib/string/index.js.map +1 -1
  79. package/lib/string/is-char.d.ts +2 -2
  80. package/lib/string/is-char.js +8 -8
  81. package/lib/string/is-string.d.ts +2 -2
  82. package/lib/string/is-string.js +6 -6
  83. package/lib/string/is-url-string.d.ts +2 -2
  84. package/lib/string/is-url-string.js +12 -12
  85. package/lib/string/remove-blank-lines.d.ts +1 -1
  86. package/lib/string/remove-blank-lines.js +7 -7
  87. package/lib/string/remove-extra-indents.d.ts +3 -3
  88. package/lib/string/remove-extra-indents.js +20 -20
  89. package/lib/string/remove-leading-blank-lines.d.ts +1 -1
  90. package/lib/string/remove-leading-blank-lines.js +12 -12
  91. package/lib/string/remove-trailing-blank-lines.d.ts +1 -1
  92. package/lib/string/remove-trailing-blank-lines.js +12 -12
  93. package/lib/string/to-string.d.ts +1 -0
  94. package/lib/string/to-string.js +4 -0
  95. package/lib/string/to-string.js.map +1 -0
  96. package/lib/string/utils.d.ts +2 -2
  97. package/lib/string/utils.js +6 -6
  98. package/package.json +14 -14
  99. package/src/array-like/first.ts +5 -0
  100. package/src/array-like/index.ts +2 -0
  101. package/src/array-like/last.ts +5 -0
  102. package/src/index.ts +1 -0
  103. package/src/string/index.ts +1 -0
  104. package/src/string/to-string.ts +3 -0
@@ -1,44 +1,44 @@
1
- import { Awaitable } from 'justypes';
2
- export declare function pipeAsync<A, B, C, D, E, F, G, H>(value: Awaitable<A>, ...operators: [
3
- (value: A) => Awaitable<B>,
4
- (value: B) => Awaitable<C>,
5
- (value: C) => Awaitable<D>,
6
- (value: D) => Awaitable<E>,
7
- (value: E) => Awaitable<F>,
8
- (value: F) => Awaitable<G>,
9
- (value: G) => Awaitable<H>
10
- ]): Promise<H>;
11
- export declare function pipeAsync<A, B, C, D, E, F, G>(value: Awaitable<A>, ...operators: [
12
- (value: A) => Awaitable<B>,
13
- (value: B) => Awaitable<C>,
14
- (value: C) => Awaitable<D>,
15
- (value: D) => Awaitable<E>,
16
- (value: E) => Awaitable<F>,
17
- (value: F) => Awaitable<G>
18
- ]): Promise<G>;
19
- export declare function pipeAsync<A, B, C, D, E, F>(value: Awaitable<A>, ...operators: [
20
- (value: A) => Awaitable<B>,
21
- (value: B) => Awaitable<C>,
22
- (value: C) => Awaitable<D>,
23
- (value: D) => Awaitable<E>,
24
- (value: E) => Awaitable<F>
25
- ]): Promise<F>;
26
- export declare function pipeAsync<A, B, C, D, E>(value: Awaitable<A>, ...operators: [
27
- (value: A) => Awaitable<B>,
28
- (value: B) => Awaitable<C>,
29
- (value: C) => Awaitable<D>,
30
- (value: D) => Awaitable<E>
31
- ]): Promise<E>;
32
- export declare function pipeAsync<A, B, C, D>(value: Awaitable<A>, ...operators: [
33
- (value: A) => Awaitable<B>,
34
- (value: B) => Awaitable<C>,
35
- (value: C) => Awaitable<D>
36
- ]): Promise<D>;
37
- export declare function pipeAsync<A, B, C>(value: Awaitable<A>, ...operators: [
38
- (value: A) => Awaitable<B>,
39
- (value: B) => Awaitable<C>
40
- ]): Promise<C>;
41
- export declare function pipeAsync<A, B>(value: Awaitable<A>, ...operators: [
42
- (value: A) => Awaitable<B>
43
- ]): Promise<B>;
44
- export declare function pipeAsync<T, U>(value: Awaitable<T>, ...operators: Array<(value: any) => Awaitable<unknown>>): Promise<U>;
1
+ import { Awaitable } from 'justypes';
2
+ export declare function pipeAsync<A, B, C, D, E, F, G, H>(value: Awaitable<A>, ...operators: [
3
+ (value: A) => Awaitable<B>,
4
+ (value: B) => Awaitable<C>,
5
+ (value: C) => Awaitable<D>,
6
+ (value: D) => Awaitable<E>,
7
+ (value: E) => Awaitable<F>,
8
+ (value: F) => Awaitable<G>,
9
+ (value: G) => Awaitable<H>
10
+ ]): Promise<H>;
11
+ export declare function pipeAsync<A, B, C, D, E, F, G>(value: Awaitable<A>, ...operators: [
12
+ (value: A) => Awaitable<B>,
13
+ (value: B) => Awaitable<C>,
14
+ (value: C) => Awaitable<D>,
15
+ (value: D) => Awaitable<E>,
16
+ (value: E) => Awaitable<F>,
17
+ (value: F) => Awaitable<G>
18
+ ]): Promise<G>;
19
+ export declare function pipeAsync<A, B, C, D, E, F>(value: Awaitable<A>, ...operators: [
20
+ (value: A) => Awaitable<B>,
21
+ (value: B) => Awaitable<C>,
22
+ (value: C) => Awaitable<D>,
23
+ (value: D) => Awaitable<E>,
24
+ (value: E) => Awaitable<F>
25
+ ]): Promise<F>;
26
+ export declare function pipeAsync<A, B, C, D, E>(value: Awaitable<A>, ...operators: [
27
+ (value: A) => Awaitable<B>,
28
+ (value: B) => Awaitable<C>,
29
+ (value: C) => Awaitable<D>,
30
+ (value: D) => Awaitable<E>
31
+ ]): Promise<E>;
32
+ export declare function pipeAsync<A, B, C, D>(value: Awaitable<A>, ...operators: [
33
+ (value: A) => Awaitable<B>,
34
+ (value: B) => Awaitable<C>,
35
+ (value: C) => Awaitable<D>
36
+ ]): Promise<D>;
37
+ export declare function pipeAsync<A, B, C>(value: Awaitable<A>, ...operators: [
38
+ (value: A) => Awaitable<B>,
39
+ (value: B) => Awaitable<C>
40
+ ]): Promise<C>;
41
+ export declare function pipeAsync<A, B>(value: Awaitable<A>, ...operators: [
42
+ (value: A) => Awaitable<B>
43
+ ]): Promise<B>;
44
+ export declare function pipeAsync<T, U>(value: Awaitable<T>, ...operators: Array<(value: any) => Awaitable<unknown>>): Promise<U>;
package/lib/pipe-async.js CHANGED
@@ -1,8 +1,8 @@
1
- export async function pipeAsync(value, ...operators) {
2
- let result = await value;
3
- for (const operator of operators) {
4
- result = await operator(result);
5
- }
6
- return result;
7
- }
1
+ export async function pipeAsync(value, ...operators) {
2
+ let result = await value;
3
+ for (const operator of operators) {
4
+ result = await operator(result);
5
+ }
6
+ return result;
7
+ }
8
8
  //# sourceMappingURL=pipe-async.js.map
package/lib/pipe.d.ts CHANGED
@@ -1,43 +1,43 @@
1
- export declare function pipe<A, B, C, D, E, F, G, H>(value: A, ...operators: [
2
- (value: A) => B,
3
- (value: B) => C,
4
- (value: C) => D,
5
- (value: D) => E,
6
- (value: E) => F,
7
- (value: F) => G,
8
- (value: G) => H
9
- ]): H;
10
- export declare function pipe<A, B, C, D, E, F, G>(value: A, ...operators: [
11
- (value: A) => B,
12
- (value: B) => C,
13
- (value: C) => D,
14
- (value: D) => E,
15
- (value: E) => F,
16
- (value: F) => G
17
- ]): G;
18
- export declare function pipe<A, B, C, D, E, F>(value: A, ...operators: [
19
- (value: A) => B,
20
- (value: B) => C,
21
- (value: C) => D,
22
- (value: D) => E,
23
- (value: E) => F
24
- ]): F;
25
- export declare function pipe<A, B, C, D, E>(value: A, ...operators: [
26
- (value: A) => B,
27
- (value: B) => C,
28
- (value: C) => D,
29
- (value: D) => E
30
- ]): E;
31
- export declare function pipe<A, B, C, D>(value: A, ...operators: [
32
- (value: A) => B,
33
- (value: B) => C,
34
- (value: C) => D
35
- ]): D;
36
- export declare function pipe<A, B, C>(value: A, ...operators: [
37
- (value: A) => B,
38
- (value: B) => C
39
- ]): C;
40
- export declare function pipe<A, B>(value: A, ...operators: [
41
- (value: A) => B
42
- ]): B;
43
- export declare function pipe<T, U>(value: T, ...operators: Array<(value: any) => unknown>): U;
1
+ export declare function pipe<A, B, C, D, E, F, G, H>(value: A, ...operators: [
2
+ (value: A) => B,
3
+ (value: B) => C,
4
+ (value: C) => D,
5
+ (value: D) => E,
6
+ (value: E) => F,
7
+ (value: F) => G,
8
+ (value: G) => H
9
+ ]): H;
10
+ export declare function pipe<A, B, C, D, E, F, G>(value: A, ...operators: [
11
+ (value: A) => B,
12
+ (value: B) => C,
13
+ (value: C) => D,
14
+ (value: D) => E,
15
+ (value: E) => F,
16
+ (value: F) => G
17
+ ]): G;
18
+ export declare function pipe<A, B, C, D, E, F>(value: A, ...operators: [
19
+ (value: A) => B,
20
+ (value: B) => C,
21
+ (value: C) => D,
22
+ (value: D) => E,
23
+ (value: E) => F
24
+ ]): F;
25
+ export declare function pipe<A, B, C, D, E>(value: A, ...operators: [
26
+ (value: A) => B,
27
+ (value: B) => C,
28
+ (value: C) => D,
29
+ (value: D) => E
30
+ ]): E;
31
+ export declare function pipe<A, B, C, D>(value: A, ...operators: [
32
+ (value: A) => B,
33
+ (value: B) => C,
34
+ (value: C) => D
35
+ ]): D;
36
+ export declare function pipe<A, B, C>(value: A, ...operators: [
37
+ (value: A) => B,
38
+ (value: B) => C
39
+ ]): C;
40
+ export declare function pipe<A, B>(value: A, ...operators: [
41
+ (value: A) => B
42
+ ]): B;
43
+ export declare function pipe<T, U>(value: T, ...operators: Array<(value: any) => unknown>): U;
package/lib/pipe.js CHANGED
@@ -1,8 +1,8 @@
1
- export function pipe(value, ...operators) {
2
- let result = value;
3
- for (const operator of operators) {
4
- result = operator(result);
5
- }
6
- return result;
7
- }
1
+ export function pipe(value, ...operators) {
2
+ let result = value;
3
+ for (const operator of operators) {
4
+ result = operator(result);
5
+ }
6
+ return result;
7
+ }
8
8
  //# sourceMappingURL=pipe.js.map
@@ -1,7 +1,8 @@
1
- export * from './is-char.js';
2
- export * from './is-string.js';
3
- export * from './is-url-string.js';
4
- export * from './remove-blank-lines.js';
5
- export * from './remove-extra-indents.js';
6
- export * from './remove-leading-blank-lines.js';
7
- export * from './remove-trailing-blank-lines.js';
1
+ export * from './is-char.js';
2
+ export * from './is-string.js';
3
+ export * from './is-url-string.js';
4
+ export * from './remove-blank-lines.js';
5
+ export * from './remove-extra-indents.js';
6
+ export * from './remove-leading-blank-lines.js';
7
+ export * from './remove-trailing-blank-lines.js';
8
+ export * from './to-string.js';
@@ -1,8 +1,9 @@
1
- export * from './is-char.js';
2
- export * from './is-string.js';
3
- export * from './is-url-string.js';
4
- export * from './remove-blank-lines.js';
5
- export * from './remove-extra-indents.js';
6
- export * from './remove-leading-blank-lines.js';
7
- export * from './remove-trailing-blank-lines.js';
1
+ export * from './is-char.js';
2
+ export * from './is-string.js';
3
+ export * from './is-url-string.js';
4
+ export * from './remove-blank-lines.js';
5
+ export * from './remove-extra-indents.js';
6
+ export * from './remove-leading-blank-lines.js';
7
+ export * from './remove-trailing-blank-lines.js';
8
+ export * from './to-string.js';
8
9
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/string/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,oBAAoB,CAAA;AAClC,cAAc,yBAAyB,CAAA;AACvC,cAAc,2BAA2B,CAAA;AACzC,cAAc,iCAAiC,CAAA;AAC/C,cAAc,kCAAkC,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/string/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,oBAAoB,CAAA;AAClC,cAAc,yBAAyB,CAAA;AACvC,cAAc,2BAA2B,CAAA;AACzC,cAAc,iCAAiC,CAAA;AAC/C,cAAc,kCAAkC,CAAA;AAChD,cAAc,gBAAgB,CAAA"}
@@ -1,2 +1,2 @@
1
- export declare function isChar(val: unknown): val is string;
2
- export declare function isntChar(val: unknown): boolean;
1
+ export declare function isChar(val: unknown): val is string;
2
+ export declare function isntChar(val: unknown): boolean;
@@ -1,9 +1,9 @@
1
- import { isString } from './is-string.js';
2
- export function isChar(val) {
3
- return isString(val)
4
- && val.length === 1;
5
- }
6
- export function isntChar(val) {
7
- return !isChar(val);
8
- }
1
+ import { isString } from './is-string.js';
2
+ export function isChar(val) {
3
+ return isString(val)
4
+ && val.length === 1;
5
+ }
6
+ export function isntChar(val) {
7
+ return !isChar(val);
8
+ }
9
9
  //# sourceMappingURL=is-char.js.map
@@ -1,2 +1,2 @@
1
- export declare function isString(val: unknown): val is string;
2
- export declare function isntString<T>(val: T): val is Exclude<T, string>;
1
+ export declare function isString(val: unknown): val is string;
2
+ export declare function isntString<T>(val: T): val is Exclude<T, string>;
@@ -1,7 +1,7 @@
1
- export function isString(val) {
2
- return typeof val === 'string';
3
- }
4
- export function isntString(val) {
5
- return !isString(val);
6
- }
1
+ export function isString(val) {
2
+ return typeof val === 'string';
3
+ }
4
+ export function isntString(val) {
5
+ return !isString(val);
6
+ }
7
7
  //# sourceMappingURL=is-string.js.map
@@ -1,2 +1,2 @@
1
- export declare function isURLString(text: string): boolean;
2
- export declare function isntURLString(text: string): boolean;
1
+ export declare function isURLString(text: string): boolean;
2
+ export declare function isntURLString(text: string): boolean;
@@ -1,13 +1,13 @@
1
- export function isURLString(text) {
2
- try {
3
- new URL(text);
4
- return true;
5
- }
6
- catch (_a) {
7
- return false;
8
- }
9
- }
10
- export function isntURLString(text) {
11
- return !isURLString(text);
12
- }
1
+ export function isURLString(text) {
2
+ try {
3
+ new URL(text);
4
+ return true;
5
+ }
6
+ catch (_a) {
7
+ return false;
8
+ }
9
+ }
10
+ export function isntURLString(text) {
11
+ return !isURLString(text);
12
+ }
13
13
  //# sourceMappingURL=is-url-string.js.map
@@ -1 +1 @@
1
- export declare function removeBlankLines(text: string): string;
1
+ export declare function removeBlankLines(text: string): string;
@@ -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
@@ -0,0 +1 @@
1
+ export declare function toString(val: unknown): string;
@@ -0,0 +1,4 @@
1
+ export function toString(val) {
2
+ return `${val}`;
3
+ }
4
+ //# sourceMappingURL=to-string.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to-string.js","sourceRoot":"","sources":["../../src/string/to-string.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,QAAQ,CAAC,GAAY;IACnC,OAAO,GAAG,GAAG,EAAE,CAAA;AACjB,CAAC"}
@@ -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;
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "extra-utils",
3
- "version": "5.1.1",
3
+ "version": "5.3.0",
4
4
  "description": "Utilities for JavaScript and Typescript",
5
5
  "files": [
6
6
  "src",
@@ -36,30 +36,30 @@
36
36
  "devDependencies": {
37
37
  "@blackglory/jest-resolver": "^0.3.0",
38
38
  "@blackglory/pass": "^1.1.0",
39
- "@commitlint/cli": "^17.4.4",
40
- "@commitlint/config-conventional": "^17.4.4",
41
- "@types/jest": "^29.4.0",
42
- "@types/jsdom": "^21.1.0",
43
- "@types/lodash-es": "^4.17.6",
44
- "@typescript-eslint/eslint-plugin": "^5.52.0",
45
- "@typescript-eslint/parser": "^5.52.0",
39
+ "@commitlint/cli": "^17.6.1",
40
+ "@commitlint/config-conventional": "^17.6.1",
41
+ "@types/jest": "^29.5.0",
42
+ "@types/jsdom": "^21.1.1",
43
+ "@types/lodash-es": "^4.17.7",
44
+ "@typescript-eslint/eslint-plugin": "^5.58.0",
45
+ "@typescript-eslint/parser": "^5.58.0",
46
46
  "cross-env": "^7.0.3",
47
- "eslint": "^8.34.0",
47
+ "eslint": "^8.38.0",
48
48
  "husky": "^4.3.8",
49
- "jest": "^29.4.3",
50
- "jest-resolve": "^29.4.3",
49
+ "jest": "^29.5.0",
50
+ "jest-resolve": "^29.5.0",
51
51
  "npm-run-all": "^4.1.5",
52
52
  "rimraf": "^3.0.2",
53
53
  "standard-version": "^9.5.0",
54
- "ts-jest": "^29.0.5",
54
+ "ts-jest": "^29.1.0",
55
55
  "ts-patch": "^2.1.0",
56
- "tsd": "^0.25.0",
56
+ "tsd": "^0.28.1",
57
57
  "tslib": "^2.5.0",
58
58
  "typescript": "4.8",
59
59
  "typescript-transform-paths": "^3.4.6"
60
60
  },
61
61
  "dependencies": {
62
- "justypes": "^4.1.0",
62
+ "justypes": "^4.2.0",
63
63
  "lodash-es": "^4.17.21"
64
64
  }
65
65
  }
@@ -0,0 +1,5 @@
1
+ export function first<T>(arr: ArrayLike<T>): T | undefined {
2
+ return arr.length
3
+ ? arr[0]
4
+ : undefined
5
+ }
@@ -0,0 +1,2 @@
1
+ export * from './first.js'
2
+ export * from './last.js'
@@ -0,0 +1,5 @@
1
+ export function last<T>(arr: ArrayLike<T>): T | undefined {
2
+ return arr.length
3
+ ? arr[arr.length - 1]
4
+ : undefined
5
+ }
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './array-like/index.js'
1
2
  export * from './array/index.js'
2
3
  export * from './boolean/index.js'
3
4
  export * from './number/index.js'
@@ -5,3 +5,4 @@ export * from './remove-blank-lines.js'
5
5
  export * from './remove-extra-indents.js'
6
6
  export * from './remove-leading-blank-lines.js'
7
7
  export * from './remove-trailing-blank-lines.js'
8
+ export * from './to-string.js'
@@ -0,0 +1,3 @@
1
+ export function toString(val: unknown): string {
2
+ return `${val}`
3
+ }