@sohanemon/utils 5.0.1 → 5.0.3

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.
@@ -209,3 +209,14 @@ export declare const mergeRefs: MergeRefs;
209
209
  * @example goToClientSideHash('my-element');
210
210
  */
211
211
  export declare function goToClientSideHash(id: string, opts?: ScrollIntoViewOptions): void;
212
+ /**
213
+ * Escapes a string for use in a regular expression.
214
+ *
215
+ * @param str - The string to escape
216
+ * @returns - The escaped string
217
+ *
218
+ * @example
219
+ * const escapedString = escapeRegExp('Hello, world!');
220
+ * // escapedString === 'Hello\\, world!'
221
+ */
222
+ export declare function escapeRegExp(str: string): string;
@@ -374,3 +374,16 @@ export function goToClientSideHash(id, opts) {
374
374
  el.scrollIntoView({ behavior: 'smooth', block: 'start', ...opts });
375
375
  window.history.pushState(null, '', `#${id}`);
376
376
  }
377
+ /**
378
+ * Escapes a string for use in a regular expression.
379
+ *
380
+ * @param str - The string to escape
381
+ * @returns - The escaped string
382
+ *
383
+ * @example
384
+ * const escapedString = escapeRegExp('Hello, world!');
385
+ * // escapedString === 'Hello\\, world!'
386
+ */
387
+ export function escapeRegExp(str) {
388
+ return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
389
+ }
@@ -1,6 +1,5 @@
1
1
  export type Primitive = string | number | bigint | boolean | symbol | null | undefined;
2
2
  export type Falsy = false | '' | 0 | null | undefined;
3
- export type Nullish = null | undefined;
4
3
  export declare const isFalsy: (val: unknown) => val is Falsy;
5
- export declare const isNullish: (val: unknown) => val is Nullish;
4
+ export declare const isNullish: (val: unknown) => val is (null | undefined);
6
5
  export declare const isPrimitive: (val: unknown) => val is Primitive;
@@ -10,6 +10,18 @@ export type DeepRequired<T> = T extends Function ? T : T extends Array<infer U>
10
10
  export type Never<T> = {
11
11
  [K in keyof T]: never;
12
12
  };
13
+ export type Nullable<T> = T extends object ? {
14
+ [P in keyof T]: Nullable<T[P]>;
15
+ } : T | null;
16
+ export type Optional<T> = T extends object ? {
17
+ [P in keyof T]: Optional<T[P]>;
18
+ } : T | undefined;
19
+ export type Nullish<T> = T extends object ? {
20
+ [P in keyof T]: Nullish<T[P]>;
21
+ } : T | null | undefined;
22
+ export type Maybe<T> = T extends object ? {
23
+ [P in keyof T]?: Nullish<T[P]>;
24
+ } : T | null | undefined;
13
25
  export type DeepReadonly<T> = T extends Function ? T : T extends Array<infer U> ? ReadonlyArray<DeepReadonly<U>> : T extends object ? {
14
26
  readonly [K in keyof T]: DeepReadonly<T[K]>;
15
27
  } : T;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sohanemon/utils",
3
- "version": "5.0.1",
3
+ "version": "5.0.3",
4
4
  "author": "Sohan Emon <sohanemon@outlook.com>",
5
5
  "description": "",
6
6
  "type": "module",