moderndash 0.0.10 → 0.0.12

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 (42) hide show
  1. package/package.json +2 -2
  2. package/src/array/difference.ts +2 -2
  3. package/src/array/differenceBy.ts +1 -1
  4. package/src/array/index.ts +0 -3
  5. package/src/array/intersectionBy.ts +1 -1
  6. package/src/array/shuffle.ts +1 -1
  7. package/src/array/uniqWith.ts +1 -1
  8. package/src/collection/countBy.ts +4 -4
  9. package/src/collection/groupBy.ts +3 -3
  10. package/src/function/after.ts +10 -4
  11. package/src/function/before.ts +8 -4
  12. package/src/function/debounce.ts +12 -11
  13. package/src/function/index.ts +1 -0
  14. package/src/function/memoize.ts +7 -3
  15. package/src/function/once.ts +6 -3
  16. package/src/function/throttle.ts +5 -3
  17. package/src/lang/isEmpty.ts +33 -5
  18. package/src/lang/isEqual.ts +26 -0
  19. package/src/lang/isEqualWith.ts +30 -1
  20. package/src/object/pick.ts +4 -5
  21. package/src/string/camelCase.ts +15 -0
  22. package/src/string/capitalize.ts +11 -0
  23. package/src/string/deburr.ts +15 -0
  24. package/src/string/escape.ts +11 -0
  25. package/src/string/escapeRegExp.ts +12 -0
  26. package/src/string/kebabCase.ts +15 -0
  27. package/src/string/pascalCase.ts +16 -0
  28. package/src/string/snakeCase.ts +17 -0
  29. package/src/string/startCase.ts +15 -0
  30. package/src/string/stripSpecialChars.ts +11 -0
  31. package/src/string/unescape.ts +14 -2
  32. package/src/types.ts +9 -3
  33. package/LICENSE +0 -21
  34. package/README.md +0 -92
  35. package/dist/index.cjs +0 -733
  36. package/dist/index.cjs.map +0 -1
  37. package/dist/index.d.ts +0 -585
  38. package/dist/index.js +0 -658
  39. package/dist/index.js.map +0 -1
  40. package/src/array/union.ts +0 -16
  41. package/src/array/unionBy.ts +0 -26
  42. package/src/array/unionWith.ts +0 -31
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "moderndash",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
4
4
  "type": "module",
5
5
  "description": "A lodash inspired utility framework for ESM/Typescript/ES2020",
6
6
  "scripts": {
@@ -40,7 +40,7 @@
40
40
  "dist",
41
41
  "src"
42
42
  ],
43
- "homepage": "https://github.com/Maggi64/moderndash#readme",
43
+ "homepage": "https://moderndash.io",
44
44
  "devDependencies": {
45
45
  "@vitest/coverage-c8": "0.27.1",
46
46
  "@vitest/ui": "0.27.1",
@@ -13,9 +13,9 @@ import { isEqual } from '@lang/isEqual';
13
13
  * @returns Returns the new array of filtered values.
14
14
  * @example
15
15
  * difference([2, 1], [2, 3])
16
- * // =\> [1]
16
+ * // => [1]
17
17
  */
18
18
 
19
- export function difference<T>(...arrays: MinimumTwoArrays<T>): T[] {
19
+ export function difference<TInput>(...arrays: MinimumTwoArrays<TInput>): TInput[] {
20
20
  return differenceWith(isEqual, ...arrays);
21
21
  }
@@ -26,5 +26,5 @@ import { isEqualWith } from '@lang/isEqualWith';
26
26
 
27
27
  export function differenceBy<T>(iteratee: IterateeFunction<T> | PropertyShorthand<T>, ...arrays: MinimumTwoArrays<T>): T[] {
28
28
  const iterateeFunction = getIterateFunction(iteratee);
29
- return differenceWith((a, b) => isEqualWith(iterateeFunction, a, b), ...arrays);
29
+ return differenceWith((a, b) => isEqualWith(a, b, iterateeFunction), ...arrays);
30
30
  }
@@ -12,9 +12,6 @@ export * from './sampleSize';
12
12
  export * from './shuffle';
13
13
  export * from './takeRightWhile';
14
14
  export * from './takeWhile';
15
- export * from './union';
16
- export * from './unionBy';
17
- export * from './unionWith';
18
15
  export * from './uniq';
19
16
  export * from './uniqBy';
20
17
  export * from './uniqWith';
@@ -22,5 +22,5 @@ import { isEqualWith } from '@lang/isEqualWith';
22
22
 
23
23
  export function intersectionBy<TInput>(iteratee: IterateeFunction<TInput> | PropertyShorthand<TInput>, ...arrays: MinimumTwoArrays<TInput>): TInput[] {
24
24
  const iterateeFunction = getIterateFunction(iteratee);
25
- return intersectionWith((a, b) => isEqualWith(iterateeFunction, a, b), ...arrays);
25
+ return intersectionWith((a, b) => isEqualWith(a, b, iterateeFunction), ...arrays);
26
26
  }
@@ -5,7 +5,7 @@
5
5
  * @since 0.1.0
6
6
  * @category Array
7
7
  * @param array - The array or object to shuffle.
8
- * @returns {Array} Returns the new shuffled array.
8
+ * @returns Returns the new shuffled array.
9
9
  * @example
10
10
  * shuffle([1, 2, 3, 4])
11
11
  * // => [4, 1, 3, 2]
@@ -5,7 +5,7 @@
5
5
  * @category Array
6
6
  * @param array - The array to inspect.
7
7
  * @param comparator - The comparator invoked per element.
8
- * @returns {Array} Returns the new duplicate free array.
8
+ * @returns Returns the new duplicate free array.
9
9
  * @example
10
10
  * const objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }]
