mark-3 0.0.4 → 0.0.6
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.
- package/CHANGELOG.md +25 -0
- package/components/index.js +1 -0
- package/components/scroll-aware-content.vue +162 -0
- package/composables/index.js +5 -0
- package/composables/use-event-listener.js +20 -6
- package/composables/use-intersection-observer.js +67 -0
- package/composables/use-outside-clicks.js +62 -0
- package/composables/use-pointer-swipe.js +138 -0
- package/composables/use-scroll-event.js +97 -0
- package/composables/use-swipeable-drawer.js +161 -0
- package/helpers/array/index.js +1 -0
- package/helpers/array/pick-random.js +24 -0
- package/helpers/array/tests/pick-random.test.js +39 -0
- package/helpers/date/index.js +1 -1
- package/helpers/date/{from-timestamp/index.test.js → tests/format-timestamp.test.js} +1 -1
- package/helpers/date/tests/format.test.js +97 -0
- package/helpers/date/{is-on-same-day/index.test.js → tests/is-on-same-day.test.js} +1 -1
- package/helpers/date/{is-on-same-year/index.test.js → tests/is-on-same-year.test.js} +1 -1
- package/helpers/number/clamp.js +17 -0
- package/helpers/number/index.js +2 -0
- package/helpers/number/random.js +24 -0
- package/helpers/number/tests/clamp.test.js +37 -0
- package/helpers/number/tests/random.test.js +51 -0
- package/helpers/string/{camel-to-dash/index.js → camel-to-dash.js} +2 -2
- package/helpers/string/encode-subscript.js +45 -0
- package/helpers/string/encode-superscript.js +46 -0
- package/helpers/string/{escape-regex/index.js → escape-regex.js} +1 -1
- package/helpers/string/index.js +2 -0
- package/helpers/string/{camel-to-dash/index.test.js → tests/camel-to-dash.test.js} +1 -1
- package/helpers/string/tests/encode-subscript.test.js +41 -0
- package/helpers/string/tests/encode-superscript.test.js +42 -0
- package/helpers/string/{escape-regex/index.test.js → tests/escape-regex.test.js} +1 -1
- package/helpers/string/{trim/index.test.js → tests/trim.test.js} +1 -1
- package/helpers/string/{trim/index.js → trim.js} +2 -2
- package/helpers/time/debounce.js +29 -0
- package/helpers/time/index.js +1 -0
- package/helpers/time/tests/debounce.test.js +58 -0
- package/helpers/types/index.js +1 -0
- package/helpers/types/{is-empty/index.js → is-empty.js} +1 -1
- package/helpers/types/{is-map/index.js → is-map.js} +1 -1
- package/helpers/types/is-numeric.js +22 -0
- package/helpers/types/{is-set/index.js → is-set.js} +1 -1
- package/helpers/types/{get-type-name/index.test.js → tests/get-type-name.test.js} +2 -2
- package/helpers/types/{is-array/index.test.js → tests/is-array.test.js} +1 -1
- package/helpers/types/{is-empty/index.test.js → tests/is-empty.test.js} +1 -1
- package/helpers/types/{is-map/index.test.js → tests/is-map.test.js} +1 -1
- package/helpers/types/tests/is-numeric.test.js +51 -0
- package/helpers/types/{is-plain-object/index.test.js → tests/is-plain-object.test.js} +1 -1
- package/helpers/types/{is-set/index.test.js → tests/is-set.test.js} +1 -1
- package/helpers/types/{is-string/index.test.js → tests/is-string.test.js} +1 -1
- package/package.json +4 -1
- package/helpers/date/format/README.md +0 -33
- package/helpers/date/format/index.test.js +0 -97
- package/helpers/date/from-timestamp/README.md +0 -14
- package/helpers/date/is-on-same-day/README.md +0 -12
- package/helpers/date/is-on-same-year/README.md +0 -13
- package/helpers/string/camel-to-dash/README.md +0 -24
- package/helpers/string/escape-regex/README.md +0 -12
- package/helpers/string/trim/README.md +0 -66
- package/helpers/types/get-type-name/README.md +0 -11
- package/helpers/types/is-array/README.md +0 -11
- package/helpers/types/is-empty/README.md +0 -35
- package/helpers/types/is-map/README.md +0 -15
- package/helpers/types/is-plain-object/README.md +0 -17
- package/helpers/types/is-set/README.md +0 -15
- package/helpers/types/is-string/README.md +0 -12
- /package/helpers/date/{from-timestamp/index.js → format-timestamp.js} +0 -0
- /package/helpers/date/{format/index.js → format.js} +0 -0
- /package/helpers/date/{is-on-same-day/index.js → is-on-same-day.js} +0 -0
- /package/helpers/date/{is-on-same-year/index.js → is-on-same-year.js} +0 -0
- /package/helpers/types/{get-type-name/index.js → get-type-name.js} +0 -0
- /package/helpers/types/{is-array/index.js → is-array.js} +0 -0
- /package/helpers/types/{is-plain-object/index.js → is-plain-object.js} +0 -0
- /package/helpers/types/{is-string/index.js → is-string.js} +0 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { encodeSuperscript } from "..";
|
|
3
|
+
|
|
4
|
+
describe("encodeSuperscript", () =>
|
|
5
|
+
{
|
|
6
|
+
it("converts full match to superscript", () =>
|
|
7
|
+
{
|
|
8
|
+
expect(encodeSuperscript("h2o")).toBe("ʰ²ᵒ");
|
|
9
|
+
expect(encodeSuperscript("123")).toBe("¹²³");
|
|
10
|
+
expect(encodeSuperscript("abc")).toBe("ᵃᵇᶜ");
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("returns original string if any character mismatches and rollbackWhenMismatch is true", () =>
|
|
14
|
+
{
|
|
15
|
+
expect(encodeSuperscript("H2O")).toBe("H2O"); // 'H' and 'O' not in map
|
|
16
|
+
expect(encodeSuperscript("x+2")).toBe("x+2"); // '+' not in map
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("fallbacks partially when rollbackWhenMismatch is false", () =>
|
|
20
|
+
{
|
|
21
|
+
expect(encodeSuperscript("x+2", false)).toBe("ˣ+²");
|
|
22
|
+
expect(encodeSuperscript("H2O", false)).toBe("H²O");
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("returns non-string inputs as-is", () =>
|
|
26
|
+
{
|
|
27
|
+
expect(encodeSuperscript(null)).toBe(null);
|
|
28
|
+
expect(encodeSuperscript(undefined)).toBe(undefined);
|
|
29
|
+
expect(encodeSuperscript(123)).toBe(123);
|
|
30
|
+
expect(encodeSuperscript({})).toEqual({});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("handles empty string correctly", () =>
|
|
34
|
+
{
|
|
35
|
+
expect(encodeSuperscript("")).toBe("");
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("works with a full string of superscriptable characters", () =>
|
|
39
|
+
{
|
|
40
|
+
expect(encodeSuperscript("abcdefghijklmnopqrstuvwxyz", false)).toBe("ᵃᵇᶜᵈᵉᶠᵍʰⁱʲᵏˡᵐⁿᵒᵖqʳˢᵗᵘᵛʷˣʸᶻ");
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { escapeRegex } from "
|
|
2
|
-
import { isEmpty, isArray, isString } from "
|
|
1
|
+
import { escapeRegex } from ".";
|
|
2
|
+
import { isEmpty, isArray, isString } from "../types";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Trims the specified characters from the beginning and end of a string.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Debounce a function call to prevent it from being called too often.
|
|
3
|
+
*
|
|
4
|
+
* This is useful for functions that are called on every
|
|
5
|
+
* frame, such as onScroll. This will ensure that the function
|
|
6
|
+
* is only called at most once every `delay` milliseconds.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const debounced = debounce(() =>
|
|
10
|
+
* console.log( "Hello" ),
|
|
11
|
+
* 1000
|
|
12
|
+
* );
|
|
13
|
+
*
|
|
14
|
+
* window.addEventListener( "scroll", debounced );
|
|
15
|
+
*
|
|
16
|
+
* @param {function} callback The function to debounce.
|
|
17
|
+
* @param {number} delay The delay in milliseconds.
|
|
18
|
+
* @returns {function}
|
|
19
|
+
*/
|
|
20
|
+
export default function debounce( callback, delay = 200 )
|
|
21
|
+
{
|
|
22
|
+
let timer;
|
|
23
|
+
|
|
24
|
+
return function debounceWrapper( ...args )
|
|
25
|
+
{
|
|
26
|
+
clearTimeout( timer );
|
|
27
|
+
timer = setTimeout( callback.bind( this, ...args ), delay );
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as debounce } from "./debounce";
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from "vitest";
|
|
2
|
+
import { debounce } from "..";
|
|
3
|
+
|
|
4
|
+
describe("debounce", () =>
|
|
5
|
+
{
|
|
6
|
+
it("should call the callback after the delay", async () =>
|
|
7
|
+
{
|
|
8
|
+
const callback = vi.fn();
|
|
9
|
+
const delay = 100;
|
|
10
|
+
const debouncedFn = debounce(callback, delay);
|
|
11
|
+
|
|
12
|
+
debouncedFn();
|
|
13
|
+
expect(callback).not.toHaveBeenCalled();
|
|
14
|
+
|
|
15
|
+
// wait delay + 20ms
|
|
16
|
+
await new Promise((r) => setTimeout(r, delay + 20));
|
|
17
|
+
|
|
18
|
+
expect(callback).toHaveBeenCalledTimes(1);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("should call the callback only once if called multiple times quickly", async () =>
|
|
22
|
+
{
|
|
23
|
+
const callback = vi.fn();
|
|
24
|
+
const delay = 100;
|
|
25
|
+
const debouncedFn = debounce(callback, delay);
|
|
26
|
+
|
|
27
|
+
debouncedFn();
|
|
28
|
+
debouncedFn();
|
|
29
|
+
debouncedFn();
|
|
30
|
+
|
|
31
|
+
expect(callback).not.toHaveBeenCalled();
|
|
32
|
+
|
|
33
|
+
await new Promise((r) => setTimeout(r, delay + 20));
|
|
34
|
+
|
|
35
|
+
expect(callback).toHaveBeenCalledTimes(1);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("should pass arguments and context correctly", async () =>
|
|
39
|
+
{
|
|
40
|
+
const callback = vi.fn(function (a, b)
|
|
41
|
+
{
|
|
42
|
+
// 'this' should be the wrapper's this context
|
|
43
|
+
expect(this).toEqual({ foo: "bar" });
|
|
44
|
+
expect(a).toBe(1);
|
|
45
|
+
expect(b).toBe(2);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const delay = 50;
|
|
49
|
+
const debouncedFn = debounce(callback, delay);
|
|
50
|
+
|
|
51
|
+
// call with context and arguments
|
|
52
|
+
debouncedFn.call({ foo: "bar" }, 1, 2);
|
|
53
|
+
|
|
54
|
+
await new Promise((r) => setTimeout(r, delay + 20));
|
|
55
|
+
|
|
56
|
+
expect(callback).toHaveBeenCalledTimes(1);
|
|
57
|
+
});
|
|
58
|
+
});
|
package/helpers/types/index.js
CHANGED
|
@@ -3,5 +3,6 @@ export { default as isSet } from "./is-set";
|
|
|
3
3
|
export { default as isArray } from "./is-array";
|
|
4
4
|
export { default as isEmpty } from "./is-empty";
|
|
5
5
|
export { default as isString } from "./is-string";
|
|
6
|
+
export { default as isNumeric } from "./is-numeric";
|
|
6
7
|
export { default as getTypeName } from "./get-type-name";
|
|
7
8
|
export { default as isPlainObject } from "./is-plain-object";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a value is numeric or can be converted to a number.
|
|
3
|
+
*
|
|
4
|
+
* @param {any} value - The value to be checked.
|
|
5
|
+
* @returns {boolean} true if the value is numeric, false otherwise.
|
|
6
|
+
*/
|
|
7
|
+
export default function isNumeric( value )
|
|
8
|
+
{
|
|
9
|
+
if( typeof value === "number" )
|
|
10
|
+
{
|
|
11
|
+
return ! isNaN( value ) && isFinite( value );
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if( typeof value === "string" )
|
|
15
|
+
{
|
|
16
|
+
return value.trim() !== "" &&
|
|
17
|
+
! isNaN( Number( value )) &&
|
|
18
|
+
isFinite( Number( value ));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { isNumeric } from "..";
|
|
3
|
+
|
|
4
|
+
describe("isNumeric function", () =>
|
|
5
|
+
{
|
|
6
|
+
it("should return true for numeric numbers", () =>
|
|
7
|
+
{
|
|
8
|
+
expect(isNumeric(0)).toBe(true);
|
|
9
|
+
expect(isNumeric(123)).toBe(true);
|
|
10
|
+
expect(isNumeric(-456)).toBe(true);
|
|
11
|
+
expect(isNumeric(1e4)).toBe(true);
|
|
12
|
+
expect(isNumeric(3.14)).toBe(true);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("should return false for NaN and Infinity numbers", () =>
|
|
16
|
+
{
|
|
17
|
+
expect(isNumeric(NaN)).toBe(false);
|
|
18
|
+
expect(isNumeric(Infinity)).toBe(false);
|
|
19
|
+
expect(isNumeric(-Infinity)).toBe(false);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("should return true for numeric strings", () =>
|
|
23
|
+
{
|
|
24
|
+
expect(isNumeric("0")).toBe(true);
|
|
25
|
+
expect(isNumeric("123")).toBe(true);
|
|
26
|
+
expect(isNumeric("-456")).toBe(true);
|
|
27
|
+
expect(isNumeric("1e4")).toBe(true);
|
|
28
|
+
expect(isNumeric("3.14")).toBe(true);
|
|
29
|
+
expect(isNumeric(" 42 ")).toBe(true);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("should return false for non-numeric strings", () =>
|
|
33
|
+
{
|
|
34
|
+
expect(isNumeric("")).toBe(false);
|
|
35
|
+
expect(isNumeric(" ")).toBe(false);
|
|
36
|
+
expect(isNumeric("abc")).toBe(false);
|
|
37
|
+
expect(isNumeric("123abc")).toBe(false);
|
|
38
|
+
expect(isNumeric("Infinity")).toBe(false);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("should return false for other data types", () =>
|
|
42
|
+
{
|
|
43
|
+
expect(isNumeric(null)).toBe(false);
|
|
44
|
+
expect(isNumeric(undefined)).toBe(false);
|
|
45
|
+
expect(isNumeric(true)).toBe(false);
|
|
46
|
+
expect(isNumeric(false)).toBe(false);
|
|
47
|
+
expect(isNumeric({})).toBe(false);
|
|
48
|
+
expect(isNumeric([])).toBe(false);
|
|
49
|
+
expect(isNumeric(() => {})).toBe(false);
|
|
50
|
+
});
|
|
51
|
+
});
|
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.
|
|
5
|
+
"version": "0.0.6",
|
|
6
6
|
"workspaces": [
|
|
7
7
|
"src/*/*"
|
|
8
8
|
],
|
|
@@ -25,5 +25,8 @@
|
|
|
25
25
|
"@vitest/coverage-v8": "^3.2.4",
|
|
26
26
|
"@vitest/ui": "^3.2.4",
|
|
27
27
|
"vitest": "^3.2.4"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"vue": "^3.5.18"
|
|
28
31
|
}
|
|
29
32
|
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
# format
|
|
2
|
-
A lightweight and flexible date formatting utility for JavaScript and TypeScript. This helper formats Date objects using PHP-style tokens like Y, m, d, H, i, and more. It supports both short and long month names with locale-aware formatting via Intl.DateTimeFormat.
|
|
3
|
-
|
|
4
|
-
Built with simplicity and clarity in mind — no external dependencies, easy to use, fully typed.
|
|
5
|
-
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
## Usage
|
|
9
|
-
```ts
|
|
10
|
-
import { format } from '@mark-3/helpers/date';
|
|
11
|
-
|
|
12
|
-
format( new Date, "Y-m-d H:i:s" );
|
|
13
|
-
// 2022-01-01 22:00:00 (mysql datetime format)
|
|
14
|
-
|
|
15
|
-
format( new Date, "j MM, H:i", "tr" );
|
|
16
|
-
// 1 Temmuz, 22:00
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
---
|
|
20
|
-
|
|
21
|
-
## 💡 Supported Tokens
|
|
22
|
-
`d`: 01-31 (zero-padded day)
|
|
23
|
-
`j`: 1-31 (non-padded day)
|
|
24
|
-
`m`: 01-12 (zero-padded month)
|
|
25
|
-
`n`: 1-12 (non-padded month)
|
|
26
|
-
`M`: Jan–Dec (short month name, localized)
|
|
27
|
-
`MM`: January–December (long month name, localized)
|
|
28
|
-
`y`: 00-99 (two-digit year)
|
|
29
|
-
`Y`: 0000-9999 (full year)
|
|
30
|
-
`H`: 00-23 (zero-padded hour, 24h)
|
|
31
|
-
`G`: 0-23 (hour, 24h)
|
|
32
|
-
`i`: 00-59 (minutes)
|
|
33
|
-
`s`: 00-59 (seconds)
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import formatDate from "./index";
|
|
3
|
-
|
|
4
|
-
describe( "formatDate", () =>
|
|
5
|
-
{
|
|
6
|
-
const date = new Date( "2025-12-21T22:10:05" );
|
|
7
|
-
|
|
8
|
-
it( "formats full year (Y)", () =>
|
|
9
|
-
{
|
|
10
|
-
expect( formatDate( date, "Y" )).toBe( "2025" );
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it( "formats short year (y)", () =>
|
|
14
|
-
{
|
|
15
|
-
expect( formatDate( date, "y" )).toBe( "25" );
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it( "formats zero-padded month (m)", () =>
|
|
19
|
-
{
|
|
20
|
-
expect( formatDate( date, "m" )).toBe( "12" );
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it( "formats non-padded month (n)", () =>
|
|
24
|
-
{
|
|
25
|
-
expect( formatDate( date, "n" )).toBe( "12" );
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it( "formats short month name (M)", () =>
|
|
29
|
-
{
|
|
30
|
-
expect( formatDate( date, "M" )).toBe( "Dec" );
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it( "formats full month name (MM)", () =>
|
|
34
|
-
{
|
|
35
|
-
expect( formatDate( date, "MM" )).toBe( "December" );
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it( "formats day padded (d)", () =>
|
|
39
|
-
{
|
|
40
|
-
expect( formatDate( date, "d" )).toBe( "21" );
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it( "formats day non-padded (j)", () =>
|
|
44
|
-
{
|
|
45
|
-
expect( formatDate( date, "j" )).toBe( "21" );
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it( "formats zero-padded hour (H)", () =>
|
|
49
|
-
{
|
|
50
|
-
expect( formatDate( date, "H" )).toBe( "22" );
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it( "formats non-padded hour (G)", () =>
|
|
54
|
-
{
|
|
55
|
-
expect( formatDate( date, "G" )).toBe( "22" );
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it( "formats minutes (i)", () =>
|
|
59
|
-
{
|
|
60
|
-
expect( formatDate( date, "i" )).toBe( "10" );
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it( "formats seconds (s)", () =>
|
|
64
|
-
{
|
|
65
|
-
expect( formatDate( date, "s" )).toBe( "05" );
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it( "formats a custom pattern", () =>
|
|
69
|
-
{
|
|
70
|
-
expect( formatDate( date, "d.m.Y H:i" )).toBe( "21.12.2025 22:10" );
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it( "supports localized short month (M) in TR", () =>
|
|
74
|
-
{
|
|
75
|
-
expect( formatDate( date, "M", "tr" )).toBe( "Ara" ); // Aralık
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it( "supports localized long month (MM) in TR", () =>
|
|
79
|
-
{
|
|
80
|
-
expect( formatDate( date, "MM", "tr" )).toBe( "Aralık" );
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it( "returns empty string for empty pattern", () =>
|
|
84
|
-
{
|
|
85
|
-
expect( formatDate( date, "" )).toBe( "" );
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it( "leaves unknown tokens as-is", () =>
|
|
89
|
-
{
|
|
90
|
-
expect( formatDate( date, "[foo] Y" )).toBe( "[foo] 2025" );
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it( "mixes plain text and tokens", () =>
|
|
94
|
-
{
|
|
95
|
-
expect( formatDate( date, "d MM Y, H:i" )).toBe( "21 December 2025, 22:10" );
|
|
96
|
-
});
|
|
97
|
-
});
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
# fromTimestamp
|
|
2
|
-
This function handles both seconds and milliseconds timestamps by checking the length of the number.
|
|
3
|
-
|
|
4
|
-
If the `timestamp` is less than `1e11`, it's assumed to be in seconds and is converted to milliseconds. If the conversion results in an invalid `Date` object, the function returns the provided `defaultValue`
|
|
5
|
-
or `undefined` if no default is specified.
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## Usage
|
|
10
|
-
```ts
|
|
11
|
-
import fromTimestamp from '@mark-3/helpers-date-from-timestamp';
|
|
12
|
-
|
|
13
|
-
const result = fromTimestamp( 1753634780845 );
|
|
14
|
-
```
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
# isOnSameDay
|
|
2
|
-
A lightweight utility to check whether two JavaScript `Date` objects are in the same calendar day.
|
|
3
|
-
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
## Usage
|
|
7
|
-
```ts
|
|
8
|
-
import isOnSameDay from '@mark-3/helpers-date-is-on-same-day';
|
|
9
|
-
|
|
10
|
-
const result = isOnSameDay( new Date( '2022-01-01' ), new Date( '2022-12-31' ));
|
|
11
|
-
// false
|
|
12
|
-
```
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
# isOnSameYear
|
|
2
|
-
A lightweight utility to check whether two JavaScript `Date` objects are in the same calendar year.
|
|
3
|
-
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
## Usage
|
|
7
|
-
|
|
8
|
-
```ts
|
|
9
|
-
import isOnSameYear from '@mark-3/helpers-date-is-on-same-year';
|
|
10
|
-
|
|
11
|
-
const result = isOnSameYear( new Date( '2022-01-01' ), new Date( '2022-12-31' ));
|
|
12
|
-
// true
|
|
13
|
-
```
|
|
@@ -1,24 +0,0 @@
|
|
|
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
|
-
```
|
|
@@ -1,12 +0,0 @@
|
|
|
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
|
-
```
|
|
@@ -1,66 +0,0 @@
|
|
|
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.
|