clear-af.js 1.0.2 → 1.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.
@@ -1,42 +0,0 @@
1
- /**
2
- * Create a deep clone of any object or array
3
- * @category Object Manipulation
4
- * @function deepClone
5
- * @param obj - The object or array to clone
6
- * @returns A deep clone of the object
7
- * @example
8
- * const user = { name: "Alice", skills: ["JS", "TS"] };
9
- * const clone = deepClone(user);
10
- * clone.name = "Bob";
11
- * clone.skills[0] = "Python";
12
- * console.log(user.name); // "Alice" (unchanged)
13
- * console.log(user.skills[0]); // "JS" (unchanged)
14
- */
15
- function deepClone<T>(obj: T): T {
16
- if (obj === null || typeof obj !== "object") return obj;
17
-
18
- if (Array.isArray(obj)) return obj.map(item => deepClone(item)) as T;
19
-
20
- const cloned = {} as T;
21
- for (const key in obj) {
22
- if (obj.hasOwnProperty(key)) cloned[key] = deepClone(obj[key]);
23
- }
24
- return cloned;
25
- }
26
-
27
- /**
28
- * Remove duplicate values from an array
29
- * @category Object Manipulation
30
- * @function noTwins
31
- * @param arr - The array to remove duplicates from
32
- * @returns {unknown[]} A new array with unique values only
33
- * @example
34
- * noTwins([1, 2, 2, 3, 3, 3]); // [1, 2, 3]
35
- * noTwins(["a", "b", "a", "c"]); // ["a", "b", "c"]
36
- * noTwins([1, "1", 1, "1"]); // [1, "1"]
37
- */
38
- function noTwins(arr: unknown[]): unknown[] {
39
- return Array.from(new Set(arr));
40
- }
41
-
42
- export {deepClone, noTwins};
@@ -1,89 +0,0 @@
1
- import { isEmpty } from './validation';
2
-
3
- /**
4
- * Transform a string to camelCase format
5
- * @category Transformation
6
- * @function camelify
7
- * @param str - The string to transform
8
- * @returns {string} The string in camelCase format
9
- * @example
10
- * camelify("hello world"); // "helloWorld"
11
- * camelify("C'est un test"); // "cestUnTest"
12
- * camelify("foo bar baz"); // "fooBarBaz"
13
- */
14
- function camelify(str: string): string {
15
- let camelCased: string = "";
16
- if (!isEmpty(str)) {
17
- let cleaned = str.replace(/[^a-zA-Z0-9\s]/g, "");
18
- let toCamelify = cleaned.split(" ");
19
-
20
- camelCased = toCamelify.map((word, index) => {
21
- if (index === 0) return word.toLowerCase();
22
- return word[0].toUpperCase() + word.slice(1).toLowerCase();
23
- })
24
- .join('');
25
- }
26
- return camelCased;
27
- }
28
-
29
- /**
30
- * Transform a string to kebab-case format
31
- * @category Transformation
32
- * @function kebabify
33
- * @param str - The string to transform
34
- * @returns {string} The string in kebab-case format
35
- * @example
36
- * kebabify("hello world"); // "hello-world"
37
- * kebabify("C'est un test"); // "ceststun-test"
38
- * kebabify("foo bar baz"); // "foo-bar-baz"
39
- */
40
- function kebabify(str: string): string {
41
- let kebabised: string = "";
42
- if (!isEmpty(str)) {
43
- let cleaned = str.replace(/[^a-zA-Z0-9\s]/g, "");
44
- let toKebabify = cleaned.split(" ");
45
- kebabised = toKebabify.map(word => word.toLowerCase())
46
- .join("-");
47
- }
48
- return kebabised;
49
- }
50
-
51
- /**
52
- * Transform a string to snake_case format
53
- * @category Transformation
54
- * @function snakify
55
- * @param str - The string to transform
56
- * @returns {string} The string in snake_case format
57
- * @example
58
- * snakify("hello world"); // "hello_world"
59
- * snakify("C'est un test"); // "ceststun_test"
60
- * snakify("foo bar baz"); // "foo_bar_baz"
61
- */
62
- function snakify(str: string): string {
63
- let snaked: string = "";
64
- if (!isEmpty(str)) {
65
- let cleaned = str.replace(/[^a-zA-Z0-9\s]/g, "");
66
- let toSnakify = cleaned.split(" ");
67
- snaked = toSnakify.map(word => word.toLowerCase())
68
- .join("_");
69
- }
70
- return snaked;
71
- }
72
-
73
- /**
74
- * Capitalize the first character of a string
75
- * @category Transformation
76
- * @function capitalize
77
- * @param str - The string to capitalize
78
- * @returns {string} The string with the first character in uppercase
79
- * @example
80
- * capitalize("hello"); // "Hello"
81
- * capitalize("hello world"); // "Hello world"
82
- * capitalize(""); // ""
83
- */
84
- function capitalize(str: string): string {
85
- if (isEmpty(str)) return str;
86
- return str[0].toUpperCase() + str.slice(1);
87
- }
88
-
89
- export {camelify, kebabify, snakify, capitalize};
package/src/validation.ts DELETED
@@ -1,79 +0,0 @@
1
- /**
2
- * Check if any type of variable is empty
3
- * @category Validation
4
- * @function isEmpty
5
- * @param value - The variable to check
6
- * @returns {boolean} True if the value is empty, false otherwise
7
- * @example
8
- * isEmpty(""); // true
9
- * isEmpty(" "); // true
10
- * isEmpty(null); // true
11
- * isEmpty([]); // true
12
- * isEmpty({}); // true
13
- * isEmpty("hello"); // false
14
- * isEmpty([1, 2]); // false
15
- */
16
- function isEmpty(value: unknown): boolean {
17
- if (value === null || value === undefined) return true;
18
- if (typeof value === "string") return value.trim().length === 0;
19
- if (Array.isArray(value)) return value.length === 0;
20
- if (typeof value === "object") return Object.keys(value).length === 0;
21
- return false;
22
- }
23
-
24
- /**
25
- * Check if the variable is of the chosen type
26
- * @category Validation
27
- * @function isType
28
- * @param value - The variable to check
29
- * @param type - The type you want
30
- * @returns {boolean} True if the value is of the chosen type, false otherwise
31
- * @example
32
- * isType("hello", "string"); // true
33
- * isType(42, "number"); // true
34
- * isType([], "object"); // true
35
- * isType("42", "number"); // false
36
- */
37
- function isType(value: unknown, type: string): boolean {
38
- return typeof value === type;
39
- }
40
-
41
- /**
42
- * Check if an email is valid
43
- * @category Validation
44
- * @function isEmail
45
- * @param email - The email to check
46
- * @returns {boolean} True if the email is valid, false otherwise
47
- * @example
48
- * isEmail("alice@example.com"); // true
49
- * isEmail("bob.smith@company.co.uk"); // true
50
- * isEmail("invalid@.com"); // false
51
- * isEmail("no-at-sign.com"); // false
52
- */
53
- function isEmail(email: string): boolean {
54
- const regex = /^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
55
- return regex.test(email);
56
- }
57
-
58
- /**
59
- * Check if a URL is valid
60
- * @category Validation
61
- * @function isURL
62
- * @param url - The URL to check
63
- * @returns {boolean} True if the URL is valid, false otherwise
64
- * @example
65
- * isURL("https://www.example.com"); // true
66
- * isURL("http://example.com/path"); // true
67
- * isURL("www.example.com"); // false (missing protocol)
68
- * isURL("not a url"); // false
69
- */
70
- function isURL(url: string): boolean {
71
- try {
72
- new URL(url);
73
- return true;
74
- } catch (error) {
75
- return false;
76
- }
77
- }
78
-
79
- export {isEmpty, isType, isEmail, isURL};
package/tsconfig.json DELETED
@@ -1,24 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "module": "commonjs",
5
- "lib": [
6
- "ES2020",
7
- "DOM"
8
- ],
9
- "outDir": "./dist",
10
- "rootDir": "./src",
11
- "strict": true,
12
- "esModuleInterop": true,
13
- "skipLibCheck": true,
14
- "forceConsistentCasingInFileNames": true,
15
- "declaration": true,
16
- "declarationMap": true
17
- },
18
- "include": [
19
- "src/**/*"
20
- ],
21
- "exclude": [
22
- "node_modules"
23
- ]
24
- }