@catstral/levy-utils 1.0.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.
Files changed (52) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +912 -0
  3. package/dist/array/index.d.ts +7 -0
  4. package/dist/array/utils/cluster/index.d.ts +17 -0
  5. package/dist/array/utils/counting/index.d.ts +15 -0
  6. package/dist/array/utils/fork/index.d.ts +14 -0
  7. package/dist/array/utils/list/index.d.ts +65 -0
  8. package/dist/array/utils/select/index.d.ts +14 -0
  9. package/dist/array/utils/sift/index.d.ts +11 -0
  10. package/dist/array/utils/toggle/index.d.ts +34 -0
  11. package/dist/callback/index.d.ts +3 -0
  12. package/dist/callback/utils/chain/index.d.ts +31 -0
  13. package/dist/callback/utils/defer/index.d.ts +9 -0
  14. package/dist/callback/utils/retry/index.d.ts +30 -0
  15. package/dist/error.d.ts +4 -0
  16. package/dist/index.d.ts +8 -0
  17. package/dist/levyUtils.cjs +5 -0
  18. package/dist/levyUtils.js +1198 -0
  19. package/dist/misc/index.d.ts +5 -0
  20. package/dist/misc/utils/compute/index.d.ts +24 -0
  21. package/dist/misc/utils/isEmpty/index.d.ts +19 -0
  22. package/dist/misc/utils/isPrimitive/index.d.ts +18 -0
  23. package/dist/misc/utils/range/index.d.ts +89 -0
  24. package/dist/misc/utils/sleep/index.d.ts +9 -0
  25. package/dist/number/index.d.ts +2 -0
  26. package/dist/number/utils/toFloat/index.d.ts +10 -0
  27. package/dist/number/utils/toInt/index.d.ts +12 -0
  28. package/dist/object/index.d.ts +5 -0
  29. package/dist/object/utils/entries/index.d.ts +7 -0
  30. package/dist/object/utils/isObject/index.d.ts +9 -0
  31. package/dist/object/utils/keys/index.d.ts +4 -0
  32. package/dist/object/utils/omit/index.d.ts +12 -0
  33. package/dist/object/utils/pick/index.d.ts +12 -0
  34. package/dist/string/casing/index.d.ts +11 -0
  35. package/dist/string/casing/internal/splitCasing/index.d.ts +59 -0
  36. package/dist/string/casing/utils/camel/index.d.ts +27 -0
  37. package/dist/string/casing/utils/capitalize/index.d.ts +13 -0
  38. package/dist/string/casing/utils/custom/index.d.ts +42 -0
  39. package/dist/string/casing/utils/http/index.d.ts +27 -0
  40. package/dist/string/casing/utils/kebab/index.d.ts +48 -0
  41. package/dist/string/casing/utils/lower/index.d.ts +13 -0
  42. package/dist/string/casing/utils/pascal/index.d.ts +31 -0
  43. package/dist/string/casing/utils/snake/index.d.ts +48 -0
  44. package/dist/string/casing/utils/title/index.d.ts +27 -0
  45. package/dist/string/casing/utils/uncapitalize/index.d.ts +13 -0
  46. package/dist/string/casing/utils/upper/index.d.ts +13 -0
  47. package/dist/string/index.d.ts +4 -0
  48. package/dist/string/utils/parseUrlParams/index.d.ts +4 -0
  49. package/dist/string/utils/slug/index.d.ts +1 -0
  50. package/dist/string/utils/textDifference/index.d.ts +133 -0
  51. package/dist/types.d.ts +3 -0
  52. package/package.json +63 -0
