mark-3 0.0.2 → 0.0.4

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 (41) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/composables/index.js +3 -0
  3. package/composables/use-event-listener.js +40 -0
  4. package/composables/use-media-query.js +34 -0
  5. package/composables/use-responsiveness.js +61 -0
  6. package/helpers/string/camel-to-dash/README.md +24 -0
  7. package/helpers/string/camel-to-dash/index.js +23 -0
  8. package/helpers/string/camel-to-dash/index.test.js +39 -0
  9. package/helpers/string/escape-regex/README.md +12 -0
  10. package/helpers/string/escape-regex/index.js +20 -0
  11. package/helpers/string/escape-regex/index.test.js +58 -0
  12. package/helpers/string/index.js +3 -0
  13. package/helpers/string/trim/README.md +66 -0
  14. package/helpers/string/trim/index.js +33 -0
  15. package/helpers/string/trim/index.test.js +62 -0
  16. package/helpers/types/get-type-name/README.md +11 -0
  17. package/helpers/types/get-type-name/index.js +13 -0
  18. package/helpers/types/get-type-name/index.test.js +71 -0
  19. package/helpers/types/index.js +7 -0
  20. package/helpers/types/is-array/README.md +11 -0
  21. package/helpers/types/is-array/index.js +10 -0
  22. package/helpers/types/is-array/index.test.js +56 -0
  23. package/helpers/types/is-empty/README.md +35 -0
  24. package/helpers/types/is-empty/index.js +45 -0
  25. package/helpers/types/is-empty/index.test.js +84 -0
  26. package/helpers/types/is-map/README.md +15 -0
  27. package/helpers/types/is-map/index.js +12 -0
  28. package/helpers/types/is-map/index.test.js +41 -0
  29. package/helpers/types/is-plain-object/README.md +17 -0
  30. package/helpers/types/is-plain-object/index.js +17 -0
  31. package/helpers/types/is-plain-object/index.test.js +61 -0
  32. package/helpers/types/is-set/README.md +15 -0
  33. package/helpers/types/is-set/index.js +12 -0
  34. package/helpers/types/is-set/index.test.js +41 -0
  35. package/helpers/types/is-string/README.md +12 -0
  36. package/helpers/types/is-string/index.js +10 -0
  37. package/helpers/types/is-string/index.test.js +46 -0
  38. package/package.json +1 -1
  39. package/vitest.config.js +12 -0
  40. package/helpers/date/is-on-same-year/package.json +0 -25
  41. package/vitest.config.ts +0 -12
