moderndash 0.0.16 → 0.0.18

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 (66) hide show
  1. package/README.md +16 -75
  2. package/dist/index.cjs +66 -73
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.ts +125 -113
  5. package/dist/index.js +62 -69
  6. package/dist/index.js.map +1 -1
  7. package/package.json +6 -5
  8. package/src/array/chunk.ts +0 -31
  9. package/src/array/difference.ts +0 -21
  10. package/src/array/differenceBy.ts +0 -30
  11. package/src/array/differenceWith.ts +0 -31
  12. package/src/array/dropRightWhile.ts +0 -28
  13. package/src/array/dropWhile.ts +0 -24
  14. package/src/array/index.ts +0 -21
  15. package/src/array/intersection.ts +0 -20
  16. package/src/array/intersectionBy.ts +0 -26
  17. package/src/array/intersectionWith.ts +0 -33
  18. package/src/array/sample.ts +0 -18
  19. package/src/array/sampleSize.ts +0 -31
  20. package/src/array/shuffle.ts +0 -33
  21. package/src/array/takeRightWhile.ts +0 -33
  22. package/src/array/takeWhile.ts +0 -33
  23. package/src/array/uniq.ts +0 -18
  24. package/src/array/uniqBy.ts +0 -25
  25. package/src/array/uniqWith.ts +0 -20
  26. package/src/array/unzip.ts +0 -20
  27. package/src/array/unzipWith.ts +0 -26
  28. package/src/array/zip.ts +0 -17
  29. package/src/array/zipWith.ts +0 -28
  30. package/src/collection/countBy.ts +0 -38
  31. package/src/collection/groupBy.ts +0 -32
  32. package/src/collection/index.ts +0 -3
  33. package/src/collection/sortBy.ts +0 -15
  34. package/src/function/after.ts +0 -29
  35. package/src/function/before.ts +0 -31
  36. package/src/function/debounce.ts +0 -125
  37. package/src/function/index.ts +0 -7
  38. package/src/function/memoize.ts +0 -63
  39. package/src/function/once.ts +0 -22
  40. package/src/function/throttle.ts +0 -13
  41. package/src/function/times.ts +0 -24
  42. package/src/helpers/collections.ts +0 -5
  43. package/src/helpers/shortHands.ts +0 -17
  44. package/src/helpers/stringModifiers.ts +0 -18
  45. package/src/helpers/typeofChecks.ts +0 -3
  46. package/src/index.ts +0 -7
  47. package/src/lang/index.ts +0 -4
  48. package/src/lang/isEmpty.ts +0 -51
  49. package/src/lang/isEqual.ts +0 -80
  50. package/src/lang/isEqualWith.ts +0 -34
  51. package/src/lang/isPlainObject.ts +0 -3
  52. package/src/object/index.ts +0 -1
  53. package/src/object/pick.ts +0 -21
  54. package/src/string/camelCase.ts +0 -30
  55. package/src/string/capitalize.ts +0 -14
  56. package/src/string/deburr.ts +0 -20
  57. package/src/string/escape.ts +0 -21
  58. package/src/string/escapeRegExp.ts +0 -15
  59. package/src/string/index.ts +0 -11
  60. package/src/string/kebabCase.ts +0 -25
  61. package/src/string/pascalCase.ts +0 -26
  62. package/src/string/snakeCase.ts +0 -30
  63. package/src/string/startCase.ts +0 -25
  64. package/src/string/stripSpecialChars.ts +0 -17
  65. package/src/string/unescape.ts +0 -22
  66. package/src/types.ts +0 -15