@@ -0,0 +1,4 @@
1
+ export declare function parseUrlParams(url: string): Record<string, string | undefined>;
2
+ export declare function parseUrlParams<const T extends Record<string, (value: string | undefined) => unknown>>(url: string, transform: T): {
3
+ [K in keyof T]: ReturnType<T[K]>;
4
+ };
@@ -0,0 +1 @@
1
+ export declare function slug(text: string): string;
@@ -0,0 +1,133 @@
1
+ /**
2
+ * @typedef TextDifferenceOptionsNodes
3
+ * @prop {true} raw If raw nodes should be returned instead of a constructed string
4
+ * @prop {boolean} [htmlAware] If the difference should be HTML aware
5
+ */
6
+ export type TextDifferenceOptionsNodes = {
7
+ /**
8
+ * If raw nodes should be returned instead of a constructed string
9
+ *
10
+ * @default false
11
+ */
12
+ raw: true;
13
+ /**
14
+ * If the difference should be HTML aware
15
+ *
16
+ * @default false
17
+ */
18
+ htmlAware?: boolean;
19
+ };
20
+ export type TextDifferenceTag = string | [string, string];
21
+ /**
22
+ * @typedef TextDifferenceOptionsStringContextTags
23
+ * @prop {string | [string, string]} [equal] The tag(s) to wrap around nodes that are considered as equal
24
+ * @prop {string | [string, string]} [insert] The tag(s) to wrap around nodes that are considered as inserted/new
25
+ * @prop {string | [string, string]} [delete] The tag(s) to wrap around nodes that are considered as deleted/removed
26
+ */
27
+ export type TextDifferenceOptionsStringTags = {
28
+ /**
29
+ * The tag(s) to wrap around nodes that are considered as equal.
30
+ *
31
+ * By default no tags are wrapped around equal nodes.
32
+ */
33
+ equal?: TextDifferenceTag;
34
+ /**
35
+ * The tag(s) to wrap around nodes that are considered as inserted/new.
36
+ */
37
+ insert?: TextDifferenceTag;
38
+ /**
39
+ * The tag(s) to wrap around nodes that are considered as deleted/removed.
40
+ */
41
+ delete?: TextDifferenceTag;
42
+ };
43
+ /**
44
+ * @typedef TextDifferenceOptionsStringContextTags
45
+ * @prop {TextDifferenceOptionsStringTags} [inlineContext] The tags to use when in a inline context for the diff
46
+ * @prop {TextDifferenceOptionsStringTags} [blockContext] The tags to use when in a block context for the diff
47
+ */
48
+ export type TextDifferenceOptionsStringContextTags = {
49
+ /**
50
+ * The tags to use when in a inline context for the diff.
51
+ */
52
+ inlineContext?: TextDifferenceOptionsStringTags;
53
+ /**
54
+ * The tags to use when in a block context for the diff.
55
+ */
56
+ blockContext?: TextDifferenceOptionsStringTags;
57
+ };
58
+ /**
59
+ * @typedef TextDifferenceOptionsString
60
+ * @prop {false} [raw] If raw nodes should be returned instead of a constructed string
61
+ * @prop {boolean} [htmlAware] If the difference should be HTML aware
62
+ * @prop {TextDifferenceOptionsStringContextTags | TextDifferenceOptionsStringTags} [tags] The tags to wrap around the diff
63
+ */
64
+ export type TextDifferenceOptionsString = {
65
+ /**
66
+ * If raw nodes should be returned instead of a constructed string
67
+ *
68
+ * @default false
69
+ */
70
+ raw?: false;
71
+ } & ({
72
+ /**
73
+ * If the difference should be HTML aware
74
+ *
75
+ * @default false
76
+ */
77
+ htmlAware?: false;
78
+ /**
79
+ * The tags to use to mark the diff
80
+ */
81
+ tags?: TextDifferenceOptionsStringTags;
82
+ } | {
83
+ /**
84
+ * If the difference should be HTML aware
85
+ *
86
+ * @default false
87
+ */
88
+ htmlAware: true;
89
+ /**
90
+ * The tags to use to mark the diff
91
+ */
92
+ tags?: TextDifferenceOptionsStringContextTags | TextDifferenceOptionsStringTags;
93
+ });
94
+ export type TextDifferenceNodeType = "EQUAL" | "INSERT" | "DELETE";
95
+ export type TextDifferenceNodeContext = "INLINE" | "BLOCK" | "UNKNOWN";
96
+ /**
97
+ * @typedef TextDifferenceNode
98
+ * @prop {"EQUAL" | "INSERT" | "DELETE"} type The operation type this node represents
99
+ * @prop {string} content The content this diff type applies for
100
+ * @prop {"INLINE" | "BLOCK" | "UNKNOWN"} context The HTML context this node is used in, this will always be `UNKNOWN` if `htmlAware` is not true
101
+ */
102
+ export type TextDifferenceNode = {
103
+ /**
104
+ * The operation type this node represents.
105
+ */
106
+ type: TextDifferenceNodeType;
107
+ /**
108
+ * The content this diff type applies for.
109
+ */
110
+ content: string;
111
+ /**
112
+ * The HTML context this node is used in, this will always be `UNKNOWN` if `htmlAware` is not true.
113
+ */
114
+ context: TextDifferenceNodeContext;
115
+ };
116
+ /**
117
+ * Turns 2 strings into a constructed string, showing the difference using tags wrapped around changes.
118
+ *
119
+ * @param {string} oldValue A string representing what the text used to be
120
+ * @param {string} newValue A string representing what the text has turned into
121
+ * @param {TextDifferenceOptionsString} [options] Options to tweak the result (see {@link TextDifferenceOptionsString} for more details)
122
+ * @returns {string} A constructed string based on the difference between the 2 given strings
123
+ */
124
+ export declare function textDifference(oldValue: string, newValue: string, options?: TextDifferenceOptionsString): string;
125
+ /**
126
+ * Turns 2 strings into a list of difference nodes containing the info needed to be able to construct/view a difference of the 2.
127
+ *
128
+ * @param {string} oldValue A string representing what the text used to be
129
+ * @param {string} newValue A string representing what the text has turned into
130
+ * @param {TextDifferenceOptionsNodes} [options] Options to tweak the result (see {@link TextDifferenceOptionsNodes} for more details)
131
+ * @returns {TextDifferenceNode[]} A list of raw nodes that represent the difference between the 2 given strings (see {@link TextDifferenceNode} for more details)
132
+ */
133
+ export declare function textDifference(oldValue: string, newValue: string, options?: TextDifferenceOptionsNodes): TextDifferenceNode[];
@@ -0,0 +1,3 @@
1
+ export type Key = string | number | symbol;
2
+ export type Falsy = false | 0 | 0n | "" | null | undefined;
3
+ export type Promisable<T> = T | Promise<T>;
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@catstral/levy-utils",
3
+ "version": "1.0.0",
4
+ "description": "Re-useable and common JS/TS utility functions",
5
+ "license": "MIT",
6
+ "contributors": [
7
+ {
8
+ "email": "levyvandervalk@gmail.com",
9
+ "name": "Levy van der Valk"
10
+ },
11
+ {
12
+ "email": "levypondman@live.nl",
13
+ "name": "Levy Pondman"
14
+ }
15
+ ],
16
+ "keywords": [
17
+ "javascript",
18
+ "typescript",
19
+ "util",
20
+ "utils",
21
+ "utility",
22
+ "utilities"
23
+ ],
24
+ "type": "module",
25
+ "sideEffects": false,
26
+ "files": [
27
+ "dist"
28
+ ],
29
+ "main": "dist/levyUtils.cjs",
30
+ "module": "dist/levyUtils.js",
31
+ "types": "dist/index.d.ts",
32
+ "exports": {
33
+ "types": "./dist/index.d.ts",
34
+ "import": "./dist/levyUtils.js",
35
+ "require": "./dist/levyUtils.cjs"
36
+ },
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/Catstral/levy-utils.git"
40
+ },
41
+ "scripts": {
42
+ "dev": "vite",
43
+ "compile": "tsc && bun test && vite build",
44
+ "preview": "vite preview",
45
+ "production": "bun compile && npm publish",
46
+ "tsc": "tsc --noEmit --diagnostics",
47
+ "lint": "biome check . --formatter-enabled=true",
48
+ "lint:apply": "biome check . --formatter-enabled=true --write",
49
+ "lint:apply:unsafe": "biome check . --formatter-enabled=true --write --unsafe",
50
+ "check": "bun tsc && bun lint"
51
+ },
52
+ "devDependencies": {
53
+ "@types/bun": "1.4.0",
54
+ "@biomejs/biome": "2.5.4",
55
+ "@types/diff-match-patch": "^1.0.36",
56
+ "typescript": "^7.0.0",
57
+ "vite": "^8.1.5",
58
+ "vite-plugin-dts": "^5.1.0"
59
+ },
60
+ "dependencies": {
61
+ "diff-match-patch": "^1.0.5"
62
+ }
63
+ }