package/CHANGELOG.md CHANGED
@@ -2,6 +2,36 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [0.0.4](https://github.com/ismailceylan/mark-3/compare/v0.0.3...v0.0.4) (2025-08-02)
6
+
7
+
8
+ ### Features
9
+
10
+ * **composables:** add new use-responsiveness composable ([3b6ebe4](https://github.com/ismailceylan/mark-3/commit/3b6ebe4f0c50668453071cf4146b3dc459a25f24))
11
+ * **helpers:** add new types/is-map method ([fdcda02](https://github.com/ismailceylan/mark-3/commit/fdcda0239aab54951df1c708dee7e74989801c79))
12
+ * **helpers:** add new types/is-set method ([618abbe](https://github.com/ismailceylan/mark-3/commit/618abbeb6f068774dfa4c6158302fd7ac5f7fccc))
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * **helpers:** ensures that the default argument value is used for chars on string/trim method ([645f41e](https://github.com/ismailceylan/mark-3/commit/645f41e883b8777a16e4773ed520411e9953a45b))
18
+
19
+ ### [0.0.3](https://github.com/ismailceylan/mark-3/compare/v0.0.2...v0.0.3) (2025-08-02)
20
+
21
+
22
+ ### Features
23
+
24
+ * **composables:** add new use-event-listener composable ([58bee94](https://github.com/ismailceylan/mark-3/commit/58bee94286d6736fee813f2286a3bd33031d58b2))
25
+ * **composables:** add new use-media-query composable ([b76da8a](https://github.com/ismailceylan/mark-3/commit/b76da8a083e13e60c967c90f8116aaa3c735c74f))
26
+ * **helpers:** add new escape-regex helper ([78ba818](https://github.com/ismailceylan/mark-3/commit/78ba818542c8325809d72ec7920f2aa14cd053d0))
27
+ * **helpers:** add new get-type-name helper ([12cc26c](https://github.com/ismailceylan/mark-3/commit/12cc26c83335f96af408d90b5accab3aaa5f6d32))
28
+ * **helpers:** add new is-array helper ([b8b95f6](https://github.com/ismailceylan/mark-3/commit/b8b95f652677f6dc6079b34cd97bcb64671db75c))
29
+ * **helpers:** add new string/camel-to-dash helper ([fbbbcf0](https://github.com/ismailceylan/mark-3/commit/fbbbcf0570b38ccabbd44044ca9054d3dccdaafd))
30
+ * **helpers:** add new string/trim helper ([cfd40a3](https://github.com/ismailceylan/mark-3/commit/cfd40a3a4741bb0ffe8bcc184f623cb6c6f39c6c))
31
+ * **helpers:** add new types/is-empty helper ([151a547](https://github.com/ismailceylan/mark-3/commit/151a547d2ab89e47b5d9f85bad080af82d4e02a4))
32
+ * **helpers:** add new types/is-plain-object method ([98a7804](https://github.com/ismailceylan/mark-3/commit/98a780415f4d1b086075be042b8467509fb2815d))
33
+ * **helpers:** add new types/is-string helper ([2ee5197](https://github.com/ismailceylan/mark-3/commit/2ee51979235a674d63a3d8c9381f37ccc84ecfd7))
34
+
5
35
  ### [0.0.2](https://github.com/ismailceylan/mark-3/compare/v0.0.1...v0.0.2) (2025-08-01)
6
36
 
7
37
 
@@ -0,0 +1,3 @@
1
+ export { default as useMediaQuery } from "./use-media-query.js";
2
+ export { default as useEventListener } from "./use-event-listener.js";
3
+ export { default as useResponsiveness } from "./use-responsiveness.js";
@@ -0,0 +1,40 @@
1
+ import { onMounted, onUnmounted, getCurrentInstance } from "vue";
2
+
3
+ /**
4
+ * A composition function that adds a DOM event listener to the given target with the
5
+ * given event name and callback. The options object is optional. If the composition
6
+ * function is called from within a component, then the event listener is added when
7
+ * the component is mounted and removed when the component is unmounted. If the
8
+ * composition function is called outside of a component, then the event listener is
9
+ * added immediately and must be removed manually by calling the returned function.
10
+ *
11
+ * @param {Element} target - The target element to add the event listener to.
12
+ * @param {string} eventName - The name of the event to add a listener for.
13
+ * @param {function} callBack - The callback function to call when the event happens.
14
+ * @param {object} [options] - The options object to pass to addEventListener.
15
+ * @returns {function} - A function that can be called to remove the event listener.
16
+ */
17
+ export default function useEventListener( target, eventName, callBack, options )
18
+ {
19
+ if( getCurrentInstance())
20
+ {
21
+ onMounted( listen );
22
+ onUnmounted( stop );
23
+ }
24
+ else
25
+ {
26
+ listen();
27
+ }
28
+
29
+ function listen()
30
+ {
31
+ target.addEventListener( eventName, callBack, options );
32
+ }
33
+
34
+ function stop()
35
+ {
36
+ target.removeEventListener( eventName, callBack );
37
+ }
38
+
39
+ return stop;
40
+ }
@@ -0,0 +1,34 @@
1
+ import { ref } from "vue";
2
+ import { useEventListener } from ".";
3
+
4
+ /**
5
+ * Creates a reactive reference that tracks whether the given media query matches the current viewport.
6
+ *
7
+ * @typedef {import('vue').Ref} Ref
8
+ * @param {string} query - A valid media query string.
9
+ * @param {function(boolean)} [watcher] - A function that will be called whenever the match status changes.
10
+ * The function will receive the current match status as a boolean argument.
11
+ * @returns {Ref<boolean>} A reactive reference to the match status.
12
+ * @example
13
+ * const isMobileRef = useMediaQuery( "(max-width: 767px)", matches =>
14
+ * console.log( matches )
15
+ * );
16
+ */
17
+ export default function useMediaQuery( query, watcher )
18
+ {
19
+ const match = matchMedia( query );
20
+ const matches = ref( match.matches );
21
+
22
+ triggerWatcher();
23
+
24
+ useEventListener( match, "change", e =>
25
+ triggerWatcher( matches.value = e.matches )
26
+ );
27
+
28
+ function triggerWatcher()
29
+ {
30
+ watcher && watcher( matches.value );
31
+ }
32
+
33
+ return matches;
34
+ }
@@ -0,0 +1,61 @@
1
+ import { reactive, toRefs } from "vue";
2
+ import { camelToDash } from "../helpers/string";
3
+ import { useMediaQuery } from ".";
4
+
5
+ /**
6
+ * Reactive media query states for multiple breakpoints at once using
7
+ * useMediaQuery composable under the hood and returns an object of
8
+ * reactive media query states.
9
+ *
10
+ * The object keys are the same as the keys of the rules object.
11
+ *
12
+ * If the media queries you pass to the useResponsiveness composable
13
+ * are min- prefixed, the relevant props of returned object will be
14
+ * true if the screen is at least or more in that breakpoint. But if
15
+ * the queries are min- and max- prefixed, the relevant props of the
16
+ * reactive object that returned will be true if the screen is exactly
17
+ * in that breakpoint.
18
+ *
19
+ * You can pass any valid media query to the useResponsiveness composable
20
+ * like color schemes, display modes, and more.
21
+ *
22
+ * @typedef {import('vue').Ref} Ref
23
+ * @typedef {import('vue').Reactive} Reactive
24
+ * @param {Object} rules Object of media queries
25
+ * @returns {Reactive<{}>|Ref<boolean>} Object of reactive media query states
26
+ * @example
27
+ * const breakpoints = useResponsiveness({
28
+ * mobile: "(max-width: 767px)",
29
+ * tablet: "(min-width: 768px) and (max-width: 1023px)",
30
+ * desktop: "(min-width: 1024px)",
31
+ * });
32
+ * // { mobile: false, tablet: false, desktop: true}
33
+ * // every property tells the screen is exactly in that breakpoint
34
+ * @example
35
+ * const breakpoints = useResponsiveness({
36
+ * mobile: "(min-width: 300px)",
37
+ * tablet: "(min-width: 768px)",
38
+ * desktop: "(min-width: 1024px)",
39
+ * });
40
+ * // { mobile: true, tablet: true, desktop: false}
41
+ * // every property tells the screen is at least or more in that breakpoint
42
+ */
43
+ export default function useResponsiveness( rules = {})
44
+ {
45
+ const breakpoints = reactive({});
46
+ const keys = Object.keys( rules );
47
+
48
+ for( const name in rules )
49
+ {
50
+ useMediaQuery( rules[ name ], isActive =>
51
+ breakpoints[ camelToDash( name )] = isActive
52
+ );
53
+ }
54
+
55
+ if( keys.length === 1 )
56
+ {
57
+ return toRefs( breakpoints )[ keys[ 0 ]];
58
+ }
59
+
60
+ return breakpoints;
61
+ }
@@ -0,0 +1,24 @@
1
+ # camelToDash
2
+ Converts a camelCase string to dash-case.
3
+
4
+ * replaces uppercase letters with a dash followed by the lowercase equivalent
5
+ * removes leading and trailing dashes
6
+ * if the input is not a string, returns it unchanged
7
+
8
+ ---
9
+
10
+ ## Usage
11
+ ```js
12
+ import { camelToDash } from "mark-3/helpers/string";
13
+
14
+ camelToDash("helloWorld"); // "hello-world"
15
+ camelToDash("backgroundColor"); // "background-color"
16
+ camelToDash("already-dashed"); // "already-dashed"
17
+ camelToDash("already---dashed"); // "already---dashed"
18
+ camelToDash("MyComponent"); // "my-component"
19
+ camelToDash("XMLHttpRequest"); // "x-m-l-http-request"
20
+ camelToDash("someValue123"); // "some-value123"
21
+ camelToDash("---EdgeCase---"); // "edge-case"
22
+ camelToDash(42); // 42
23
+ camelToDash(null); // null
24
+ ```
@@ -0,0 +1,23 @@
1
+ import { trim } from "..";
2
+ import { isString } from "../../types";
3
+
4
+ /**
5
+ * Converts a camelCase string to dash-case.
6
+ *
7
+ * @param {string} source - The camelCase string to convert.
8
+ * @returns {string} The converted dash-case string. If the input is not a string, returns the input as is.
9
+ */
10
+ export default function camelToDash( source )
11
+ {
12
+ if( ! isString( source ))
13
+ {
14
+ return source;
15
+ }
16
+
17
+ source = source.replace(
18
+ /([A-Z])/g,
19
+ upper => "-" + upper.toLowerCase()
20
+ );
21
+
22
+ return trim( source, "-" );
23
+ }
@@ -0,0 +1,39 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import camelToDash from ".";
3
+
4
+ describe( "camelToDash", () =>
5
+ {
6
+ it( "converts camelCase to dash-case", () =>
7
+ {
8
+ expect( camelToDash( "helloWorld" )).toBe( "hello-world" );
9
+ expect( camelToDash( "mySuperVariable" )).toBe( "my-super-variable" );
10
+ expect( camelToDash( "alreadyDashCase" )).toBe( "already-dash-case" );
11
+ });
12
+
13
+ it( "handles strings with multiple uppercase letters in a row", () =>
14
+ {
15
+ expect( camelToDash( "PDFLoader" )).toBe( "p-d-f-loader" );
16
+ expect( camelToDash( "loadXMLDocument" )).toBe( "load-x-m-l-document" );
17
+ });
18
+
19
+ it( "trims dashes from the beginning and end", () =>
20
+ {
21
+ expect( camelToDash( "CamelCase" )).toBe( "camel-case" );
22
+ expect( camelToDash( "AB" )).toBe( "a-b" );
23
+ expect( camelToDash( "A" )).toBe( "a" );
24
+ });
25
+
26
+ it( "returns empty string when input is empty", () =>
27
+ {
28
+ expect( camelToDash( "" )).toBe( "" );
29
+ });
30
+
31
+ it( "returns non-string inputs unchanged", () =>
32
+ {
33
+ expect( camelToDash( null )).toBe( null );
34
+ expect( camelToDash( undefined )).toBe( undefined );
35
+ expect( camelToDash( 123 )).toBe( 123 );
36
+ expect( camelToDash({})).toEqual({});
37
+ expect( camelToDash([ "camelCase" ])).toEqual([ "camelCase" ]);
38
+ });
39
+ });
@@ -0,0 +1,12 @@
1
+ # escapeRegex
2
+ Escapes special characters in a string to be used in a regular expression.
3
+
4
+ ---
5
+
6
+ ## Usage
7
+ ```js
8
+ import { escapeRegex } from "mark-3/helpers/string";
9
+
10
+ escapeRegex( "foo" ); // => "foo"
11
+ escapeRegex( "foo*" ); // => "foo\*"
12
+ ```
@@ -0,0 +1,20 @@
1
+ import { isString } from "../../types";
2
+
3
+ /**
4
+ * Escapes special characters in a string to be used in a regular expression.
5
+ *
6
+ * @param {string} str - The input string containing characters to be escaped.
7
+ * @returns {string} The modified string with special characters escaped.
8
+ */
9
+ export default function escapeRegex( str )
10
+ {
11
+ if( ! isString( str ))
12
+ {
13
+ return "";
14
+ }
15
+
16
+ return str.replace(
17
+ /[.*+?^${}()|[\]\\]/g,
18
+ "\\$&"
19
+ );
20
+ }
@@ -0,0 +1,58 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import escapeRegex from ".";
3
+
4
+ describe( "escapeRegex", () =>
5
+ {
6
+ it( "should escape all special regex characters", () =>
7
+ {
8
+ const input = ".*+?^${}()|[]\\";
9
+ const expected = "\\.\\*\\+\\?\\^\\$\\{\\}\\(\\)\\|\\[\\]\\\\";
10
+
11
+ expect( escapeRegex( input )).toBe( expected );
12
+ });
13
+
14
+ it( "should return the same string if there are no special characters", () =>
15
+ {
16
+ expect( escapeRegex( "abc123" )).toBe( "abc123" );
17
+ });
18
+
19
+ it( "should handle mixed characters", () =>
20
+ {
21
+ expect( escapeRegex( "file(name).js" )).toBe( "file\\(name\\)\\.js" );
22
+ });
23
+
24
+ it( "should return an empty string when input is an empty string", () =>
25
+ {
26
+ expect( escapeRegex( "" )).toBe( "" );
27
+ });
28
+
29
+ it( "should return an empty string when input is null", () =>
30
+ {
31
+ expect( escapeRegex( null )).toBe( "" );
32
+ });
33
+
34
+ it( "should return an empty string when input is undefined", () =>
35
+ {
36
+ expect( escapeRegex( undefined )).toBe( "" );
37
+ });
38
+
39
+ it( "should return an empty string when input is a number", () =>
40
+ {
41
+ expect( escapeRegex( 12345 )).toBe( "" );
42
+ });
43
+
44
+ it( "should return an empty string when input is an object", () =>
45
+ {
46
+ expect( escapeRegex({})).toBe( "" );
47
+ });
48
+
49
+ it( "should return an empty string when input is an array", () =>
50
+ {
51
+ expect( escapeRegex([])).toBe( "" );
52
+ });
53
+
54
+ it( "should return an empty string when input is a function", () =>
55
+ {
56
+ expect( escapeRegex(() => {})).toBe( "" );
57
+ });
58
+ });
@@ -0,0 +1,3 @@
1
+ export { default as trim } from "./trim";
2
+ export { default as escapeRegex } from "./escape-regex";
3
+ export { default as camelToDash } from "./camel-to-dash";
@@ -0,0 +1,66 @@
1
+ # trim
2
+ A small utility function to trim specific characters from both ends of a string.
3
+
4
+ Unlike the native `String.prototype.trim()` which only removes whitespace, this function lets you specify exactly which characters to trim — including special characters or a list of them.
5
+
6
+ ---
7
+
8
+ ## Features
9
+ - Trim custom characters from the **start and end** of a string
10
+ - Accepts either a **single character string** or an **array of characters**
11
+ - Automatically escapes special regex characters
12
+ - Ignores non-string input safely
13
+
14
+ ---
15
+
16
+ ## Usage
17
+ ```js
18
+ import { trim } from "mark-3/helpers/string";
19
+
20
+ // Default whitespace trim
21
+ trim(" Hello world ");
22
+ // => "Hello world"
23
+
24
+ // Trim specific character
25
+ trim("---Hello---", "-");
26
+ // => "Hello"
27
+
28
+ // Trim multiple characters
29
+ trim("..//Hello//..", [".", "/"]);
30
+ // => "Hello"
31
+
32
+ // No trim if input is not a string
33
+ trim(42, "-");
34
+ // => 42
35
+
36
+ // Empty trim characters (returns input as-is)
37
+ trim("text", "");
38
+ // => "text"
39
+
40
+ // trim characters as a pattern
41
+ trim(":::text:::_", ":::" );
42
+ // => "text:::_"
43
+ ```
44
+
45
+ ---
46
+
47
+ ## Parameters
48
+ ```ts
49
+ trim(input: string, chars?: string | string[]): string
50
+ ```
51
+
52
+ | Name | Type | Default | Description |
53
+ | ----- | -------------------- | ------- | --------------------------------------- |
54
+ | input | `string` | — | The string to be trimmed |
55
+ | chars | `string \| string[]` | `" "` | The character(s) to trim from both ends |
56
+
57
+ If chars is a string of multiple characters, each character will be treated individually and removed if present at the start or end.
58
+
59
+ **Behavior Details**
60
+ If chars is an array: All characters in the array will be treated as individual characters to trim.
61
+
62
+ If chars is a string:
63
+ * A single-character string: trimmed directly like a single items array.
64
+ * A multi-character string: each character as a whole.
65
+
66
+ All special characters like ., *, +, ^ are automatically escaped — no need to handle them manually.
@@ -0,0 +1,33 @@
1
+ import { escapeRegex } from "..";
2
+ import { isEmpty, isArray, isString } from "../../types";
3
+
4
+ /**
5
+ * Trims the specified characters from the beginning and end of a string.
6
+ *
7
+ * @param {string} input - The string to trim.
8
+ * @param {string|string[]} [chars=" "] - The character(s) to trim. Can be a single
9
+ * character or array of characters.
10
+ * @returns {string} The trimmed string.
11
+ */
12
+ export default function trim( input, chars = " " )
13
+ {
14
+ if( ! isString( input ) || ( chars !== " " && isEmpty( chars )))
15
+ {
16
+ return input;
17
+ }
18
+
19
+ const patternStr = isArray( chars )
20
+ ? makePattern( chars.map( escapeRegex ).join( "" ), "b" )
21
+ : makePattern( escapeRegex( chars ));
22
+
23
+ const pattern = new RegExp( patternStr, "g" );
24
+
25
+ function makePattern( escaped, type )
26
+ {
27
+ return type == "b"
28
+ ? `^[${escaped}]+|[${escaped}]+$`
29
+ : `^${escaped}+|${escaped}+$`;
30
+ }
31
+
32
+ return input.replace( pattern, "" );
33
+ }
@@ -0,0 +1,62 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import trim from ".";
3
+
4
+ describe( "trim", () =>
5
+ {
6
+ it( "should trim spaces by default", () =>
7
+ {
8
+ expect( trim( " hello " )).toBe( "hello" );
9
+ });
10
+
11
+ it( "should trim custom character from both ends (single char)", () =>
12
+ {
13
+ expect( trim( "--hello--", "-" )).toBe( "hello" );
14
+ });
15
+
16
+ it( "should trim multiple characters (array)", () =>
17
+ {
18
+ expect( trim( "-_=hello=_-", [ "-", "_", "=" ])).toBe( "hello" );
19
+ });
20
+
21
+ it( "should not trim characters in the middle", () =>
22
+ {
23
+ expect( trim( "--he--llo--", "-" )).toBe( "he--llo" );
24
+ });
25
+
26
+ it( "should return input unchanged if it is not a string", () =>
27
+ {
28
+ expect( trim( 12345, "-" )).toBe( 12345 );
29
+ expect( trim( null, "-" )).toBe( null );
30
+ expect( trim( undefined, "-" )).toBe( undefined );
31
+ });
32
+
33
+ it( "should return the same string if chars is empty string", () =>
34
+ {
35
+ expect( trim( "abc", "" )).toBe( "abc" );
36
+ });
37
+
38
+ it( "should return the same string if chars is an empty array", () =>
39
+ {
40
+ expect( trim( "abc", [])).toBe( "abc" );
41
+ });
42
+
43
+ it( "should return empty string if input is empty", () =>
44
+ {
45
+ expect( trim( "" )).toBe( "" );
46
+ });
47
+
48
+ it( "should trim regex special characters properly", () =>
49
+ {
50
+ expect( trim( ".*hello.*", [ ".", "*" ])).toBe( "hello" );
51
+ });
52
+
53
+ it( "should trim only from start and end, not inside", () =>
54
+ {
55
+ expect( trim( "***abc***xyz***", "*" )).toBe( "abc***xyz" );
56
+ });
57
+
58
+ it( "should trim multiple different characters in mixed order", () =>
59
+ {
60
+ expect( trim( "-_-abc-_--", [ "-", "_" ])).toBe( "abc" );
61
+ });
62
+ });
@@ -0,0 +1,11 @@
1
+ # getTypeName
2
+ Returns the name of a variable's type.
3
+
4
+ ---
5
+
6
+ ## Usage
7
+ ```js
8
+ import { getTypeName } from "mark-3/helpers/types";
9
+
10
+ getTypeName({}); // 'Object'
11
+ ```
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Returns the type name of a given variable.
3
+ *
4
+ * @param {any} variable - The variable whose type name is to be determined.
5
+ * @return {string} The type name of the variable.
6
+ */
7
+ export default function getTypeName( variable )
8
+ {
9
+ return Object.prototype
10
+ .toString
11
+ .call( variable )
12
+ .match( /\[object (.*)\]/ )[ 1 ];
13
+ }
@@ -0,0 +1,71 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import getTypeName from ".";
3
+
4
+ describe( "type", () =>
5
+ {
6
+ it( 'should return "String" for a string', () =>
7
+ {
8
+ expect( getTypeName( "hello" )).toBe( "String" );
9
+ });
10
+
11
+ it( 'should return "Number" for a number', () =>
12
+ {
13
+ expect( getTypeName( 123 )).toBe( "Number" );
14
+ });
15
+
16
+ it( 'should return "Boolean" for a boolean', () =>
17
+ {
18
+ expect( getTypeName( true )).toBe( "Boolean" );
19
+ expect( getTypeName( false )).toBe("Boolean" );
20
+ });
21
+
22
+ it( 'should return "Object" for an object', () =>
23
+ {
24
+ expect( getTypeName({})).toBe( "Object" );
25
+ });
26
+
27
+ it( 'should return "Array" for an array', () =>
28
+ {
29
+ expect( getTypeName([])).toBe( "Array" );
30
+ });
31
+
32
+ it( 'should return "Null" for null', () =>
33
+ {
34
+ expect( getTypeName( null )).toBe( "Null" );
35
+ });
36
+
37
+ it( 'should return "Undefined" for undefined', () =>
38
+ {
39
+ expect( getTypeName( undefined )).toBe( "Undefined" );
40
+ });
41
+
42
+ it( 'should return "Function" for a function', () =>
43
+ {
44
+ expect( getTypeName(() => {})).toBe( "Function" );
45
+ });
46
+
47
+ it( 'should return "RegExp" for a regular expression', () =>
48
+ {
49
+ expect( getTypeName( /abc/ )).toBe( 'RegExp' );
50
+ });
51
+
52
+ it( 'should return "Date" for a Date object', () =>
53
+ {
54
+ expect( getTypeName( new Date())).toBe( "Date" );
55
+ });
56
+
57
+ it( 'should return "Error" for an Error object', () =>
58
+ {
59
+ expect( getTypeName( new Error( "Something went wrong" ))).toBe( 'Error' );
60
+ });
61
+
62
+ it( 'should return "Symbol" for a Symbol', () =>
63
+ {
64
+ expect( getTypeName( Symbol( "foo" ))).toBe( "Symbol" );
65
+ });
66
+
67
+ it( 'should return "BigInt" for a BigInt', () =>
68
+ {
69
+ expect( getTypeName( 123n )).toBe( "BigInt" );
70
+ });
71
+ });
@@ -0,0 +1,7 @@
1
+ export { default as isMap } from "./is-map";
2
+ export { default as isSet } from "./is-set";
3
+ export { default as isArray } from "./is-array";
4
+ export { default as isEmpty } from "./is-empty";
5
+ export { default as isString } from "./is-string";
6
+ export { default as getTypeName } from "./get-type-name";
7
+ export { default as isPlainObject } from "./is-plain-object";
@@ -0,0 +1,11 @@
1
+ # isArray
2
+ Checks if a value is an array.
3
+
4
+ ---
5
+
6
+ ## Usage
7
+ ```js
8
+ import { isArray } from "mark-3/helpers/types";
9
+
10
+ isArray([ 1, 2, 3 ]); // true
11
+ ```
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Checks if a value is an array.
3
+ *
4
+ * @param {*} value
5
+ * @return {boolean}
6
+ */
7
+ export default function isArray( value )
8
+ {
9
+ return Array.isArray( value );
10
+ }
@@ -0,0 +1,56 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import isArray from ".";
3
+
4
+ describe( "isArray", () =>
5
+ {
6
+ it( "should return true for an empty array", () =>
7
+ {
8
+ expect( isArray([])).toBe( true );
9
+ });
10
+
11
+ it( "should return true for a non-empty array", () =>
12
+ {
13
+ expect( isArray([ 1, 2, 3 ])).toBe( true );
14
+ });
15
+
16
+ it( "should return false for a string", () =>
17
+ {
18
+ expect( isArray( "hello" )).toBe( false );
19
+ });
20
+
21
+ it( "should return false for a number", () =>
22
+ {
23
+ expect( isArray( 123 )).toBe( false );
24
+ });
25
+
26
+ it( "should return false for null", () =>
27
+ {
28
+ expect( isArray( null )).toBe( false );
29
+ });
30
+
31
+ it( "should return false for undefined", () =>
32
+ {
33
+ expect( isArray( undefined )).toBe( false );
34
+ });
35
+
36
+ it( "should return false for an object", () =>
37
+ {
38
+ expect( isArray({ a: 1 })).toBe( false );
39
+ });
40
+
41
+ it( "should return false for a function", () =>
42
+ {
43
+ expect( isArray(() => {})).toBe( false );
44
+ });
45
+
46
+ it( "should return false for a Set", () =>
47
+ {
48
+ expect( isArray( new Set([ 1, 2, 3 ]))).toBe( false );
49
+ });
50
+
51
+ it( "should return false for an Array-like object", () =>
52
+ {
53
+ const arrayLike = { 0: "a", 1: "b", length: 2 };
54
+ expect( isArray( arrayLike )).toBe( false );
55
+ });
56
+ });
@@ -0,0 +1,35 @@
1
+ # isEmpty
2
+ Checks if the given variable is empty.
3
+
4
+ If the variable is an object, it is considered empty if it has no keys.
5
+ If the variable is an array, it is considered empty if it has no elements.
6
+ If the variable is a map or a set, it is considered empty if it has no size.
7
+ If the variable is a string, it is considered empty if it is trimmed to be an empty string.
8
+ If the variable is undefined or null, it is considered empty.
9
+
10
+ Otherwise, it is not considered empty.
11
+
12
+ ---
13
+
14
+ ## Usage
15
+
16
+ ```js
17
+ import { isEmpty } from 'mark-3/helpers/types/isEmpty';
18
+
19
+ isEmpty( '' ); // true
20
+ isEmpty( ' ' ); // true
21
+ isEmpty([]); // true
22
+ isEmpty({}); // true
23
+ isEmpty( new Map()); // true
24
+ isEmpty( new Set()); // true
25
+ isEmpty( null ); // true
26
+ isEmpty( undefined ); // true
27
+
28
+ isEmpty( 'foo' ); // false
29
+ isEmpty([ 'foo' ]); // false
30
+ isEmpty({ foo: 'bar' }); // false
31
+ isEmpty( new Map([ 'foo', 'bar' ])); // false
32
+ isEmpty( new Set([ 'foo' ])); // false
33
+ isEmpty({ foo: 'bar' }); // false
34
+ isEmpty(() => {}); // false
35
+ ```
@@ -0,0 +1,45 @@
1
+ import { isString, isArray, isMap, isSet, isPlainObject } from "..";
2
+
3
+ /**
4
+ * Checks if the given variable is empty.
5
+ *
6
+ * If the variable is an object, it is considered empty if it has no keys.
7
+ * If the variable is an array, it is considered empty if it has no elements.
8
+ * If the variable is a map or a set, it is considered empty if it has no size.
9
+ * If the variable is a string, it is considered empty if it is trimmed to be an empty string.
10
+ * If the variable is undefined or null, it is considered empty.
11
+ *
12
+ * Otherwise, it is not considered empty.
13
+ *
14
+ * @param {*} variable the variable to check
15
+ * @return {Boolean} true if the variable is empty, false otherwise
16
+ */
17
+ export default function isEmpty( variable )
18
+ {
19
+ if( isPlainObject( variable ))
20
+ {
21
+ return Object.keys( variable ).length === 0;
22
+ }
23
+
24
+ if( isArray( variable ))
25
+ {
26
+ return variable.length === 0;
27
+ }
28
+
29
+ if( isMap( variable ) || isSet( variable ))
30
+ {
31
+ return variable.size === 0;
32
+ }
33
+
34
+ if( isString( variable ))
35
+ {
36
+ return variable.trim() === "";
37
+ }
38
+
39
+ if( variable === undefined || variable === null )
40
+ {
41
+ return true;
42
+ }
43
+
44
+ return false;
45
+ }
@@ -0,0 +1,84 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import isEmpty from ".";
3
+
4
+ describe( "isEmpty", () =>
5
+ {
6
+ // Null & undefined
7
+ it( "should return true for null and undefined", () =>
8
+ {
9
+ expect( isEmpty( null )).toBe( true );
10
+ expect( isEmpty( undefined )).toBe( true );
11
+ });
12
+
13
+ // Strings
14
+ it( "should return true for empty and whitespace-only strings", () =>
15
+ {
16
+ expect( isEmpty( "" )).toBe( true );
17
+ expect( isEmpty( " " )).toBe( true );
18
+ });
19
+
20
+ it( "should return false for non-empty strings", () =>
21
+ {
22
+ expect( isEmpty( "hello" )).toBe( false );
23
+ expect( isEmpty( " test " )).toBe( false );
24
+ });
25
+
26
+ // Arrays
27
+ it( "should return true for empty arrays", () =>
28
+ {
29
+ expect( isEmpty([] )).toBe( true );
30
+ });
31
+
32
+ it( "should return false for non-empty arrays", () =>
33
+ {
34
+ expect( isEmpty([1] )).toBe( false );
35
+ });
36
+
37
+ // Plain objects
38
+ it( "should return true for empty plain objects", () =>
39
+ {
40
+ expect( isEmpty({} )).toBe( true );
41
+ });
42
+
43
+ it( "should return false for non-empty plain objects", () =>
44
+ {
45
+ expect( isEmpty({ a: 1 } )).toBe( false );
46
+ });
47
+
48
+ // Map
49
+ it( "should return true for empty Map", () =>
50
+ {
51
+ expect( isEmpty(new Map( ))).toBe( true );
52
+ });
53
+
54
+ it( "should return false for non-empty Map", () =>
55
+ {
56
+ const map = new Map();
57
+ map.set( "key", "value");
58
+ expect( isEmpty(map )).toBe( false );
59
+ });
60
+
61
+ // Set
62
+ it( "should return true for empty Set", () =>
63
+ {
64
+ expect( isEmpty(new Set( ))).toBe( true );
65
+ });
66
+
67
+ it( "should return false for non-empty Set", () =>
68
+ {
69
+ const set = new Set();
70
+ set.add(1);
71
+ expect( isEmpty(set )).toBe( false );
72
+ });
73
+
74
+ // Other types
75
+ it( "should return false for other types", () =>
76
+ {
77
+ expect( isEmpty(0 )).toBe( false );
78
+ expect( isEmpty(false )).toBe( false );
79
+ expect( isEmpty(NaN )).toBe( false );
80
+ expect( isEmpty(Symbol( ))).toBe( false );
81
+ expect( isEmpty(() => {} )).toBe( false );
82
+ expect( isEmpty(new Date( ))).toBe( false );
83
+ });
84
+ });
@@ -0,0 +1,15 @@
1
+ # isMap
2
+ Utility function to check if a value is a native `Map` object in JavaScript.
3
+
4
+ ---
5
+
6
+ ## Usage
7
+ ```js
8
+ import { isMap } from "@mark-3/helpers/types";
9
+
10
+ isMap(new Map()); // true
11
+ isMap(new WeakMap()); // false
12
+ isMap({}); // false
13
+ isMap([]); // false
14
+ isMap(null); // false
15
+ ```
@@ -0,0 +1,12 @@
1
+ import { getTypeName } from "..";
2
+
3
+ /**
4
+ * Checks if a given value is a Map.
5
+ *
6
+ * @param {any} value - The value to be checked.
7
+ * @returns {boolean} true if the value is a Map, false otherwise.
8
+ */
9
+ export default function isMap( value )
10
+ {
11
+ return getTypeName( value ) === "Map";
12
+ }
@@ -0,0 +1,41 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import isMap from ".";
3
+
4
+ describe("isMap", () =>
5
+ {
6
+ it("should return true for Map instances", () =>
7
+ {
8
+ expect(isMap(new Map())).toBe(true);
9
+ const map = new Map();
10
+ map.set("key", "value");
11
+ expect(isMap(map)).toBe(true);
12
+ });
13
+
14
+ it("should return false for WeakMap", () =>
15
+ {
16
+ expect(isMap(new WeakMap())).toBe(false);
17
+ });
18
+
19
+ it("should return false for plain objects", () =>
20
+ {
21
+ expect(isMap({})).toBe(false);
22
+ expect(isMap({ a: 1 })).toBe(false);
23
+ });
24
+
25
+ it("should return false for arrays", () =>
26
+ {
27
+ expect(isMap([])).toBe(false);
28
+ expect(isMap([1, 2, 3])).toBe(false);
29
+ });
30
+
31
+ it("should return false for other types", () =>
32
+ {
33
+ expect(isMap(null)).toBe(false);
34
+ expect(isMap(undefined)).toBe(false);
35
+ expect(isMap(42)).toBe(false);
36
+ expect(isMap("string")).toBe(false);
37
+ expect(isMap(true)).toBe(false);
38
+ expect(isMap(Symbol("sym"))).toBe(false);
39
+ expect(isMap(function () {})).toBe(false);
40
+ });
41
+ });
@@ -0,0 +1,17 @@
1
+ # isPlainObject
2
+ A utility function to check if a value is a plain object.
3
+
4
+ ## Usage
5
+ ```js
6
+ import { isPlainObject } from "mark-3/helpers/types";
7
+
8
+ isPlainObject({}); // true
9
+ isPlainObject({ a: 1 }); // true
10
+ isPlainObject(Object.create(null)); // true
11
+ isPlainObject([]); // false
12
+ isPlainObject(null); // false
13
+ isPlainObject(new Date()); // false
14
+ isPlainObject(function(){}); // false
15
+ isPlainObject(new Map()); // false
16
+ isPlainObject(new ( class MyClass{})()); // false
17
+ ```
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Checks if the given value is a plain object.
3
+ *
4
+ * @param {any} value - The value to be checked.
5
+ * @return {boolean} true if the value is a plain object, false otherwise.
6
+ */
7
+ export default function isPlainObject( value )
8
+ {
9
+ if( typeof value !== "object" || value === null )
10
+ {
11
+ return false;
12
+ }
13
+
14
+ const proto = Object.getPrototypeOf( value );
15
+
16
+ return proto === Object.prototype || proto === null;
17
+ }
@@ -0,0 +1,61 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import isPlainObject from ".";
3
+
4
+ describe("isPlainObject", () =>
5
+ {
6
+ it("returns true for plain object literals", () =>
7
+ {
8
+ expect(isPlainObject({})).toBe(true);
9
+ expect(isPlainObject({ a: 1, b: 2 })).toBe(true);
10
+ });
11
+
12
+ it("returns true for Object created with constructor", () =>
13
+ {
14
+ expect(isPlainObject(new Object())).toBe(true);
15
+ });
16
+
17
+ it("returns true for Object.create(null)", () =>
18
+ {
19
+ expect(isPlainObject(Object.create(null))).toBe(true);
20
+ });
21
+
22
+ it("returns false for arrays", () =>
23
+ {
24
+ expect(isPlainObject([])).toBe(false);
25
+ expect(isPlainObject([1, 2, 3])).toBe(false);
26
+ });
27
+
28
+ it("returns false for null", () =>
29
+ {
30
+ expect(isPlainObject(null)).toBe(false);
31
+ });
32
+
33
+ it("returns false for functions", () =>
34
+ {
35
+ expect(isPlainObject(function () {})).toBe(false);
36
+ expect(isPlainObject(() => {})).toBe(false);
37
+ });
38
+
39
+ it("returns false for primitive values", () =>
40
+ {
41
+ expect(isPlainObject(123)).toBe(false);
42
+ expect(isPlainObject("string")).toBe(false);
43
+ expect(isPlainObject(true)).toBe(false);
44
+ expect(isPlainObject(undefined)).toBe(false);
45
+ expect(isPlainObject(Symbol("sym"))).toBe(false);
46
+ });
47
+
48
+ it("returns false for built-in objects like Date, RegExp, Map, Set", () =>
49
+ {
50
+ expect(isPlainObject(new Date())).toBe(false);
51
+ expect(isPlainObject(/regex/)).toBe(false);
52
+ expect(isPlainObject(new Map())).toBe(false);
53
+ expect(isPlainObject(new Set())).toBe(false);
54
+ });
55
+
56
+ it("returns false for class instances", () =>
57
+ {
58
+ class MyClass {}
59
+ expect(isPlainObject(new MyClass())).toBe(false);
60
+ });
61
+ });
@@ -0,0 +1,15 @@
1
+ # isSet
2
+ Utility function to check if a value is a native `Set` object in JavaScript.
3
+
4
+ ---
5
+
6
+ ## Usage
7
+ ```js
8
+ import { isSet } from "mark-3/helpers/types";
9
+
10
+ isSet(new Set()); // true
11
+ isSet(new WeakSet()); // false
12
+ isSet({}); // false
13
+ isSet([]); // false
14
+ isSet(null); // false
15
+ ```
@@ -0,0 +1,12 @@
1
+ import { getTypeName } from "..";
2
+
3
+ /**
4
+ * Checks if a given value is a Set.
5
+ *
6
+ * @param {any} value - The value to be checked.
7
+ * @returns {boolean} true if the value is a Set, false otherwise.
8
+ */
9
+ export default function isSet( value )
10
+ {
11
+ return getTypeName( value ) === "Set";
12
+ }
@@ -0,0 +1,41 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import isSet from ".";
3
+
4
+ describe("isSet", () =>
5
+ {
6
+ it("should return true for Set instances", () =>
7
+ {
8
+ expect(isSet(new Set())).toBe(true);
9
+ const set = new Set();
10
+ set.add("key", "value");
11
+ expect(isSet(set)).toBe(true);
12
+ });
13
+
14
+ it("should return false for WeakSet", () =>
15
+ {
16
+ expect(isSet(new WeakSet())).toBe(false);
17
+ });
18
+
19
+ it("should return false for plain objects", () =>
20
+ {
21
+ expect(isSet({})).toBe(false);
22
+ expect(isSet({ a: 1 })).toBe(false);
23
+ });
24
+
25
+ it("should return false for arrays", () =>
26
+ {
27
+ expect(isSet([])).toBe(false);
28
+ expect(isSet([1, 2, 3])).toBe(false);
29
+ });
30
+
31
+ it("should return false for other types", () =>
32
+ {
33
+ expect(isSet(null)).toBe(false);
34
+ expect(isSet(undefined)).toBe(false);
35
+ expect(isSet(42)).toBe(false);
36
+ expect(isSet("string")).toBe(false);
37
+ expect(isSet(true)).toBe(false);
38
+ expect(isSet(Symbol("sym"))).toBe(false);
39
+ expect(isSet(function () {})).toBe(false);
40
+ });
41
+ });
@@ -0,0 +1,12 @@
1
+ # isString
2
+ Checks if a value is a string.
3
+
4
+ ---
5
+
6
+ ## Usage
7
+ ```js
8
+ import { isString } from "mark-3/helpers/types";
9
+
10
+ isString( "foo" ); // true
11
+ isString(1); // false
12
+ ```
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Checks if a value is a string.
3
+ *
4
+ * @param {*} value
5
+ * @return {boolean}
6
+ */
7
+ export default function isString( value )
8
+ {
9
+ return typeof value === "string";
10
+ }
@@ -0,0 +1,46 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import isString from ".";
3
+
4
+ describe("isString", () => {
5
+ it("should return true for a normal string", () => {
6
+ expect(isString("hello")).toBe(true);
7
+ });
8
+
9
+ it("should return true for an empty string", () => {
10
+ expect(isString("")).toBe(true);
11
+ });
12
+
13
+ it("should return false for a String object", () => {
14
+ // typeof new String("abc") === "object"
15
+ expect(isString(new String("abc"))).toBe(false);
16
+ });
17
+
18
+ it("should return false for a number", () => {
19
+ expect(isString(123)).toBe(false);
20
+ });
21
+
22
+ it("should return false for null", () => {
23
+ expect(isString(null)).toBe(false);
24
+ });
25
+
26
+ it("should return false for undefined", () => {
27
+ expect(isString(undefined)).toBe(false);
28
+ });
29
+
30
+ it("should return false for an object", () => {
31
+ expect(isString({})).toBe(false);
32
+ });
33
+
34
+ it("should return false for an array", () => {
35
+ expect(isString(["a", "b"])).toBe(false);
36
+ });
37
+
38
+ it("should return false for a boolean", () => {
39
+ expect(isString(true)).toBe(false);
40
+ expect(isString(false)).toBe(false);
41
+ });
42
+
43
+ it("should return false for a function", () => {
44
+ expect(isString(() => {})).toBe(false);
45
+ });
46
+ });
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "mark-3",
3
3
  "description": "Modular collection of reusable JavaScript helpers, utilities, and Vue components. Built for maintainability, performance, and clarity.",
4
4
  "private": false,
5
- "version": "0.0.2",
5
+ "version": "0.0.4",
6
6
  "workspaces": [
7
7
  "src/*/*"
8
8
  ],
@@ -0,0 +1,12 @@
1
+ import { defineConfig } from "vitest/config";
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ coverage: {
6
+ enabled: true,
7
+ reporter: ["text", "json", "html"],
8
+ include: ["*/*/*/"],
9
+ },
10
+ environment: "node",
11
+ },
12
+ });
@@ -1,25 +0,0 @@
1
- {
2
- "name": "@mark-3/helpers-date-is-on-same-year",
3
- "type": "module",
4
- "version": "0.0.3",
5
- "description": "Checks if two Date objects fall within the same year.",
6
- "main": "dist/index.js",
7
- "types": "dist/index.d.ts",
8
- "scripts": {
9
- "build": "tsc",
10
- "release": "standard-version",
11
- "publish-package": "npm publish --access=public"
12
- },
13
- "standard-version": {
14
- "tagPrefix": "@mark-3/helpers/date/is-on-same-year@"
15
- },
16
- "keywords": [
17
- "date",
18
- "helper",
19
- "year",
20
- "compare",
21
- "utility"
22
- ],
23
- "author": "Ismail Ceylan",
24
- "license": "MIT"
25
- }
package/vitest.config.ts DELETED
@@ -1,12 +0,0 @@
1
- import { defineConfig } from 'vitest/config';
2
-
3
- export default defineConfig({
4
- test: {
5
- coverage: {
6
- enabled: true,
7
- reporter: ['text', 'json', 'html'],
8
- include: ['*/*/*/'],
9
- },
10
- environment: 'node',
11
- },
12
- });