@goodbyenjn/utils 1.1.1 → 1.2.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/dist/fs.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Result, ResultAsync } from "./libs/result-f34c580d.js";
2
- import "./libs/types-16d7a3e8.js";
1
+ import "./libs/types-4042b7e8.js";
2
+ import { Result, ResultAsync } from "./libs/result-81665e58.js";
3
3
 
4
4
  //#region src/fs/types.d.ts
5
5
  type PathLike = string | URL;
package/dist/fs.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { e$3 as e } from "./libs/remeda-662cc9ef.js";
2
- import { errorToMessage, removePrefix } from "./libs/common-e8d0d8ef.js";
2
+ import { errorToMessage, removePrefix } from "./libs/common-7de47aac.js";
3
3
  import { Result, ResultAsync, err, ok, safeTry } from "./libs/result-6175a096.js";
4
4
  import fs, { promises } from "node:fs";
5
5
  import path, { dirname } from "node:path";
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { ResultAsync } from "./libs/result-f34c580d.js";
2
- import { AsyncFn, Fn } from "./libs/types-16d7a3e8.js";
1
+ import { AsyncFn, Fn } from "./libs/types-4042b7e8.js";
2
+ import { ResultAsync } from "./libs/result-81665e58.js";
3
3
 
4
4
  //#region src/common/error.d.ts
