mark-3 0.0.3 → 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.
- package/CHANGELOG.md +14 -0
- package/composables/index.js +2 -1
- package/composables/use-responsiveness.js +61 -0
- package/helpers/string/escape-regex/index.test.js +1 -1
- package/helpers/string/trim/index.js +1 -1
- package/helpers/types/get-type-name/index.test.js +1 -1
- package/helpers/types/index.js +2 -0
- package/helpers/types/is-empty/index.test.js +1 -1
- package/helpers/types/is-map/README.md +15 -0
- package/helpers/types/is-map/index.js +12 -0
- package/helpers/types/is-map/index.test.js +41 -0
- package/helpers/types/is-plain-object/index.js +8 -3
- package/helpers/types/is-plain-object/index.test.js +1 -1
- package/helpers/types/is-set/README.md +15 -0
- package/helpers/types/is-set/index.js +12 -0
- package/helpers/types/is-set/index.test.js +41 -0
- package/helpers/types/is-string/index.test.js +18 -18
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
@@ -2,6 +2,20 @@
|
|
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
|
+
|
5
19
|
### [0.0.3](https://github.com/ismailceylan/mark-3/compare/v0.0.2...v0.0.3) (2025-08-02)
|
6
20
|
|
7
21
|
|
package/composables/index.js
CHANGED
@@ -1,2 +1,3 @@
|
|
1
|
-
export { default as useEventListener } from "./use-event-listener.js";
|
2
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,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
|
+
}
|
@@ -11,7 +11,7 @@ import { isEmpty, isArray, isString } from "../../types";
|
|
11
11
|
*/
|
12
12
|
export default function trim( input, chars = " " )
|
13
13
|
{
|
14
|
-
if( ! isString( input ) || isEmpty( chars ))
|
14
|
+
if( ! isString( input ) || ( chars !== " " && isEmpty( chars )))
|
15
15
|
{
|
16
16
|
return input;
|
17
17
|
}
|
package/helpers/types/index.js
CHANGED
@@ -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
|
+
});
|
@@ -1,5 +1,3 @@
|
|
1
|
-
import { getTypeName } from "../type";
|
2
|
-
|
3
1
|
/**
|
4
2
|
* Checks if the given value is a plain object.
|
5
3
|
*
|
@@ -8,5 +6,12 @@ import { getTypeName } from "../type";
|
|
8
6
|
*/
|
9
7
|
export default function isPlainObject( value )
|
10
8
|
{
|
11
|
-
|
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;
|
12
17
|
}
|
@@ -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
|
+
});
|
@@ -1,46 +1,46 @@
|
|
1
|
-
import { describe, it, expect } from
|
2
|
-
import isString from
|
1
|
+
import { describe, it, expect } from "vitest";
|
2
|
+
import isString from ".";
|
3
3
|
|
4
|
-
describe(
|
5
|
-
it(
|
6
|
-
expect(isString(
|
4
|
+
describe("isString", () => {
|
5
|
+
it("should return true for a normal string", () => {
|
6
|
+
expect(isString("hello")).toBe(true);
|
7
7
|
});
|
8
8
|
|
9
|
-
it(
|
10
|
-
expect(isString(
|
9
|
+
it("should return true for an empty string", () => {
|
10
|
+
expect(isString("")).toBe(true);
|
11
11
|
});
|
12
12
|
|
13
|
-
it(
|
14
|
-
// typeof new String(
|
15
|
-
expect(isString(new String(
|
13
|
+
it("should return false for a String object", () => {
|
14
|
+
// typeof new String("abc") === "object"
|
15
|
+
expect(isString(new String("abc"))).toBe(false);
|
16
16
|
});
|
17
17
|
|
18
|
-
it(
|
18
|
+
it("should return false for a number", () => {
|
19
19
|
expect(isString(123)).toBe(false);
|
20
20
|
});
|
21
21
|
|
22
|
-
it(
|
22
|
+
it("should return false for null", () => {
|
23
23
|
expect(isString(null)).toBe(false);
|
24
24
|
});
|
25
25
|
|
26
|
-
it(
|
26
|
+
it("should return false for undefined", () => {
|
27
27
|
expect(isString(undefined)).toBe(false);
|
28
28
|
});
|
29
29
|
|
30
|
-
it(
|
30
|
+
it("should return false for an object", () => {
|
31
31
|
expect(isString({})).toBe(false);
|
32
32
|
});
|
33
33
|
|
34
|
-
it(
|
35
|
-
expect(isString([
|
34
|
+
it("should return false for an array", () => {
|
35
|
+
expect(isString(["a", "b"])).toBe(false);
|
36
36
|
});
|
37
37
|
|
38
|
-
it(
|
38
|
+
it("should return false for a boolean", () => {
|
39
39
|
expect(isString(true)).toBe(false);
|
40
40
|
expect(isString(false)).toBe(false);
|
41
41
|
});
|
42
42
|
|
43
|
-
it(
|
43
|
+
it("should return false for a function", () => {
|
44
44
|
expect(isString(() => {})).toBe(false);
|
45
45
|
});
|
46
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.
|
5
|
+
"version": "0.0.4",
|
6
6
|
"workspaces": [
|
7
7
|
"src/*/*"
|
8
8
|
],
|