@ntnyq/utils 0.4.0 → 0.4.2

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/README.md CHANGED
@@ -10,18 +10,22 @@
10
10
 
11
11
  ## Install
12
12
 
13
- ```bash
13
+ ```shell
14
14
  npm install @ntnyq/utils
15
15
  ```
16
16
 
17
- ```bash
17
+ ```shell
18
18
  yarn add @ntnyq/utils
19
19
  ```
20
20
 
21
- ```bash
21
+ ```shell
22
22
  pnpm add @ntnyq/utils
23
23
  ```
24
24
 
25
+ ## Credits
26
+
27
+ - [antfu/utils](https://github.com/antfu/utils)
28
+
25
29
  ## License
26
30
 
27
31
  [MIT](./LICENSE) License © 2024-PRESENT [ntnyq](https://github.com/ntnyq)
package/dist/index.cjs CHANGED
@@ -18,8 +18,8 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
20
  // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
23
  NOOP: () => NOOP,
24
24
  at: () => at,
25
25
  cAF: () => cAF,
@@ -94,7 +94,7 @@ __export(src_exports, {
94
94
  warnOnce: () => warnOnce,
95
95
  weeks: () => weeks
96
96
  });
97
- module.exports = __toCommonJS(src_exports);
97
+ module.exports = __toCommonJS(index_exports);
98
98
 
99
99
  // src/is/isDeepEqual.ts
100
100
  function isDeepEqual(value1, value2) {
@@ -406,10 +406,10 @@ function unindent(input) {
406
406
  const lines = (typeof input === "string" ? input : input[0]).split("\n");
407
407
  const whitespaceLines = lines.map((line) => _RE_FULL_WS.test(line));
408
408
  const commonIndent = lines.reduce((min, line, idx) => {
409
- if (!whitespaceLines[idx]) {
409
+ if (whitespaceLines[idx]) {
410
410
  return min;
411
411
  }
412
- const indent = line.match(/^\s/)?.[0].length;
412
+ const indent = line.match(/^\s*/)?.[0].length;
413
413
  return indent === void 0 ? min : Math.min(min, indent);
414
414
  }, Number.POSITIVE_INFINITY);
415
415
  let emptylinesHead = 0;
package/dist/index.d.cts CHANGED
@@ -174,6 +174,18 @@ declare function unique<T>(array: T[]): T[];
174
174
  */
175
175
  declare function uniqueBy<T>(array: T[], equalFn: (a: T, b: T) => boolean): T[];
176
176
 
177
+ type JsonArray = JsonValue[] | readonly JsonValue[];
178
+ type JsonObject = {
179
+ [Key in string]: JsonValue;
180
+ } & {
181
+ [Key in string]?: JsonValue | undefined;
182
+ };
183
+ type JsonPrimitive = boolean | number | string | null;
184
+ /**
185
+ * @copyright {@link https://github.com/sindresorhus/type-fest/blob/main/source/basic.d.ts}
186
+ */
187
+ type JsonValue = JsonArray | JsonObject | JsonPrimitive;
188
+
177
189
  /**
178
190
  * interop module
179
191
  */
@@ -184,6 +196,7 @@ type InteropModuleDefault<T> = T extends {
184
196
  type AnyFn<T = any, R = any> = (...args: T[]) => R;
185
197
  type Arrayable<T> = T | T[];
186
198
  type Awaitable<T> = Promise<T> | T;
199
+ type Callable<T> = AnyFn<any, T> | T;
187
200
  type MayBe<T> = T | undefined;
188
201
  type Nullable<T> = T | null;
189
202
  type PrimitiveType = bigint | boolean | number | string | symbol | null | undefined;
@@ -246,7 +259,7 @@ declare function join(array: JoinableValue[], options?: JoinOptions): string;
246
259
  declare function slash(input: string): string;
247
260
 
248
261
  /**
249
- * Remove leading whitespace from a template string
262
+ * Remove common leading whitespace from a template string
250
263
  * Empty lines at the beginning and end of the template string are also removed.
251
264
  * @param input - template string
252
265
  *
@@ -362,4 +375,4 @@ declare function sortObject<T extends Record<string, any>>(obj: T, options?: Sor
362
375
  */
363
376
  declare const capitalize: typeof upperFirst;
364
377
 
365
- export { type AnyFn, type Arrayable, type Awaitable, type CleanObjectOptions, type InteropModuleDefault, type MayBe, NOOP, type NonEmptyString, type Nullable, type Overwrite, type Prettify, type PrettifyV2, type PrimitiveType, type ResolvedOptions, type SortObjectOptions, type ThrottleDebounceOptions, type Whitespace, at, cAF, capitalize, chunk, clamp, cleanObject, days, debounce, ensurePrefix, ensureSuffix, escapeHtml, flattenArrayable, getObjectType, hasOwn, hours, isArray, isArrayEqual, isBoolean, isBrowser, isDeepEqual, isEmptyArray, isEmptyObject, isEmptyString, isEmptyStringOrWhitespace, isFunction, isInteger, isNaN, isNativePromise, isNil, isNonEmptyString, isNull, isNumber, isNumbericString, isObject, isPromise, isRegExp, isSet, isString, isUndefined, isWhitespaceString, isZero, join, last, mergeArrayable, minutes, noop, omit, once, pick, rAF, seconds, slash, sortObject, throttle, toArray, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
378
+ export { type AnyFn, type Arrayable, type Awaitable, type Callable, type CleanObjectOptions, type InteropModuleDefault, type JsonArray, type JsonObject, type JsonPrimitive, type JsonValue, type MayBe, NOOP, type NonEmptyString, type Nullable, type Overwrite, type Prettify, type PrettifyV2, type PrimitiveType, type ResolvedOptions, type SortObjectOptions, type ThrottleDebounceOptions, type Whitespace, at, cAF, capitalize, chunk, clamp, cleanObject, days, debounce, ensurePrefix, ensureSuffix, escapeHtml, flattenArrayable, getObjectType, hasOwn, hours, isArray, isArrayEqual, isBoolean, isBrowser, isDeepEqual, isEmptyArray, isEmptyObject, isEmptyString, isEmptyStringOrWhitespace, isFunction, isInteger, isNaN, isNativePromise, isNil, isNonEmptyString, isNull, isNumber, isNumbericString, isObject, isPromise, isRegExp, isSet, isString, isUndefined, isWhitespaceString, isZero, join, last, mergeArrayable, minutes, noop, omit, once, pick, rAF, seconds, slash, sortObject, throttle, toArray, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
package/dist/index.d.ts CHANGED
@@ -174,6 +174,18 @@ declare function unique<T>(array: T[]): T[];
174
174
  */
175
175
  declare function uniqueBy<T>(array: T[], equalFn: (a: T, b: T) => boolean): T[];
176
176
 
177
+ type JsonArray = JsonValue[] | readonly JsonValue[];
178
+ type JsonObject = {
179
+ [Key in string]: JsonValue;
180
+ } & {
181
+ [Key in string]?: JsonValue | undefined;
182
+ };
183
+ type JsonPrimitive = boolean | number | string | null;
184
+ /**
185
+ * @copyright {@link https://github.com/sindresorhus/type-fest/blob/main/source/basic.d.ts}
186
+ */
187
+ type JsonValue = JsonArray | JsonObject | JsonPrimitive;
188
+
177
189
  /**
178
190
  * interop module
179
191
  */
@@ -184,6 +196,7 @@ type InteropModuleDefault<T> = T extends {
184
196
  type AnyFn<T = any, R = any> = (...args: T[]) => R;
185
197
  type Arrayable<T> = T | T[];
186
198
  type Awaitable<T> = Promise<T> | T;
199
+ type Callable<T> = AnyFn<any, T> | T;
187
200
  type MayBe<T> = T | undefined;
188
201
  type Nullable<T> = T | null;
189
202
  type PrimitiveType = bigint | boolean | number | string | symbol | null | undefined;
@@ -246,7 +259,7 @@ declare function join(array: JoinableValue[], options?: JoinOptions): string;
246
259
  declare function slash(input: string): string;
247
260
 
248
261
  /**
249
- * Remove leading whitespace from a template string
262
+ * Remove common leading whitespace from a template string
250
263
  * Empty lines at the beginning and end of the template string are also removed.
251
264
  * @param input - template string
252
265
  *
@@ -362,4 +375,4 @@ declare function sortObject<T extends Record<string, any>>(obj: T, options?: Sor
362
375
  */
363
376
  declare const capitalize: typeof upperFirst;
364
377
 
365
- export { type AnyFn, type Arrayable, type Awaitable, type CleanObjectOptions, type InteropModuleDefault, type MayBe, NOOP, type NonEmptyString, type Nullable, type Overwrite, type Prettify, type PrettifyV2, type PrimitiveType, type ResolvedOptions, type SortObjectOptions, type ThrottleDebounceOptions, type Whitespace, at, cAF, capitalize, chunk, clamp, cleanObject, days, debounce, ensurePrefix, ensureSuffix, escapeHtml, flattenArrayable, getObjectType, hasOwn, hours, isArray, isArrayEqual, isBoolean, isBrowser, isDeepEqual, isEmptyArray, isEmptyObject, isEmptyString, isEmptyStringOrWhitespace, isFunction, isInteger, isNaN, isNativePromise, isNil, isNonEmptyString, isNull, isNumber, isNumbericString, isObject, isPromise, isRegExp, isSet, isString, isUndefined, isWhitespaceString, isZero, join, last, mergeArrayable, minutes, noop, omit, once, pick, rAF, seconds, slash, sortObject, throttle, toArray, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
378
+ export { type AnyFn, type Arrayable, type Awaitable, type Callable, type CleanObjectOptions, type InteropModuleDefault, type JsonArray, type JsonObject, type JsonPrimitive, type JsonValue, type MayBe, NOOP, type NonEmptyString, type Nullable, type Overwrite, type Prettify, type PrettifyV2, type PrimitiveType, type ResolvedOptions, type SortObjectOptions, type ThrottleDebounceOptions, type Whitespace, at, cAF, capitalize, chunk, clamp, cleanObject, days, debounce, ensurePrefix, ensureSuffix, escapeHtml, flattenArrayable, getObjectType, hasOwn, hours, isArray, isArrayEqual, isBoolean, isBrowser, isDeepEqual, isEmptyArray, isEmptyObject, isEmptyString, isEmptyStringOrWhitespace, isFunction, isInteger, isNaN, isNativePromise, isNil, isNonEmptyString, isNull, isNumber, isNumbericString, isObject, isPromise, isRegExp, isSet, isString, isUndefined, isWhitespaceString, isZero, join, last, mergeArrayable, minutes, noop, omit, once, pick, rAF, seconds, slash, sortObject, throttle, toArray, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
package/dist/index.js CHANGED
@@ -308,10 +308,10 @@ function unindent(input) {
308
308
  const lines = (typeof input === "string" ? input : input[0]).split("\n");
309
309
  const whitespaceLines = lines.map((line) => _RE_FULL_WS.test(line));
310
310
  const commonIndent = lines.reduce((min, line, idx) => {
311
- if (!whitespaceLines[idx]) {
311
+ if (whitespaceLines[idx]) {
312
312
  return min;
313
313
  }
314
- const indent = line.match(/^\s/)?.[0].length;
314
+ const indent = line.match(/^\s*/)?.[0].length;
315
315
  return indent === void 0 ? min : Math.min(min, indent);
316
316
  }, Number.POSITIVE_INFINITY);
317
317
  let emptylinesHead = 0;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ntnyq/utils",
3
3
  "type": "module",
4
- "version": "0.4.0",
4
+ "version": "0.4.2",
5
5
  "description": "Common used utils.",
6
6
  "keywords": [
7
7
  "utils"
@@ -40,18 +40,18 @@
40
40
  "scule": "^1.3.0"
41
41
  },
42
42
  "devDependencies": {
43
- "@ntnyq/eslint-config": "^3.8.1",
43
+ "@ntnyq/eslint-config": "^3.10.2",
44
44
  "@ntnyq/prettier-config": "^1.22.0",
45
- "@vitest/coverage-v8": "^2.1.8",
46
- "bumpp": "^9.8.1",
47
- "eslint": "^9.16.0",
45
+ "@vitest/coverage-v8": "^3.0.0-beta.3",
46
+ "bumpp": "^9.9.2",
47
+ "eslint": "^9.17.0",
48
48
  "husky": "^9.1.7",
49
49
  "nano-staged": "^0.8.0",
50
- "npm-run-all2": "^7.0.1",
50
+ "npm-run-all2": "^7.0.2",
51
51
  "prettier": "^3.4.2",
52
52
  "tsup": "^8.3.5",
53
53
  "typescript": "^5.7.2",
54
- "vitest": "^2.1.8"
54
+ "vitest": "^3.0.0-beta.3"
55
55
  },
56
56
  "engines": {
57
57
  "node": ">=18.18.0"