@@ -1,31 +0,0 @@
1
- /**
2
- * Creates a function that invokes `func`, while it's called less than `n` times. Subsequent
3
- * calls to the created function return the result of the last `func` invocation.
4
- *
5
- * @category Function
6
- * @param n - The number of calls at which `func` is no longer invoked.
7
- * @param func - The function to restrict.
8
- * @returns Returns the new restricted function.
9
- * @example
10
- * const caution = () => console.log("Caution!");
11
- *
12
- * // Only call caution two times
13
- * const reducedCaution = before(2, caution)
14
- *
15
- * reducedCaution()
16
- * reducedCaution()
17
- * reducedCaution()
18
- * // => `caution` is invoked twice
19
- */
20
-
21
- export function before<TFunc extends (...args: Parameters<TFunc>) => ReturnType<TFunc>>(n: number, func: TFunc): TFunc {
22
- let count = 0;
23
- let result: ReturnType<TFunc>;
24
- return ((...args: Parameters<TFunc>): ReturnType<TFunc> => {
25
- if (count < n) {
26
- count += 1;
27
- result = func(...args);
28
- }
29
- return result;
30
- }) as TFunc;
31
- }
@@ -1,125 +0,0 @@
1
- import type { GenericFunction } from 'src/types.js';
2
-
3
- // TODO this is a port from lodash, it probably can be improved and shortened, also fix TS errors
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>;
10
- let timerId: ReturnType<typeof setTimeout> | undefined;
11
- let lastCallTime: number | undefined;
12
- let lastInvokeTime = 0;
13
- const maxing = options.maxWait ?? false;
14
- const leading = options.leading ?? false;
15
- const trailing = options.trailing ?? true;
16
- const maxWait = options.maxWait ?? 0;
17
-
18
- function invokeFunc(time: number) {
19
- const args: Parameters<TFunc> | undefined = lastArgs;
20
- const thisArg: ThisParameterType<TFunc> | undefined = lastThis;
21
-
22
- lastArgs = lastThis = undefined;
23
- lastInvokeTime = time;
24
- // @ts-expect-error
25
- result = fn.apply(thisArg, args);
26
- return result;
27
- }
28
-
29
- function leadingEdge(time: number) {
30
- // Reset any `maxWait` timer.
31
- lastInvokeTime = time;
32
- // Start the timer for the trailing edge.
33
- timerId = setTimeout(timerExpired, wait);
34
- // Invoke the leading edge.
35
- return leading ? invokeFunc(time) : result;
36
- }
37
-
38
- function remainingWait(time: number) {
39
- // @ts-expect-error
40
- const timeSinceLastCall = time - lastCallTime;
41
- const timeSinceLastInvoke = time - lastInvokeTime;
42
- const timeWaiting = wait - timeSinceLastCall;
43
-
44
- return maxing
45
- ? Math.min(timeWaiting, maxWait - timeSinceLastInvoke)
46
- : timeWaiting;
47
- }
48
-
49
- function shouldInvoke(time: number) {
50
- if (lastCallTime === undefined)
51
- return true;
52
-
53
- const timeSinceLastCall = time - lastCallTime;
54
- const timeSinceLastInvoke = time - lastInvokeTime;
55
-
56
- // Either this is the first call, activity has stopped and we're at the
57
- // trailing edge, the system time has gone backwards and we're treating
58
- // it as the trailing edge, or we've hit the `maxWait` limit.
59
- return timeSinceLastCall >= wait || timeSinceLastCall < 0 || (maxing && timeSinceLastInvoke >= maxWait);
60
- }
61
-
62
- function timerExpired() {
63
- const time = Date.now();
64
- if (shouldInvoke(time)) {
65
- return trailingEdge(time);
66
- }
67
- // Restart the timer.
68
- timerId = setTimeout(timerExpired, remainingWait(time));
69
- }
70
-
71
- function trailingEdge(time: number) {
72
- timerId = undefined;
73
-
74
- // Only invoke if we have `lastArgs` which means `fn` has been
75
- // debounced at least once.
76
- if (trailing && lastArgs) {
77
- return invokeFunc(time);
78
- }
79
- lastArgs = lastThis = undefined;
80
- return result;
81
- }
82
-
83
- function cancel() {
84
- if (timerId !== undefined) {
85
- clearTimeout(timerId);
86
- }
87
- lastInvokeTime = 0;
88
- lastArgs = lastCallTime = lastThis = timerId = undefined;
89
- }
90
-
91
- function flush() {
92
- return timerId === undefined ? result : trailingEdge(Date.now());
93
- }
94
-
95
- function debounced(this: ThisParameterType<TFunc>, ...args: Parameters<TFunc>): ReturnType<TFunc> {
96
- const time = Date.now();
97
- const isInvoking = shouldInvoke(time);
98
-
99
- lastArgs = args;
100
- // TODO Fix this assignment
101
- // eslint-disable-next-line @typescript-eslint/no-this-alias,unicorn/no-this-assignment
102
- lastThis = this;
103
- lastCallTime = time;
104
-
105
- if (isInvoking) {
106
- if (timerId === undefined) {
107
- return leadingEdge(lastCallTime);
108
- }
109
- if (maxing) {
110
- // Handle invocations in a tight loop.
111
- clearTimeout(timerId);
112
- timerId = setTimeout(timerExpired, wait);
113
- return invokeFunc(lastCallTime);
114
- }
115
- }
116
- if (timerId === undefined) {
117
- timerId = setTimeout(timerExpired, wait);
118
- }
119
- return result;
120
- }
121
-
122
- debounced.cancel = cancel;
123
- debounced.flush = flush;
124
- return debounced;
125
- }
@@ -1,7 +0,0 @@
1
- export * from './after';
2
- export * from './before';
3
- export * from './debounce';
4
- export * from './memoize';
5
- export * from './once';
6
- export * from './throttle';
7
- export * from './times';
@@ -1,63 +0,0 @@
1
- import type{ GenericFunction } from 'src/types.js';
2
-
3
- const defaultResolver = (...args: unknown[]) => JSON.stringify(args);
4
-
5
- /**
6
- * Creates a function that memoizes the result of `func`. If `resolver` is
7
- * provided, it determines the cache key for storing the result based on the
8
- * arguments provided to the memoized function. By default, all arguments
9
- * provided to the memoized function are used as the map cache key.
10
- *
11
- * **Note:** The cache is exposed as the `cache` property on the memoized
12
- * function. Its creation may be customized by replacing the `memoize.Cache`
13
- * constructor with one whose instances implement the
14
- * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
15
- * method interface of `clear`, `delete`, `get`, `has`, and `set`.
16
- *
17
- * @category Function
18
- * @param func - The function to have its output memoized.
19
- * @param resolver - The function to resolve the cache key.
20
- * @typeParam TFunc - The input function type
21
- * @typeParam Cache - The cache map type
22
- * @returns Returns the new memoized function.
23
- * @example
24
- * const object = \{ 'a': 1, 'b': 2 \}
25
- *
26
- * const values = memoize(values)
27
- * values(object)
28
- * // => [1, 2]
29
- *
30
- * values(object)
31
- * // => [1, 2]
32
- *
33
- * object.a = 2
34
- * values(object)
35
- * // => [2, 2]
36
- *
37
- * // Modify the result cache.
38
- * values.cache.set(object, ['a', 'b'])
39
- * values(object)
40
- * // => ['a', 'b']
41
- *
42
- * // Replace `memoize.Cache`.
43
- * memoize.Cache = WeakMap
44
- */
45
-
46
- export function memoize<TFunc extends GenericFunction<TFunc>, Cache extends Map<string | symbol, ReturnType<TFunc>>>(
47
- func: TFunc, resolver: ((...args: Parameters<TFunc>) => string | symbol) = defaultResolver
48
- ): TFunc & { cache: Cache } {
49
-
50
- const cache = new Map() as Cache;
51
- const memoizedFunc = (...args: Parameters<TFunc>): ReturnType<TFunc> => {
52
- const key = resolver(...args);
53
- if (cache.has(key)) {
54
- // eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style
55
- return cache.get(key) as ReturnType<TFunc>;
56
- }
57
- const result = func(...args);
58
- cache.set(key, result);
59
- return result;
60
- };
61
- memoizedFunc.cache = cache;
62
- return memoizedFunc as TFunc & { cache: Cache };
63
- }
@@ -1,22 +0,0 @@
1
- import type { GenericFunction } from 'src/types.js';
2
-
3
- import { before } from '@function/before';
4
-
5
- /**
6
- * Creates a function that is restricted to invoking `func` once. Repeat calls
7
- * to the function return the value of the first invocation. The `func` is
8
- * invoked with the `this` binding and arguments of the created function.
9
- *
10
- * @category Function
11
- * @param func - The function to restrict.
12
- * @returns Returns the new restricted function.
13
- * @example
14
- * const initialize = once(() => console.log('initialize'))
15
- * initialize()
16
- * initialize()
17
- * // => `createApplication` is invoked once
18
- */
19
-
20
- export function once<TFunc extends GenericFunction<TFunc>>(func: TFunc): TFunc {
21
- return before(1, func);
22
- }
@@ -1,13 +0,0 @@
1
- import type { GenericFunction } from 'src/types.js';
2
-
3
- import { debounce } from '@function/debounce';
4
-
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> {
8
- return debounce(func, wait, {
9
- leading: options.leading ?? true,
10
- maxWait: wait,
11
- trailing: options.trailing ?? true
12
- });
13
- }
@@ -1,24 +0,0 @@
1
- /**
2
- * Invokes the iteratee `n` times, returning an array of the results of
3
- * each invocation. The function is invoked with one argument: (index).
4
- *
5
- * @example
6
- * times(3, index => console.log("Run", index)))
7
- * // => "Run 0" | "Run 1" | "Run 2"
8
- * times(3, Math.random)
9
- * // => [0.123, 0.456, 0.789]
10
- * times(4, () => 0)
11
- * // => [0, 0, 0, 0]
12
- * @category Function
13
- * @param n - The number of times to invoke `func`.
14
- * @param iteratee - The function invoked per iteration.
15
- * @returns Returns the array of results.
16
- */
17
-
18
- export function times<T>(n: number, func: (index: number) => T): T[] {
19
- const result: T[] = [];
20
- for (let i = 0; i < n; i++) {
21
- result.push(func(i));
22
- }
23
- return result;
24
- }
@@ -1,5 +0,0 @@
1
- import type { ArrayOrRecord } from '../types';
2
-
3
- export function getValuesFromCollection<T>(collection: ArrayOrRecord<T>): T[] {
4
- return Array.isArray(collection) ? collection : Object.values(collection);
5
- }
@@ -1,17 +0,0 @@
1
- import type { IterateeFunction, PropertyShorthand } from '../types';
2
-
3
- import { isObjectKey } from '@helpers/typeofChecks';
4
-
5
- export function getPropertyShorthand<T, K extends keyof T>(key: K): (object: T) => T[K] {
6
- return object => object[key];
7
- }
8
-
9
- export function getIterateFunction<T>(iteratee: IterateeFunction<T> | PropertyShorthand<T>) {
10
- if (typeof iteratee === 'function') {
11
- return iteratee;
12
- } else if (isObjectKey(iteratee)) {
13
- return getPropertyShorthand(iteratee);
14
- } else {
15
- throw new TypeError('Expected iteratee to be a function or a property name');
16
- }
17
- }
@@ -1,18 +0,0 @@
1
- import { deburr } from '@string/deburr';
2
-
3
- export function splitWords(str: string): string[] {
4
- str = deburr(str);
5
-
6
- // Split non-alphanumeric characters with spaces and deal with camel/PascalCase
7
- const regex = new RegExp(
8
- '[^\\dA-Za-z]' + // match any character that is not a letter or a digit
9
- '|' + // or
10
- '(?<=[a-z])' + // lookbehind for a lowercase letter
11
- '(?=[A-Z])' + // lookahead for an uppercase letter
12
- '|' + // or
13
- '(?<=[A-Z])' + // lookbehind for an uppercase letter
14
- '(?=[A-Z][a-z])' // lookahead for an uppercase letter followed by a lowercase letter
15
- );
16
-
17
- return str.split(regex).filter(Boolean);
18
- }
@@ -1,3 +0,0 @@
1
- export function isObjectKey(key: unknown): key is keyof object {
2
- return typeof key === 'string' || typeof key === 'number' || typeof key === 'symbol';
3
- }
package/src/index.ts DELETED
@@ -1,7 +0,0 @@
1
- export * from './array';
2
- export * from './collection';
3
- export * from './function';
4
- export * from './lang';
5
- export * from './object';
6
- export * from './string';
7
- export * from './types';
package/src/lang/index.ts DELETED
@@ -1,4 +0,0 @@
1
- export * from './isEmpty';
2
- export * from './isEqual';
3
- export * from './isEqualWith';
4
- export * from './isPlainObject';
@@ -1,51 +0,0 @@
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 {
34
- if (value === null || value === undefined) {
35
- return true;
36
- }
37
-
38
- if (typeof value === 'string' || Array.isArray(value)) {
39
- return value.length === 0;
40
- }
41
-
42
- if (value instanceof Map || value instanceof Set) {
43
- return value.size === 0;
44
- }
45
-
46
- if (typeof value === 'object') {
47
- return Object.keys(value).length === 0;
48
- }
49
-
50
- return false;
51
- }
@@ -1,80 +0,0 @@
1
- import type { RecordKey } from '../types';
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
-
29
- export function isEqual(value1: unknown, value2: unknown): boolean {
30
- if (value1 === value2) return true;
31
-
32
- if (Array.isArray(value1) && Array.isArray(value2)) {
33
- return isSameArray(value1, value2);
34
- }
35
-
36
- if (value1 instanceof RegExp && value2 instanceof RegExp) {
37
- return value1.toString() === value2.toString();
38
- }
39
-
40
- if (isObject(value1) && isObject(value2)) {
41
- return isSameObject(value1, value2);
42
- }
43
-
44
- return false;
45
- }
46
-
47
- type KeyValueObject = Record<RecordKey, unknown>;
48
- function isObject(value: unknown): value is KeyValueObject {
49
- return typeof value === 'object'
50
- && value !== null
51
- && !Array.isArray(value)
52
- && Object.prototype.toString.call(value) === '[object Object]';
53
- }
54
-
55
- function isSameObject(value1: KeyValueObject, value2: KeyValueObject) {
56
- // check if the objects have the same keys
57
- const keys1 = Object.keys(value1);
58
- const keys2 = Object.keys(value2);
59
- if (!isEqual(keys1, keys2)) return false;
60
-
61
- // check if the values of each key in the objects are equal
62
- for (const key of keys1) {
63
- if (!isEqual(value1[key], value2[key])) return false;
64
- }
65
-
66
- // the objects are deeply equal
67
- return true;
68
- }
69
-
70
- function isSameArray(value1: unknown[], value2: unknown[]) {
71
- // check if the arrays have the same length
72
- if (value1.length !== value2.length) return false;
73
-
74
- // check if the values of each element in the arrays are equal
75
- for (const [i, element] of value1.entries()) {
76
- if (!isEqual(element, value2[i])) return false;
77
- }
78
-
79
- return true;
80
- }
@@ -1,34 +0,0 @@
1
- import { isEqual } from '@lang/isEqual';
2
-
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 {
33
- return isEqual(customizer(a), customizer(b));
34
- }
@@ -1,3 +0,0 @@
1
- export function isPlainObject(value: unknown): value is object {
2
- return value !== null && typeof value === 'object' && value.constructor === Object;
3
- }
@@ -1 +0,0 @@
1
- export * from './pick';
@@ -1,21 +0,0 @@
1
- /**
2
- * Creates an object composed of the picked `object` properties.
3
- *
4
- * @example
5
- * const object = { 'a': 1, 'b': '2', 'c': 3 }
6
- *
7
- * pick(object, ['a', 'c'])
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.
13
- */
14
-
15
- export function pick<T, K extends keyof T>(object: T, keys: K[]): Pick<T, K> {
16
- const result = {} as Pick<T, K>;
17
- for (const key of keys) {
18
- result[key] = object[key];
19
- }
20
- return result;
21
- }
@@ -1,30 +0,0 @@
1
- import { splitWords } from '@helpers/stringModifiers';
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
-
18
- export function camelCase(str: string): string {
19
- const words = splitWords(str);
20
-
21
- // Capitalize the first letter of each word
22
- const camelCase = words.map((word, index) => {
23
- if (index === 0) {
24
- return word.toLowerCase();
25
- }
26
- return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
27
- });
28
-
29
- return camelCase.join('');
30
- }
@@ -1,14 +0,0 @@
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
-
12
- export function capitalize(str: string): string {
13
- return str.charAt(0).toUpperCase() + str.slice(1);
14
- }
@@ -1,20 +0,0 @@
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
-
16
- export function deburr(str: string): string {
17
- // eslint-disable-next-line no-control-regex
18
- return str.replace(/[^\u0000-\u007E]/g, (chr: string) =>
19
- chr.normalize('NFD').replace(/[\u0300-\u036F]/g, ''));
20
- }
@@ -1,21 +0,0 @@
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
-
12
- export function escape(str: string): string {
13
- const escapeChars: Record<string, string> = {
14
- '&': '&amp;',
15
- '<': '&lt;',
16
- '>': '&gt;',
17
- '\'': '&#39;',
18
- '"': '&quot;'
19
- };
20
- return str.replace(/["&'<>]/g, char => escapeChars[char] || char);
21
- }
@@ -1,15 +0,0 @@
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
-
13
- export function escapeRegExp(str: string): string {
14
- return str.replace(/[$()*+.?[\\\]^{|}]/g, '\\$&');
15
- }
@@ -1,11 +0,0 @@
1
- export * from './camelCase';
2
- export * from './capitalize';
3
- export * from './deburr';
4
- export * from './escape';
5
- export * from './escapeRegExp';
6
- export * from './kebabCase';
7
- export * from './pascalCase';
8
- export * from './snakeCase';
9
- export * from './startCase';
10
- export * from './stripSpecialChars';
11
- export * from './unescape';