11
11
  *
@@ -7,10 +7,6 @@ import { getValuesFromCollection } from '@helpers/collections';
7
7
  * each element of `collection` thru `iteratee`. The corresponding value of
8
8
  * each key is the number of times the key was returned by `iteratee`.
9
9
  *
10
- * @category Collection
11
- * @param iteratee - The iteratee to transform keys.
12
- * @param collection - The array or record to iterate over.
13
- * @returns Returns the composed aggregate object.
14
10
  * @example
15
11
  * const users = [
16
12
  * { 'user': 'barney', 'active': true },
@@ -20,6 +16,10 @@ import { getValuesFromCollection } from '@helpers/collections';
20
16
  *
21
17
  * countBy(users, value => value.active);
22
18
  * // => { 'true': 2, 'false': 1 }
19
+ * @category Collection
20
+ * @param iteratee - The iteratee to transform keys.
21
+ * @param collection - The array or record to iterate over.
22
+ * @returns Returns the composed aggregate object.
23
23
  */
24
24
 
25
25
  export function countBy<TInput, TKey extends RecordKey>(collection: ArrayOrRecord<TInput>, iteratee: (value: TInput) => TKey): Record<TKey, number> {
@@ -10,13 +10,13 @@ import { getValuesFromCollection } from '@helpers/collections';
10
10
  * value of each key is an array of elements responsible for generating the
11
11
  * key.
12
12
  *
13
+ * @example
14
+ * groupBy([6.1, 4.2, 6.3], Math.floor)
15
+ * // => { '4': [4.2], '6': [6.1, 6.3] }
13
16
  * @category Collection
14
17
  * @param collection - The array or object to iterate over.
15
18
  * @param iteratee - The iteratee to transform keys.
16
19
  * @returns Returns the composed aggregate object.
17
- * @example
18
- * groupBy([6.1, 4.2, 6.3], Math.floor)
19
- * // => { '4': [4.2], '6': [6.1, 6.3] }
20
20
  */
21
21
 
22
22
  export function groupBy<T, U extends RecordKey>(collection: ArrayOrRecord<T>, iteratee: (value: T) => U): Record<U, T[]> {
@@ -1,3 +1,5 @@
1
+ import type { GenericFunction } from '../types.js';
2
+
1
3
  /**
2
4
  * The opposite of `before`. This method creates a function that invokes `func` once it's called `n` or more times.
3
5
  *
@@ -6,13 +8,17 @@
6
8
  * @param func The function to restrict.
7
9
  * @returns Returns the new restricted function.
8
10
  * @example
9
- * const caution = () => alert("Caution!");
11
+ * const caution = () => console.log("Caution!");
12
+ *
13
+ * const afterFN = after(2, caution);
10
14
  *
11
- * // Display alert only after it has been called 5 times
12
- * after(5, caution)
15
+ * afterFN()
16
+ * afterFN()
17
+ * afterFN()
18
+ * // => `caution` is invoked after called twice
13
19
  */
14
20
 
15
- export function after<TFunc extends (...args: Parameters<TFunc>) => ReturnType<TFunc>>(n: number, func: TFunc) {
21
+ export function after<TFunc extends GenericFunction<TFunc>>(n: number, func: TFunc) {
16
22
  let count = 1;
17
23
  return (...args: Parameters<TFunc>): ReturnType<TFunc> | undefined => {
18
24
  if (count >= n) {
@@ -1,6 +1,5 @@
1
1
  /**
2
- * Creates a function that invokes `func`, with the `this` binding and arguments
3
- * of the created function, while it's called less than `n` times. Subsequent
2
+ * Creates a function that invokes `func`, while it's called less than `n` times. Subsequent
4
3
  * calls to the created function return the result of the last `func` invocation.
5
4
  *
6
5
  * @category Function
@@ -8,10 +7,15 @@
8
7
  * @param func - The function to restrict.
9
8
  * @returns Returns the new restricted function.
10
9
  * @example
11
- * const caution = () => alert("Caution!");
10
+ * const caution = () => console.log("Caution!");
12
11
  *
13
12
  * // Only call caution two times
14
- * before(2, caution)
13
+ * const reducedCaution = before(2, caution)
14
+ *
15
+ * reducedCaution()
16
+ * reducedCaution()
17
+ * reducedCaution()
18
+ * // => `caution` is invoked twice
15
19
  */
16
20
 
17
21
  export function before<TFunc extends (...args: Parameters<TFunc>) => ReturnType<TFunc>>(n: number, func: TFunc): TFunc {
@@ -1,11 +1,12 @@
1
+ import type { GenericFunction } from 'src/types.js';
1
2
 
2
3
  // TODO this is a port from lodash, it probably can be improved and shortened, also fix TS errors
3
- export function debounce<T extends (...args: Parameters<T>) => ReturnType<T>>(
4
- fn: T, wait = 0, options: { leading?: boolean, maxWait?: number, trailing?: boolean } = {}
5
- ): (this: ThisParameterType<T>, ...args: Parameters<T>) => ReturnType<T> {
6
- let lastArgs: Parameters<T> | undefined;
7
- let lastThis: ThisParameterType<T> | undefined;
8
- let result: ReturnType<T>;
4
+ export function debounce<TFunc extends GenericFunction<TFunc>>(
5
+ fn: TFunc, wait = 0, options: { leading?: boolean, maxWait?: number, trailing?: boolean } = {}
6
+ ): (this: ThisParameterType<TFunc>, ...args: Parameters<TFunc>) => ReturnType<TFunc> {
7
+ let lastArgs: Parameters<TFunc> | undefined;
8
+ let lastThis: ThisParameterType<TFunc> | undefined;
9
+ let result: ReturnType<TFunc>;
9
10
  let timerId: ReturnType<typeof setTimeout> | undefined;
10
11
  let lastCallTime: number | undefined;
11
12
  let lastInvokeTime = 0;
@@ -15,12 +16,12 @@ export function debounce<T extends (...args: Parameters<T>) => ReturnType<T>>(
15
16
  const maxWait = options.maxWait ?? 0;
16
17
 
17
18
  function invokeFunc(time: number) {
18
- const args: Parameters<T> | undefined = lastArgs;
19
- const thisArg: ThisParameterType<T> | undefined = lastThis;
19
+ const args: Parameters<TFunc> | undefined = lastArgs;
20
+ const thisArg: ThisParameterType<TFunc> | undefined = lastThis;
20
21
 
21
22
  lastArgs = lastThis = undefined;
22
23
  lastInvokeTime = time;
23
- // @ts-ignore
24
+ // @ts-expect-error
24
25
  result = fn.apply(thisArg, args);
25
26
  return result;
26
27
  }
@@ -35,7 +36,7 @@ export function debounce<T extends (...args: Parameters<T>) => ReturnType<T>>(
35
36
  }
36
37
 
37
38
  function remainingWait(time: number) {
38
- // @ts-ignore
39
+ // @ts-expect-error
39
40
  const timeSinceLastCall = time - lastCallTime;
40
41
  const timeSinceLastInvoke = time - lastInvokeTime;
41
42
  const timeWaiting = wait - timeSinceLastCall;
@@ -91,7 +92,7 @@ export function debounce<T extends (...args: Parameters<T>) => ReturnType<T>>(
91
92
  return timerId === undefined ? result : trailingEdge(Date.now());
92
93
  }
93
94
 
94
- function debounced(this: ThisParameterType<T>, ...args: Parameters<T>): ReturnType<T> {
95
+ function debounced(this: ThisParameterType<TFunc>, ...args: Parameters<TFunc>): ReturnType<TFunc> {
95
96
  const time = Date.now();
96
97
  const isInvoking = shouldInvoke(time);
97
98
 
@@ -4,3 +4,4 @@ export * from './debounce';
4
4
  export * from './memoize';
5
5
  export * from './once';
6
6
  export * from './throttle';
7
+ export * from './times';
@@ -1,5 +1,6 @@
1
+ import type{ GenericFunction } from 'src/types.js';
2
+
1
3
  const defaultResolver = (...args: unknown[]) => JSON.stringify(args);
2
- type Cache = Map<string | symbol, unknown>;
3
4
 
4
5
  /**
5
6
  * Creates a function that memoizes the result of `func`. If `resolver` is
@@ -16,6 +17,8 @@ type Cache = Map<string | symbol, unknown>;
16
17
  * @category Function
17
18
  * @param func - The function to have its output memoized.
18
19
  * @param resolver - The function to resolve the cache key.
20
+ * @typeParam TFunc - The input function type
21
+ * @typeParam Cache - The cache map type
19
22
  * @returns Returns the new memoized function.
20
23
  * @example
21
24
  * const object = \{ 'a': 1, 'b': 2 \}
@@ -40,10 +43,11 @@ type Cache = Map<string | symbol, unknown>;
40
43
  * memoize.Cache = WeakMap
41
44
  */
42
45
 
43
- export function memoize<TFunc extends (...args: Parameters<TFunc>) => ReturnType<TFunc>>(
46
+ export function memoize<TFunc extends GenericFunction<TFunc>, Cache extends Map<string | symbol, ReturnType<TFunc>>>(
44
47
  func: TFunc, resolver: ((...args: Parameters<TFunc>) => string | symbol) = defaultResolver
45
48
  ): TFunc & { cache: Cache } {
46
- const cache: Cache = new Map();
49
+
50
+ const cache = new Map() as Cache;
47
51
  const memoizedFunc = (...args: Parameters<TFunc>): ReturnType<TFunc> => {
48
52
  const key = resolver(...args);
49
53
  if (cache.has(key)) {
@@ -1,3 +1,7 @@
1
+ import type { GenericFunction } from 'src/types.js';
2
+
3
+ import { before } from '@function/before';
4
+
1
5
  /**
2
6
  * Creates a function that is restricted to invoking `func` once. Repeat calls
3
7
  * to the function return the value of the first invocation. The `func` is
@@ -7,13 +11,12 @@
7
11
  * @param func - The function to restrict.
8
12
  * @returns Returns the new restricted function.
9
13
  * @example
10
- * const initialize = once(createApplication)
14
+ * const initialize = once(() => console.log('initialize'))
11
15
  * initialize()
12
16
  * initialize()
13
17
  * // => `createApplication` is invoked once
14
18
  */
15
- import { before } from '@function/before';
16
19
 
17
- export function once<TFunc extends (...args: Parameters<TFunc>) => ReturnType<TFunc>>(func: TFunc): TFunc {
20
+ export function once<TFunc extends GenericFunction<TFunc>>(func: TFunc): TFunc {
18
21
  return before(1, func);
19
22
  }
@@ -1,8 +1,10 @@
1
+ import type { GenericFunction } from 'src/types.js';
2
+
1
3
  import { debounce } from '@function/debounce';
2
4
 
3
- export function throttle<T extends (...args: Parameters<T>) => ReturnType<T>>(
4
- func: T, wait = 0, options: { leading?: boolean, trailing?: boolean } = {}
5
- ): (this: ThisParameterType<T>, ...args: Parameters<T>) => ReturnType<T> {
5
+ export function throttle<TFunc extends GenericFunction<TFunc>>(
6
+ func: TFunc, wait = 0, options: { leading?: boolean, trailing?: boolean } = {}
7
+ ): (this: ThisParameterType<TFunc>, ...args: Parameters<TFunc>) => ReturnType<TFunc> {
6
8
  return debounce(func, wait, {
7
9
  leading: options.leading ?? true,
8
10
  maxWait: wait,
@@ -1,4 +1,36 @@
1
- export function isEmpty(value: unknown): boolean {
1
+ /**
2
+ * Checks if `value` is an empty object, collection, map, or set.
3
+ *
4
+ * Objects are considered empty if they have no own enumerable string keyed
5
+ * properties.
6
+ *
7
+ * Array-like values such as `arguments` objects, arrays, buffers, strings, or
8
+ * Similarly, maps and sets are considered empty if they have a `size` of `0`.
9
+ *
10
+ * @category Lang
11
+ * @param value - The value to check.
12
+ * @returns Returns `true` if `value` is empty, else `false`.
13
+ * @example
14
+ * isEmpty(null)
15
+ * // => true
16
+ *
17
+ * isEmpty({})
18
+ * // => true
19
+ *
20
+ * isEmpty("")
21
+ * // => true
22
+ *
23
+ * isEmpty([1, 2, 3])
24
+ * // => false
25
+ *
26
+ * isEmpty('abc')
27
+ * // => false
28
+ *
29
+ * isEmpty({ 'a': 1 })
30
+ * // => false
31
+ */
32
+
33
+ export function isEmpty(value: string | object | null | undefined): boolean {
2
34
  if (value === null || value === undefined) {
3
35
  return true;
4
36
  }
@@ -7,10 +39,6 @@ export function isEmpty(value: unknown): boolean {
7
39
  return value.length === 0;
8
40
  }
9
41
 
10
- if (typeof value === 'number') {
11
- return false;
12
- }
13
-
14
42
  if (value instanceof Map || value instanceof Set) {
15
43
  return value.size === 0;
16
44
  }
@@ -1,5 +1,31 @@
1
1
  import type { RecordKey } from '../types';
2
2
 
3
+
4
+ /**
5
+ * Performs a deep comparison between two values to determine if they are
6
+ * equivalent.
7
+ *
8
+ * **Note:** This method supports comparing arrays, array buffers, booleans,
9
+ * date objects, error objects, maps, numbers, `Object` objects, regexes,
10
+ * sets, strings, symbols, and typed arrays. `Object` objects are compared
11
+ * by their own, not inherited, enumerable properties. Functions and DOM
12
+ * nodes are compared by strict equality, i.e. `===`.
13
+ *
14
+ * @category Lang
15
+ * @param value1 - The value to compare.
16
+ * @param value2 - The other value to compare.
17
+ * @returns Returns `true` if the values are equivalent, else `false`.
18
+ * @example
19
+ * var object = { 'a': 1 };
20
+ * var other = { 'a': 1 };
21
+ *
22
+ * _.isEqual(object, other);
23
+ * // => true
24
+ *
25
+ * object === other;
26
+ * // => false
27
+ */
28
+
3
29
  export function isEqual(value1: unknown, value2: unknown): boolean {
4
30
  if (value1 === value2) return true;
5
31
 
@@ -1,5 +1,34 @@
1
1
  import { isEqual } from '@lang/isEqual';
2
2
 
3
- export function isEqualWith<T>(customizer: (value: T) => unknown, a: T, b: T): boolean {
3
+ /**
4
+ * This method is like `_.isEqual` except that it accepts `customizer` which
5
+ * is invoked to compare values. If `customizer` returns `undefined`, comparisons
6
+ * are handled by the method instead. The `customizer` is invoked with up to
7
+ * six arguments: (objValue, othValue [, index|key, object, other, stack]).
8
+ *
9
+ * @category Lang
10
+ * @param value1 - The value to compare.
11
+ * @param value2 - The other value to compare.
12
+ * @param customizer - The function to customize comparisons.
13
+ * @returns Returns `true` if the values are equivalent, else `false`.
14
+ * @example
15
+ * function isGreeting(value) {
16
+ * return /^h(?:i|ello)$/.test(value);
17
+ * }
18
+ *
19
+ * function customizer(objValue, othValue) {
20
+ * if (isGreeting(objValue) && isGreeting(othValue)) {
21
+ * return true;
22
+ * }
23
+ * }
24
+ *
25
+ * var array = ['hello', 'goodbye'];
26
+ * var other = ['hi', 'goodbye'];
27
+ *
28
+ * isEqualWith(array, other, customizer);
29
+ * // => true
30
+ */
31
+
32
+ export function isEqualWith<T>(a: T, b: T, customizer: (value: T) => unknown): boolean {
4
33
  return isEqual(customizer(a), customizer(b));
5
34
  }
@@ -1,16 +1,15 @@
1
1
  /**
2
2
  * Creates an object composed of the picked `object` properties.
3
3
  *
4
- * @category Object
5
- * @param object The source object.
6
- * @param keys The property paths to pick.
7
- * @returns {Object} Returns the new object.
8
4
  * @example
9
- *
10
5
  * const object = { 'a': 1, 'b': '2', 'c': 3 }
11
6
  *
12
7
  * pick(object, ['a', 'c'])
13
8
  * // => { 'a': 1, 'c': 3 }
9
+ * @category Object
10
+ * @param object - The source object.
11
+ * @param keys - The property paths to pick.
12
+ * @returns Returns the new object.
14
13
  */
15
14
 
16
15
  export function pick<T, K extends keyof T>(object: T, keys: K[]): Pick<T, K> {
@@ -1,5 +1,20 @@
1
1
  import { splitWords } from '@helpers/stringModifiers';
2
2
 
3
+ /**
4
+ * Converts `string` to camelCase.
5
+ *
6
+ * @example
7
+ * camelCase('Foo Bar')
8
+ * // => 'fooBar'
9
+ * camelCase('--foo-bar--')
10
+ * // => 'fooBar'
11
+ * camelCase('__FOO_BAR__')
12
+ * // => 'fooBar'
13
+ * @category String
14
+ * @param str - The string to convert.
15
+ * @returns Returns the camel cased string.
16
+ */
17
+
3
18
  export function camelCase(str: string): string {
4
19
  const words = splitWords(str);
5
20
 
@@ -1,3 +1,14 @@
1
+ /**
2
+ * Converts the first character of a string to upper case and the remaining to lower case.
3
+ *
4
+ * @example
5
+ * capitalize('FRED')
6
+ * // => 'Fred'
7
+ * @category String
8
+ * @param str - The string to capitalize.
9
+ * @returns Returns the capitalized string.
10
+ */
11
+
1
12
  export function capitalize(str: string): string {
2
13
  return str.charAt(0).toUpperCase() + str.slice(1);
3
14
  }
@@ -1,3 +1,18 @@
1
+ /**
2
+ * Deburrs a string by converting
3
+ * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
4
+ * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
5
+ * letters to basic Latin letters and removing
6
+ * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
7
+ *
8
+ * @example
9
+ * deburr('déjà vu')
10
+ * // => 'deja vu'
11
+ * @category String
12
+ * @param str - The string to deburr.
13
+ * @returns Returns the deburred string.
14
+ */
15
+
1
16
  export function deburr(str: string): string {
2
17
  // eslint-disable-next-line no-control-regex
3
18
  return str.replace(/[^\u0000-\u007E]/g, (chr: string) =>
@@ -1,3 +1,14 @@
1
+ /**
2
+ * Converts the characters `&`, `<`, `>`, `"` and `'` in a string to their corresponding HTML entities.
3
+ *
4
+ * @example
5
+ * escape('fred, barney, & pebbles')
6
+ * // => 'fred, barney, &amp; pebbles'
7
+ * @category String
8
+ * @param str - The string to escape.
9
+ * @returns Returns the escaped string.
10
+ */
11
+
1
12
  export function escape(str: string): string {
2
13
  const escapeChars: Record<string, string> = {
3
14
  '&': '&amp;',
@@ -1,3 +1,15 @@
1
+ /**
2
+ * Escapes the `RegExp` special characters `^`, `$`, `\`, `.`, `*`, `+`,
3
+ * `?`, `(`, `)`, `[`, `]`, `{`, `}`, and `|` in a string.
4
+ *
5
+ * @example
6
+ * escapeRegExp('[moderndash](https://moderndash.io/)')
7
+ * // => '\[moderndash\]\(https://moderndash\.io/\)'
8
+ * @category String
9
+ * @param str - The string to escape.
10
+ * @returns Returns the escaped string.
11
+ */
12
+
1
13
  export function escapeRegExp(str: string): string {
2
14
  return str.replace(/[$()*+.?[\\\]^{|}]/g, '\\$&');
3
15
  }
@@ -1,5 +1,20 @@
1
1
  import { splitWords } from '@helpers/stringModifiers';
2
2
 
3
+ /**
4
+ * Converts a string to kebab-case.
5
+ *
6
+ * @example
7
+ * kebabCase('Foo Bar')
8
+ * // => 'foo-bar'
9
+ * kebabCase('fooBar')
10
+ * // => 'foo-bar'
11
+ * kebabCase('__FOO_BAR__')
12
+ * // => 'foo-bar'
13
+ * @category String
14
+ * @param str - The string to convert.
15
+ * @returns Returns the kebab cased string.
16
+ */
17
+
3
18
  export function kebabCase(str: string): string {
4
19
  const words = splitWords(str);
5
20
  let kebabCase = '';
@@ -1,5 +1,21 @@
1
1
  import { splitWords } from '@helpers/stringModifiers';
2
2
 
3
+
4
+ /**
5
+ * Converts a string to PascalCase.
6
+ *
7
+ * @example
8
+ * kebabCase('Foo Bar')
9
+ * // => 'FooBar'
10
+ * kebabCase('fooBar')
11
+ * // => 'FooBar'
12
+ * kebabCase('__FOO_BAR__')
13
+ * // => 'FooBar'
14
+ * @category String
15
+ * @param str - The string to convert.
16
+ * @returns Returns the pascal cased string.
17
+ */
18
+
3
19
  export function pascalCase(str: string): string {
4
20
  const words = splitWords(str);
5
21
  let pascalCase = '';
@@ -1,5 +1,22 @@
1
1
  import { splitWords } from '@helpers/stringModifiers';
2
2
 
3
+ /**
4
+ * Converts a string to snake_case.
5
+ *
6
+ * @example
7
+ * snakeCase('Foo Bar')
8
+ * // => 'foo_bar'
9
+ * snakeCase('fooBar')
10
+ * // => 'foo_bar'
11
+ * snakeCase('--FOO-BAR--')
12
+ * // => 'foo_bar'
13
+ * snakeCase('foo2bar')
14
+ * // => 'foo_2_bar'
15
+ * @category String
16
+ * @param str - The string to convert.
17
+ * @returns Returns the snake cased string.
18
+ */
19
+
3
20
  export function snakeCase(str: string): string {
4
21
  const words = splitWords(str);
5
22
  let snakeCase = '';
@@ -1,5 +1,20 @@
1
1
  import { splitWords } from '@helpers/stringModifiers';
2
2
 
3
+ /**
4
+ * Converts a string to Start Case.
5
+ *
6
+ * @example
7
+ * startCase('--foo-bar--')
8
+ * // => 'Foo Bar'
9
+ * startCase('fooBar')
10
+ * // => 'Foo Bar'
11
+ * startCase('__FOO_BAR__')
12
+ * // => 'Foo Bar'
13
+ * @category String
14
+ * @param str - The string to convert.
15
+ * @returns Returns the start cased string.
16
+ */
17
+
3
18
  export function startCase(str: string): string {
4
19
  const words = splitWords(str);
5
20
  let startCase = '';
@@ -1,5 +1,16 @@
1
1
  import { deburr } from '@string/deburr';
2
2
 
3
+ /**
4
+ * Removes all special characters from a string.
5
+ *
6
+ * @example
7
+ * stripSpecialChars('Héllo! World #$%&*!')
8
+ * // => 'Hello World'
9
+ * @category String
10
+ * @param str - The string to remove special characters from.
11
+ * @returns Returns the string with special characters removed.
12
+ */
13
+
3
14
  export function stripSpecialChars(str: string): string {
4
15
  str = deburr(str);
5
16
  return str.replace(/[^\s\w]/gi, '');