5
5
  interface ErrorLike extends Partial<Error> {
@@ -30,16 +30,6 @@ declare const scale: (value: number, inRange: [min: number, max: number], outRan
30
30
  declare const parseKeyValuePairs: (input: string) => Record<string, string>;
31
31
  declare const parseValueToBoolean: (value: unknown, defaultValue: boolean) => boolean;
32
32
  //#endregion
33
- //#region src/common/process.d.ts
34
- declare function $(cmd: string): ResultAsync<{
35
- stdout: string;
36
- stderr: string;
37
- }, string>;
38
- declare function $(cmd: TemplateStringsArray, ...values: any[]): ResultAsync<{
39
- stdout: string;
40
- stderr: string;
41
- }, string>;
42
- //#endregion
43
33
  //#region src/common/promise.d.ts
44
34
  interface PromiseWithResolvers<T> {
45
35
  promise: Promise<T>;
@@ -72,6 +62,17 @@ declare const createLock: () => {
72
62
  };
73
63
  declare const PromiseWithResolvers: <T>() => PromiseWithResolvers<T>;
74
64
  //#endregion
65
+ //#region src/common/shell.d.ts
66
+ declare function $(cmd: string): ResultAsync<{
67
+ stdout: string;
68
+ stderr: string;
69
+ }, string>;
70
+ declare function $(cmd: TemplateStringsArray, ...values: any[]): ResultAsync<{
71
+ stdout: string;
72
+ stderr: string;
73
+ }, string>;
74
+ declare const quoteShellArg: (arg: string) => string;
75
+ //#endregion
75
76
  //#region src/common/string.d.ts
76
77
  declare const addPrefix: (prefix: string, str: string) => string;
77
78
  declare const addSuffix: (suffix: string, str: string) => string;
@@ -137,4 +138,4 @@ type ThrottleOptions = Options;
137
138
  declare const debounce: <T extends Fn>(fn: T, wait?: number, options?: Options) => WrappedFn<T>;
138
139
  declare const throttle: <T extends Fn>(fn: T, wait?: number, options?: Options) => WrappedFn<T>;
139
140
  //#endregion
140
- export { $, type DebounceOptions, type DebouncedFn, type ErrorLike, PromiseWithResolvers, type ThrottleOptions, type ThrottledFn, addPrefix, addSuffix, createLock, createSingleton, debounce, errorToMessage, getErrorMessage, isErrorLike, join, joinWithSlash, linear, normalizeError, parseKeyValuePairs, parseValueToBoolean, removePrefix, removeSuffix, scale, sleep, split, splitWithSlash, template, throttle, toForwardSlash, unindent };
141
+ export { $, type DebounceOptions, type DebouncedFn, type ErrorLike, PromiseWithResolvers, type ThrottleOptions, type ThrottledFn, addPrefix, addSuffix, createLock, createSingleton, debounce, errorToMessage, getErrorMessage, isErrorLike, join, joinWithSlash, linear, normalizeError, parseKeyValuePairs, parseValueToBoolean, quoteShellArg, removePrefix, removeSuffix, scale, sleep, split, splitWithSlash, template, throttle, toForwardSlash, unindent };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./libs/remeda-662cc9ef.js";
2
- import { $, PromiseWithResolvers, addPrefix, addSuffix, createLock, createSingleton, debounce, errorToMessage, getErrorMessage, isErrorLike, join, joinWithSlash, linear, normalizeError, parseKeyValuePairs, parseValueToBoolean, removePrefix, removeSuffix, scale, sleep, split, splitWithSlash, template, throttle, toForwardSlash, unindent } from "./libs/common-e8d0d8ef.js";
2
+ import { $, PromiseWithResolvers, addPrefix, addSuffix, createLock, createSingleton, debounce, errorToMessage, getErrorMessage, isErrorLike, join, joinWithSlash, linear, normalizeError, parseKeyValuePairs, parseValueToBoolean, quoteShellArg, removePrefix, removeSuffix, scale, sleep, split, splitWithSlash, template, throttle, toForwardSlash, unindent } from "./libs/common-7de47aac.js";
3
3
  import "./libs/result-6175a096.js";
4
4
 
5
- export { $, PromiseWithResolvers, addPrefix, addSuffix, createLock, createSingleton, debounce, errorToMessage, getErrorMessage, isErrorLike, join, joinWithSlash, linear, normalizeError, parseKeyValuePairs, parseValueToBoolean, removePrefix, removeSuffix, scale, sleep, split, splitWithSlash, template, throttle, toForwardSlash, unindent };
5
+ export { $, PromiseWithResolvers, addPrefix, addSuffix, createLock, createSingleton, debounce, errorToMessage, getErrorMessage, isErrorLike, join, joinWithSlash, linear, normalizeError, parseKeyValuePairs, parseValueToBoolean, quoteShellArg, removePrefix, removeSuffix, scale, sleep, split, splitWithSlash, template, throttle, toForwardSlash, unindent };
@@ -198,7 +198,7 @@ const PromiseWithResolvers = () => {
198
198
  };
199
199
 
200
200
  //#endregion
201
- //#region src/common/process.ts
201
+ //#region src/common/shell.ts
202
202
  function $(cmd, ...values) {
203
203
  const command = t(cmd) ? cmd : cmd.reduce((acc, part, index) => acc + part + (values[index] ?? ""), "");
204
204
  const promise = import("node:child_process").then(({ exec }) => {
@@ -214,6 +214,18 @@ function $(cmd, ...values) {
214
214
  });
215
215
  return ResultAsync.fromPromise(promise, errorToMessage(`Failed to execute command: ${cmd}`));
216
216
  }
217
+ const REGEXP_NULL_CHAR = /\x00+/g;
218
+ const REGEXP_SAFE_CHARS = /^[A-Za-z0-9,:=_./-]+$/;
219
+ const REGEXP_SINGLE_QUOTES = /'+/g;
220
+ const quoteShellArg = (arg) => {
221
+ if (!arg) return "''";
222
+ const cleaned = String(arg).replace(REGEXP_NULL_CHAR, "");
223
+ const matches = REGEXP_SAFE_CHARS.exec(cleaned);
224
+ if (matches?.[0].length === cleaned.length) return cleaned;
225
+ const quoted = cleaned.replace(REGEXP_SINGLE_QUOTES, (matched) => matched.length === 1 ? `'\\''` : `'"${matched}"'`);
226
+ const trimmed = `'${quoted}'`.replace(/^''/, "").replace(/''$/, "");
227
+ return trimmed;
228
+ };
217
229
 
218
230
  //#endregion
219
231
  //#region src/common/string.ts
@@ -317,4 +329,4 @@ const throttle = (fn, wait = 0, options = {}) => {
317
329
  };
318
330
 
319
331
  //#endregion
320
- export { $, PromiseWithResolvers, addPrefix, addSuffix, createLock, createSingleton, debounce, errorToMessage, getErrorMessage, isErrorLike, join, joinWithSlash, linear, normalizeError, parseKeyValuePairs, parseValueToBoolean, removePrefix, removeSuffix, scale, sleep, split, splitWithSlash, template, throttle, toForwardSlash, unindent };
332
+ export { $, PromiseWithResolvers, addPrefix, addSuffix, createLock, createSingleton, debounce, errorToMessage, getErrorMessage, isErrorLike, join, joinWithSlash, linear, normalizeError, parseKeyValuePairs, parseValueToBoolean, quoteShellArg, removePrefix, removeSuffix, scale, sleep, split, splitWithSlash, template, throttle, toForwardSlash, unindent };
@@ -1,4 +1,4 @@
1
- import { AsyncFn, Fn, NonEmptyTuple, Promisable } from "./types-16d7a3e8.js";
1
+ import { AsyncFn, Fn, NonEmptyTuple, Promisable } from "./types-4042b7e8.js";
2
2
 
3
3
  //#region src/result/types.d.ts
4
4
  type ExtractOkTypes<T extends readonly Result[]> = { [K in keyof T]: T[K] extends Result<infer U, unknown> ? U : never };
package/dist/remeda.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { And, ArraySlice, CamelCase, EmptyObject, GreaterThan, GreaterThanOrEqual, IfNever, IntRange, IsAny, IsEqual, IsFloat, IsInteger, IsLiteral, IsNegative, IsNever, IsNumericLiteral, IsStringLiteral, IsSymbolLiteral, Join, KeysOfUnion, LastArrayElement, LessThan, Merge, MergeDeep, NonNegative, NonNegativeInteger, Or, ReadonlyTuple, RequireAtLeastOne, SharedUnionFields, Simplify, Split, Subtract, Tagged, ValueOf, Words, Writable } from "./libs/types-16d7a3e8.js";
1
+ import { And, ArraySlice, CamelCase, EmptyObject, GreaterThan, GreaterThanOrEqual, IfNever, IntRange, IsAny, IsEqual, IsFloat, IsInteger, IsLiteral, IsNegative, IsNever, IsNumericLiteral, IsStringLiteral, IsSymbolLiteral, Join, KeysOfUnion, LastArrayElement, LessThan, Merge, MergeDeep, NonNegative, NonNegativeInteger, Or, ReadonlyTuple, RequireAtLeastOne, SharedUnionFields, Simplify, Split, Subtract, Tagged, ValueOf, Words, Writable } from "./libs/types-4042b7e8.js";
2
2
 
3
3
  //#region src/remeda/types.d.ts
4
4
 
package/dist/result.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { Err, Ok, Result, ResultAsync, err, errAsync, ok, okAsync, safeTry } from "./libs/result-f34c580d.js";
2
- import "./libs/types-16d7a3e8.js";
1
+ import "./libs/types-4042b7e8.js";
2
+ import { Err, Ok, Result, ResultAsync, err, errAsync, ok, okAsync, safeTry } from "./libs/result-81665e58.js";
3
3
  export { Err, Ok, Result, ResultAsync, err, errAsync, ok, okAsync, safeTry };
package/dist/types.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { AbstractClass, AbstractConstructor, AllUnionFields, And, ArrayIndices, ArraySlice, ArraySplice, ArrayTail, ArrayValues, Arrayable, AsyncFn, AsyncFnWithThis, AsyncReturnType, Asyncify, CamelCase, CamelCasedProperties, CamelCasedPropertiesDeep, Class, ConditionalExcept, ConditionalKeys, ConditionalPick, ConditionalPickDeep, ConditionalPickDeepOptions, Constructor, DelimiterCase, DelimiterCasedProperties, DelimiterCasedPropertiesDeep, DistributedOmit, DistributedPick, EmptyObject, Entries, Entry, Exact, Except, FindGlobalInstanceType, FindGlobalType, Finite, FixedLengthArray, Float, Fn, FnWithThis, Get, GetTagMetadata, GlobalThis, GreaterThan, GreaterThanOrEqual, HasOptionalKeys, HasReadonlyKeys, HasRequiredKeys, HasWritableKeys, IfAny, IfEmptyObject, IfNever, IfNull, IfUnknown, Includes, IntClosedRange, IntRange, Integer, InvariantOf, IsAny, IsBooleanLiteral, IsEmptyObject, IsEqual, IsFloat, IsInteger, IsLiteral, IsNegative, IsNever, IsNull, IsNumericLiteral, IsStringLiteral, IsSymbolLiteral, IsTuple, IsUnknown, IterableElement, Join, JsonArray, JsonObject, JsonPrimitive, JsonValue, Jsonifiable, Jsonify, KebabCase, KebabCasedProperties, KebabCasedPropertiesDeep, KeysOfUnion, LastArrayElement, LessThan, LessThanOrEqual, LiteralToPrimitive, LiteralToPrimitiveDeep, LiteralUnion, Merge, MergeDeep, MergeDeepOptions, MergeExclusive, MultidimensionalArray, MultidimensionalReadonlyArray, Negative, NegativeFloat, NegativeInfinity, NegativeInteger, NonEmptyObject, NonEmptyString, NonEmptyTuple, NonNegative, NonNegativeInteger, Nullable, OmitByKey, OmitDeep, OmitIndexSignature, Opaque, OptionalKeysOf, Or, OverrideProperties, PackageJson, PartialDeep, PartialDeepOptions, PartialOnUndefinedDeep, PartialOnUndefinedDeepOptions, PascalCase, PascalCasedProperties, PascalCasedPropertiesDeep, Paths, PickDeep, PickIndexSignature, PositiveInfinity, Primitive, Promisable, ReadonlyDeep, ReadonlyKeysOf, ReadonlyTuple, Replace, RequireAllOrNone, RequireAtLeastOne, RequireExactlyOne, RequireOneOrNone, RequiredDeep, RequiredKeysOf, Schema, SchemaOptions, ScreamingSnakeCase, SetFieldType, SetNonNullable, SetOptional, SetParameterType, SetReadonly, SetRequired, SetRequiredDeep, SetReturnType, SharedUnionFields, SharedUnionFieldsDeep, Simplify, SimplifyDeep, SingleKeyObject, SnakeCase, SnakeCasedProperties, SnakeCasedPropertiesDeep, Split, Spread, StringKeyOf, StringRepeat, StringSlice, Stringified, StructuredCloneable, Subtract, Sum, Tagged, TaggedUnion, Trim, TsConfigJson, TupleToObject, TupleToUnion, TypedArray, UndefinedOnPartialDeep, UnionToIntersection, UnionToTuple, UnknownArray, UnknownMap, UnknownRecord, UnknownSet, UnwrapOpaque, UnwrapTagged, ValueOf, Words, Writable, WritableDeep, WritableKeysOf, YieldType } from "./libs/types-16d7a3e8.js";
1
+ import { AbstractClass, AbstractConstructor, AllUnionFields, And, ArrayIndices, ArraySlice, ArraySplice, ArrayTail, ArrayValues, Arrayable, AsyncFn, AsyncFnWithThis, AsyncReturnType, Asyncify, CamelCase, CamelCasedProperties, CamelCasedPropertiesDeep, Class, ConditionalExcept, ConditionalKeys, ConditionalPick, ConditionalPickDeep, ConditionalPickDeepOptions, Constructor, DelimiterCase, DelimiterCasedProperties, DelimiterCasedPropertiesDeep, DistributedOmit, DistributedPick, EmptyObject, Entries, Entry, Exact, Except, FindGlobalInstanceType, FindGlobalType, Finite, FixedLengthArray, Float, Fn, FnWithThis, Get, GetTagMetadata, GlobalThis, GreaterThan, GreaterThanOrEqual, HasOptionalKeys, HasReadonlyKeys, HasRequiredKeys, HasWritableKeys, IfAny, IfEmptyObject, IfNever, IfNull, IfUnknown, Includes, IntClosedRange, IntRange, Integer, InvariantOf, IsAny, IsBooleanLiteral, IsEmptyObject, IsEqual, IsFloat, IsInteger, IsLiteral, IsNegative, IsNever, IsNull, IsNumericLiteral, IsStringLiteral, IsSymbolLiteral, IsTuple, IsUnknown, IterableElement, Join, JsonArray, JsonObject, JsonPrimitive, JsonValue, Jsonifiable, Jsonify, KebabCase, KebabCasedProperties, KebabCasedPropertiesDeep, KeysOfUnion, LastArrayElement, LessThan, LessThanOrEqual, LiteralToPrimitive, LiteralToPrimitiveDeep, LiteralUnion, Merge, MergeDeep, MergeDeepOptions, MergeExclusive, MultidimensionalArray, MultidimensionalReadonlyArray, Negative, NegativeFloat, NegativeInfinity, NegativeInteger, NonEmptyObject, NonEmptyString, NonEmptyTuple, NonNegative, NonNegativeInteger, Nullable, OmitByKey, OmitDeep, OmitIndexSignature, Opaque, OptionalKeysOf, Or, OverrideProperties, PackageJson, PartialDeep, PartialDeepOptions, PartialOnUndefinedDeep, PartialOnUndefinedDeepOptions, PascalCase, PascalCasedProperties, PascalCasedPropertiesDeep, Paths, PickDeep, PickIndexSignature, PositiveInfinity, Primitive, Promisable, ReadonlyDeep, ReadonlyKeysOf, ReadonlyTuple, Replace, RequireAllOrNone, RequireAtLeastOne, RequireExactlyOne, RequireOneOrNone, RequiredDeep, RequiredKeysOf, Schema, SchemaOptions, ScreamingSnakeCase, SetFieldType, SetNonNullable, SetOptional, SetParameterType, SetReadonly, SetRequired, SetRequiredDeep, SetReturnType, SharedUnionFields, SharedUnionFieldsDeep, Simplify, SimplifyDeep, SingleKeyObject, SnakeCase, SnakeCasedProperties, SnakeCasedPropertiesDeep, Split, Spread, StringKeyOf, StringRepeat, StringSlice, Stringified, StructuredCloneable, Subtract, Sum, Tagged, TaggedUnion, Trim, TsConfigJson, TupleToObject, TupleToUnion, TypedArray, UndefinedOnPartialDeep, UnionToIntersection, UnionToTuple, UnknownArray, UnknownMap, UnknownRecord, UnknownSet, UnwrapOpaque, UnwrapTagged, ValueOf, Words, Writable, WritableDeep, WritableKeysOf, YieldType } from "./libs/types-4042b7e8.js";
2
2
  export { AbstractClass, AbstractConstructor, AllUnionFields, And, ArrayIndices, ArraySlice, ArraySplice, ArrayTail, ArrayValues, Arrayable, AsyncFn, AsyncFnWithThis, AsyncReturnType, Asyncify, CamelCase, CamelCasedProperties, CamelCasedPropertiesDeep, Class, ConditionalExcept, ConditionalKeys, ConditionalPick, ConditionalPickDeep, ConditionalPickDeepOptions, Constructor, DelimiterCase, DelimiterCasedProperties, DelimiterCasedPropertiesDeep, DistributedOmit, DistributedPick, EmptyObject, Entries, Entry, Exact, Except, FindGlobalInstanceType, FindGlobalType, Finite, FixedLengthArray, Float, Fn, FnWithThis, Get, GetTagMetadata, GlobalThis, GreaterThan, GreaterThanOrEqual, HasOptionalKeys, HasReadonlyKeys, HasRequiredKeys, HasWritableKeys, IfAny, IfEmptyObject, IfNever, IfNull, IfUnknown, Includes, IntClosedRange, IntRange, Integer, InvariantOf, IsAny, IsBooleanLiteral, IsEmptyObject, IsEqual, IsFloat, IsInteger, IsLiteral, IsNegative, IsNever, IsNull, IsNumericLiteral, IsStringLiteral, IsSymbolLiteral, IsTuple, IsUnknown, IterableElement, Join, JsonArray, JsonObject, JsonPrimitive, JsonValue, Jsonifiable, Jsonify, KebabCase, KebabCasedProperties, KebabCasedPropertiesDeep, KeysOfUnion, LastArrayElement, LessThan, LessThanOrEqual, LiteralToPrimitive, LiteralToPrimitiveDeep, LiteralUnion, Merge, MergeDeep, MergeDeepOptions, MergeExclusive, MultidimensionalArray, MultidimensionalReadonlyArray, Negative, NegativeFloat, NegativeInfinity, NegativeInteger, NonEmptyObject, NonEmptyString, NonEmptyTuple, NonNegative, NonNegativeInteger, Nullable, OmitByKey, OmitDeep, OmitIndexSignature, Opaque, OptionalKeysOf, Or, OverrideProperties as Override, OverrideProperties, PackageJson, SetOptional as PartialByKey, PartialDeep, PartialDeepOptions, PartialOnUndefinedDeep, PartialOnUndefinedDeepOptions, PascalCase, PascalCasedProperties, PascalCasedPropertiesDeep, Paths, PickDeep, PickIndexSignature, PositiveInfinity, Primitive, Promisable, ReadonlyDeep, ReadonlyKeysOf, ReadonlyTuple, Replace, RequireAllOrNone, RequireAtLeastOne, RequireExactlyOne, RequireOneOrNone, SetRequired as RequiredByKey, RequiredDeep, RequiredKeysOf, Schema, SchemaOptions, ScreamingSnakeCase, SetFieldType, SetNonNullable, SetOptional, SetParameterType, SetReadonly, SetRequired, SetRequiredDeep, SetReturnType, SharedUnionFields, SharedUnionFieldsDeep, Simplify, SimplifyDeep, SingleKeyObject, SnakeCase, SnakeCasedProperties, SnakeCasedPropertiesDeep, Split, Spread, StringKeyOf, StringRepeat, StringSlice, Stringified, StructuredCloneable, Subtract, Sum, Tagged, TaggedUnion, Trim, TsConfigJson, TupleToObject, TupleToUnion, TypedArray, UndefinedOnPartialDeep, UnionToIntersection, UnionToTuple, UnknownArray, UnknownMap, UnknownRecord, UnknownSet, UnwrapOpaque, UnwrapTagged, ValueOf, Words, Writable, WritableDeep, WritableKeysOf, YieldType };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goodbyenjn/utils",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "GoodbyeNJN's utils for typescript and javascript",
5
5
  "keywords": [
6
6
  "utils",