@aiszlab/relax 2.0.3 → 2.0.5
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/dist/class-name/normalize.cjs +2 -4
- package/dist/class-name/normalize.d.ts +2 -1
- package/dist/class-name/normalize.mjs +2 -4
- package/dist/decimal/index.d.ts +4 -0
- package/dist/hooks/use-click-away.d.ts +2 -2
- package/dist/hooks/use-lazy-ref.cjs +18 -0
- package/dist/hooks/use-lazy-ref.d.ts +7 -0
- package/dist/hooks/use-lazy-ref.mjs +16 -0
- package/dist/hooks/use-media-query.cjs +2 -2
- package/dist/hooks/use-media-query.mjs +2 -2
- package/dist/index.cjs +12 -2
- package/dist/index.d.ts +5 -1
- package/dist/index.mjs +6 -1
- package/dist/is/is-deep-key.cjs +46 -0
- package/dist/is/is-deep-key.d.ts +18 -0
- package/dist/is/is-deep-key.mjs +44 -0
- package/dist/is/is-iterable.cjs +12 -0
- package/dist/is/is-iterable.d.ts +5 -0
- package/dist/is/is-iterable.mjs +10 -0
- package/dist/is/is-key.cjs +38 -0
- package/dist/is/is-key.d.ts +14 -0
- package/dist/is/is-key.mjs +36 -0
- package/dist/is/is-object.cjs +26 -5
- package/dist/is/is-object.d.ts +22 -4
- package/dist/is/is-object.mjs +26 -5
- package/dist/is/is-symbol.cjs +23 -0
- package/dist/is/is-symbol.d.ts +15 -0
- package/dist/is/is-symbol.mjs +21 -0
- package/dist/types/first.d.ts +1 -1
- package/dist/types/get.d.ts +8 -0
- package/dist/types/last.d.ts +1 -1
- package/dist/utils/at.cjs +6 -6
- package/dist/utils/at.d.ts +2 -2
- package/dist/utils/at.mjs +6 -6
- package/dist/utils/first.cjs +7 -11
- package/dist/utils/first.d.ts +5 -2
- package/dist/utils/first.mjs +7 -11
- package/dist/utils/get.cjs +81 -0
- package/dist/utils/get.d.ts +244 -0
- package/dist/utils/get.mjs +79 -0
- package/dist/utils/is-index.cjs +28 -0
- package/dist/utils/is-index.d.ts +1 -0
- package/dist/utils/is-index.mjs +26 -0
- package/dist/utils/last.cjs +7 -11
- package/dist/utils/last.d.ts +5 -2
- package/dist/utils/last.mjs +7 -11
- package/dist/utils/merge.d.ts +1 -1
- package/dist/utils/pick.cjs +16 -0
- package/dist/utils/pick.d.ts +5 -0
- package/dist/utils/pick.mjs +14 -0
- package/dist/utils/replace/index.d.ts +3 -0
- package/dist/utils/replace/replace-at.cjs +12 -0
- package/dist/utils/replace/replace-at.d.ts +5 -0
- package/dist/utils/replace/replace-at.mjs +10 -0
- package/dist/utils/replace/replace.cjs +19 -0
- package/dist/utils/{replace.d.ts → replace/replace.d.ts} +2 -2
- package/dist/utils/replace/replace.mjs +17 -0
- package/dist/utils/set.cjs +38 -0
- package/dist/utils/set.d.ts +28 -0
- package/dist/utils/set.mjs +36 -0
- package/dist/utils/to-array.cjs +18 -10
- package/dist/utils/to-array.d.ts +2 -3
- package/dist/utils/to-array.mjs +18 -10
- package/dist/utils/to-key.cjs +23 -0
- package/dist/utils/to-key.d.ts +8 -0
- package/dist/utils/to-key.mjs +21 -0
- package/dist/utils/to-paths.cjs +85 -0
- package/dist/utils/to-paths.d.ts +18 -0
- package/dist/utils/to-paths.mjs +83 -0
- package/dist/utils/update.cjs +46 -0
- package/dist/utils/update.d.ts +11 -0
- package/dist/utils/update.mjs +44 -0
- package/package.json +19 -19
- package/dist/utils/replace.cjs +0 -23
- package/dist/utils/replace.mjs +0 -21
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
4
3
|
var _createForOfIteratorHelper = require('@babel/runtime/helpers/createForOfIteratorHelper');
|
|
5
4
|
var isString = require('../is/is-string.cjs');
|
|
6
5
|
|
|
@@ -11,13 +10,12 @@ function normalize() {
|
|
|
11
10
|
}
|
|
12
11
|
for (var _i = 0, _classNames2 = classNames; _i < _classNames2.length; _i++) {
|
|
13
12
|
var _classNames = _classNames2[_i];
|
|
14
|
-
if (!isString.isString(_classNames))
|
|
13
|
+
if (!isString.isString(_classNames)) continue;
|
|
15
14
|
var _iterator = _createForOfIteratorHelper(_classNames.matchAll(/\S+/g)),
|
|
16
15
|
_step;
|
|
17
16
|
try {
|
|
18
17
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
19
|
-
var
|
|
20
|
-
className = _step$value[0];
|
|
18
|
+
var className = _step.value[0];
|
|
21
19
|
values.add(className);
|
|
22
20
|
}
|
|
23
21
|
} catch (err) {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
2
1
|
import _createForOfIteratorHelper from '@babel/runtime/helpers/createForOfIteratorHelper';
|
|
3
2
|
import { isString } from '../is/is-string.mjs';
|
|
4
3
|
|
|
@@ -9,13 +8,12 @@ function normalize() {
|
|
|
9
8
|
}
|
|
10
9
|
for (var _i = 0, _classNames2 = classNames; _i < _classNames2.length; _i++) {
|
|
11
10
|
var _classNames = _classNames2[_i];
|
|
12
|
-
if (!isString(_classNames))
|
|
11
|
+
if (!isString(_classNames)) continue;
|
|
13
12
|
var _iterator = _createForOfIteratorHelper(_classNames.matchAll(/\S+/g)),
|
|
14
13
|
_step;
|
|
15
14
|
try {
|
|
16
15
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
17
|
-
var
|
|
18
|
-
className = _step$value[0];
|
|
16
|
+
var className = _step.value[0];
|
|
19
17
|
values.add(className);
|
|
20
18
|
}
|
|
21
19
|
} catch (err) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type RefObject } from "react";
|
|
2
2
|
import { type Containable } from "../dom";
|
|
3
3
|
import type { Nullable, Arrayable } from "@aiszlab/relax/types";
|
|
4
4
|
/**
|
|
5
5
|
* @description
|
|
6
6
|
* click away
|
|
7
7
|
*/
|
|
8
|
-
export declare const useClickAway: (onClickAway: (event: MouseEvent) => void, target: Arrayable<
|
|
8
|
+
export declare const useClickAway: (onClickAway: (event: MouseEvent) => void, target: Arrayable<RefObject<Nullable<Containable>> | false>) => void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* in react, ref always need a initial value
|
|
7
|
+
* but can not be a function
|
|
8
|
+
* so we create a lazy ref to get a value getter
|
|
9
|
+
*/
|
|
10
|
+
function useLazyRef(getter) {
|
|
11
|
+
var ref = react.useRef(null);
|
|
12
|
+
return function () {
|
|
13
|
+
var _ref$current;
|
|
14
|
+
return (_ref$current = ref.current) !== null && _ref$current !== void 0 ? _ref$current : ref.current = getter();
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
exports.useLazyRef = useLazyRef;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* in react, ref always need a initial value
|
|
5
|
+
* but can not be a function
|
|
6
|
+
* so we create a lazy ref to get a value getter
|
|
7
|
+
*/
|
|
8
|
+
function useLazyRef(getter) {
|
|
9
|
+
var ref = useRef(null);
|
|
10
|
+
return function () {
|
|
11
|
+
var _ref$current;
|
|
12
|
+
return (_ref$current = ref.current) !== null && _ref$current !== void 0 ? _ref$current : ref.current = getter();
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { useLazyRef };
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
4
4
|
var react = require('react');
|
|
5
5
|
var toArray = require('../utils/to-array.cjs');
|
|
6
|
-
var
|
|
6
|
+
var replaceAt = require('../utils/replace/replace-at.cjs');
|
|
7
7
|
|
|
8
8
|
var useMediaQuery = function useMediaQuery(query) {
|
|
9
9
|
var _query = react.useMemo(function () {
|
|
@@ -21,7 +21,7 @@ var useMediaQuery = function useMediaQuery(query) {
|
|
|
21
21
|
setValue = _useState2[1];
|
|
22
22
|
var onMediaQueryChange = react.useCallback(function (event, index) {
|
|
23
23
|
setValue(function (prev) {
|
|
24
|
-
return
|
|
24
|
+
return replaceAt.replaceAt(prev, index, event.matches);
|
|
25
25
|
});
|
|
26
26
|
}, []);
|
|
27
27
|
react.useEffect(function () {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
2
2
|
import { useMemo, useState, useCallback, useEffect } from 'react';
|
|
3
3
|
import { toArray } from '../utils/to-array.mjs';
|
|
4
|
-
import {
|
|
4
|
+
import { replaceAt } from '../utils/replace/replace-at.mjs';
|
|
5
5
|
|
|
6
6
|
var useMediaQuery = function useMediaQuery(query) {
|
|
7
7
|
var _query = useMemo(function () {
|
|
@@ -19,7 +19,7 @@ var useMediaQuery = function useMediaQuery(query) {
|
|
|
19
19
|
setValue = _useState2[1];
|
|
20
20
|
var onMediaQueryChange = useCallback(function (event, index) {
|
|
21
21
|
setValue(function (prev) {
|
|
22
|
-
return
|
|
22
|
+
return replaceAt(prev, index, event.matches);
|
|
23
23
|
});
|
|
24
24
|
}, []);
|
|
25
25
|
useEffect(function () {
|
package/dist/index.cjs
CHANGED
|
@@ -40,6 +40,7 @@ var useEventSource = require('./hooks/use-event-source.cjs');
|
|
|
40
40
|
var useResize = require('./hooks/use-resize.cjs');
|
|
41
41
|
var useDraggable = require('./hooks/use-draggable.cjs');
|
|
42
42
|
var useAsyncEffect = require('./hooks/use-async-effect.cjs');
|
|
43
|
+
var useLazyRef = require('./hooks/use-lazy-ref.cjs');
|
|
43
44
|
var isRefable = require('./is/is-refable.cjs');
|
|
44
45
|
var isUndefined = require('./is/is-undefined.cjs');
|
|
45
46
|
var isNull = require('./is/is-null.cjs');
|
|
@@ -71,7 +72,6 @@ var throttle = require('./utils/throttle.cjs');
|
|
|
71
72
|
var clone = require('./utils/clone.cjs');
|
|
72
73
|
var toggle = require('./utils/toggle.cjs');
|
|
73
74
|
var taggedTemplateLiterals = require('./utils/tagged-template-literals.cjs');
|
|
74
|
-
var replace = require('./utils/replace.cjs');
|
|
75
75
|
var first = require('./utils/first.cjs');
|
|
76
76
|
var last = require('./utils/last.cjs');
|
|
77
77
|
var merge = require('./utils/merge.cjs');
|
|
@@ -79,6 +79,11 @@ var max = require('./utils/max.cjs');
|
|
|
79
79
|
var min = require('./utils/min.cjs');
|
|
80
80
|
var load = require('./utils/load.cjs');
|
|
81
81
|
var at = require('./utils/at.cjs');
|
|
82
|
+
var pick = require('./utils/pick.cjs');
|
|
83
|
+
var get = require('./utils/get.cjs');
|
|
84
|
+
var set = require('./utils/set.cjs');
|
|
85
|
+
var replace = require('./utils/replace/replace.cjs');
|
|
86
|
+
var replaceAt = require('./utils/replace/replace-at.cjs');
|
|
82
87
|
|
|
83
88
|
|
|
84
89
|
|
|
@@ -122,6 +127,7 @@ exports.useEventSource = useEventSource.useEventSource;
|
|
|
122
127
|
exports.useResize = useResize.useResize;
|
|
123
128
|
exports.useDraggable = useDraggable.useDraggable;
|
|
124
129
|
exports.useAsyncEffect = useAsyncEffect.useAsyncEffect;
|
|
130
|
+
exports.useLazyRef = useLazyRef.useLazyRef;
|
|
125
131
|
exports.isRefable = isRefable.isRefable;
|
|
126
132
|
exports.isUndefined = isUndefined.isUndefined;
|
|
127
133
|
exports.isNull = isNull.isNull;
|
|
@@ -153,7 +159,6 @@ exports.throttle = throttle.throttle;
|
|
|
153
159
|
exports.clone = clone.clone;
|
|
154
160
|
exports.toggle = toggle.toggle;
|
|
155
161
|
exports.taggedTemplateLiterals = taggedTemplateLiterals.taggedTemplateLiterals;
|
|
156
|
-
exports.replace = replace.replace;
|
|
157
162
|
exports.first = first.first;
|
|
158
163
|
exports.last = last.last;
|
|
159
164
|
exports.merge = merge.merge;
|
|
@@ -161,3 +166,8 @@ exports.max = max.max;
|
|
|
161
166
|
exports.min = min.min;
|
|
162
167
|
exports.load = load.load;
|
|
163
168
|
exports.at = at.at;
|
|
169
|
+
exports.pick = pick.pick;
|
|
170
|
+
exports.get = get.get;
|
|
171
|
+
exports.set = set.set;
|
|
172
|
+
exports.replace = replace.replace;
|
|
173
|
+
exports.replaceAt = replaceAt.replaceAt;
|
package/dist/index.d.ts
CHANGED
|
@@ -42,6 +42,7 @@ export { useEventSource } from "./hooks/use-event-source";
|
|
|
42
42
|
export { useResize } from "./hooks/use-resize";
|
|
43
43
|
export { useDraggable } from "./hooks/use-draggable";
|
|
44
44
|
export { useAsyncEffect } from "./hooks/use-async-effect";
|
|
45
|
+
export { useLazyRef } from "./hooks/use-lazy-ref";
|
|
45
46
|
/**
|
|
46
47
|
* @description
|
|
47
48
|
* is
|
|
@@ -81,7 +82,7 @@ export { throttle } from "./utils/throttle";
|
|
|
81
82
|
export { clone } from "./utils/clone";
|
|
82
83
|
export { toggle } from "./utils/toggle";
|
|
83
84
|
export { taggedTemplateLiterals } from "./utils/tagged-template-literals";
|
|
84
|
-
export { replace } from "./utils/replace";
|
|
85
|
+
export { replace, replaceAt } from "./utils/replace";
|
|
85
86
|
export { first } from "./utils/first";
|
|
86
87
|
export { last } from "./utils/last";
|
|
87
88
|
export { merge } from "./utils/merge";
|
|
@@ -89,3 +90,6 @@ export { max } from "./utils/max";
|
|
|
89
90
|
export { min } from "./utils/min";
|
|
90
91
|
export { load } from "./utils/load";
|
|
91
92
|
export { at } from "./utils/at";
|
|
93
|
+
export { pick } from "./utils/pick";
|
|
94
|
+
export { get } from "./utils/get";
|
|
95
|
+
export { set } from "./utils/set";
|
package/dist/index.mjs
CHANGED
|
@@ -38,6 +38,7 @@ export { useEventSource } from './hooks/use-event-source.mjs';
|
|
|
38
38
|
export { useResize } from './hooks/use-resize.mjs';
|
|
39
39
|
export { useDraggable } from './hooks/use-draggable.mjs';
|
|
40
40
|
export { useAsyncEffect } from './hooks/use-async-effect.mjs';
|
|
41
|
+
export { useLazyRef } from './hooks/use-lazy-ref.mjs';
|
|
41
42
|
export { isRefable } from './is/is-refable.mjs';
|
|
42
43
|
export { isUndefined } from './is/is-undefined.mjs';
|
|
43
44
|
export { isNull } from './is/is-null.mjs';
|
|
@@ -69,7 +70,6 @@ export { throttle } from './utils/throttle.mjs';
|
|
|
69
70
|
export { clone } from './utils/clone.mjs';
|
|
70
71
|
export { toggle } from './utils/toggle.mjs';
|
|
71
72
|
export { taggedTemplateLiterals } from './utils/tagged-template-literals.mjs';
|
|
72
|
-
export { replace } from './utils/replace.mjs';
|
|
73
73
|
export { first } from './utils/first.mjs';
|
|
74
74
|
export { last } from './utils/last.mjs';
|
|
75
75
|
export { merge } from './utils/merge.mjs';
|
|
@@ -77,3 +77,8 @@ export { max } from './utils/max.mjs';
|
|
|
77
77
|
export { min } from './utils/min.mjs';
|
|
78
78
|
export { load } from './utils/load.mjs';
|
|
79
79
|
export { at } from './utils/at.mjs';
|
|
80
|
+
export { pick } from './utils/pick.mjs';
|
|
81
|
+
export { get } from './utils/get.mjs';
|
|
82
|
+
export { set } from './utils/set.mjs';
|
|
83
|
+
export { replace } from './utils/replace/replace.mjs';
|
|
84
|
+
export { replaceAt } from './utils/replace/replace-at.mjs';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _typeof = require('@babel/runtime/helpers/typeof');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Checks if a given key is a deep key.
|
|
7
|
+
*
|
|
8
|
+
* A deep key is a string that contains a dot (.) or square brackets with a property accessor.
|
|
9
|
+
*
|
|
10
|
+
* @param {PropertyKey} key - The key to check.
|
|
11
|
+
* @returns {boolean} - Returns true if the key is a deep key, otherwise false.
|
|
12
|
+
*
|
|
13
|
+
* Examples:
|
|
14
|
+
*
|
|
15
|
+
* isDeepKey('a.b') // true
|
|
16
|
+
* isDeepKey('a[b]') // true
|
|
17
|
+
* isDeepKey('a') // false
|
|
18
|
+
* isDeepKey(123) // false
|
|
19
|
+
* isDeepKey('a.b.c') // true
|
|
20
|
+
* isDeepKey('a[b][c]') // true
|
|
21
|
+
*/
|
|
22
|
+
function isDeepKey(key) {
|
|
23
|
+
switch (_typeof(key)) {
|
|
24
|
+
case "number":
|
|
25
|
+
case "symbol":
|
|
26
|
+
{
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
case "string":
|
|
30
|
+
{
|
|
31
|
+
var _deepKeys = new Set([".", "[", "]"]);
|
|
32
|
+
for (var index = 0; index < key.length; index++) {
|
|
33
|
+
if (_deepKeys.has(key[index])) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
default:
|
|
40
|
+
{
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
exports.isDeepKey = isDeepKey;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a given key is a deep key.
|
|
3
|
+
*
|
|
4
|
+
* A deep key is a string that contains a dot (.) or square brackets with a property accessor.
|
|
5
|
+
*
|
|
6
|
+
* @param {PropertyKey} key - The key to check.
|
|
7
|
+
* @returns {boolean} - Returns true if the key is a deep key, otherwise false.
|
|
8
|
+
*
|
|
9
|
+
* Examples:
|
|
10
|
+
*
|
|
11
|
+
* isDeepKey('a.b') // true
|
|
12
|
+
* isDeepKey('a[b]') // true
|
|
13
|
+
* isDeepKey('a') // false
|
|
14
|
+
* isDeepKey(123) // false
|
|
15
|
+
* isDeepKey('a.b.c') // true
|
|
16
|
+
* isDeepKey('a[b][c]') // true
|
|
17
|
+
*/
|
|
18
|
+
export declare function isDeepKey(key: PropertyKey): boolean;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import _typeof from '@babel/runtime/helpers/typeof';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Checks if a given key is a deep key.
|
|
5
|
+
*
|
|
6
|
+
* A deep key is a string that contains a dot (.) or square brackets with a property accessor.
|
|
7
|
+
*
|
|
8
|
+
* @param {PropertyKey} key - The key to check.
|
|
9
|
+
* @returns {boolean} - Returns true if the key is a deep key, otherwise false.
|
|
10
|
+
*
|
|
11
|
+
* Examples:
|
|
12
|
+
*
|
|
13
|
+
* isDeepKey('a.b') // true
|
|
14
|
+
* isDeepKey('a[b]') // true
|
|
15
|
+
* isDeepKey('a') // false
|
|
16
|
+
* isDeepKey(123) // false
|
|
17
|
+
* isDeepKey('a.b.c') // true
|
|
18
|
+
* isDeepKey('a[b][c]') // true
|
|
19
|
+
*/
|
|
20
|
+
function isDeepKey(key) {
|
|
21
|
+
switch (_typeof(key)) {
|
|
22
|
+
case "number":
|
|
23
|
+
case "symbol":
|
|
24
|
+
{
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
case "string":
|
|
28
|
+
{
|
|
29
|
+
var _deepKeys = new Set([".", "[", "]"]);
|
|
30
|
+
for (var index = 0; index < key.length; index++) {
|
|
31
|
+
if (_deepKeys.has(key[index])) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
default:
|
|
38
|
+
{
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { isDeepKey };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var isFunction = require('./is-function.cjs');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* is iterable
|
|
7
|
+
*/
|
|
8
|
+
function isIterable(value) {
|
|
9
|
+
return isFunction.isFunction(value === null || value === void 0 ? void 0 : value[Symbol.iterator]);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
exports.isIterable = isIterable;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var isArray = require('./is-array.cjs');
|
|
4
|
+
var isBoolean = require('./is-boolean.cjs');
|
|
5
|
+
var isNull = require('./is-null.cjs');
|
|
6
|
+
var isNumber = require('./is-number.cjs');
|
|
7
|
+
var isObject = require('./is-object.cjs');
|
|
8
|
+
var isString = require('./is-string.cjs');
|
|
9
|
+
var isSymbol = require('./is-symbol.cjs');
|
|
10
|
+
|
|
11
|
+
/** Matches any deep property path. (e.g. `a.b[0].c`)*/
|
|
12
|
+
var _IS_DEEP_KEY = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/;
|
|
13
|
+
/** Matches any word character (alphanumeric & underscore).*/
|
|
14
|
+
var _IS_PLAIN_KEY = /^\w*$/;
|
|
15
|
+
/**
|
|
16
|
+
* Checks if `value` is a property name and not a property path. (It's ok that the `value` is not in the keys of the `object`)
|
|
17
|
+
* @param {unknown} value The value to check.
|
|
18
|
+
* @param {unknown} object The object to query.
|
|
19
|
+
* @returns {boolean} Returns `true` if `value` is a property name, else `false`.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* isKey('a', { a: 1 });
|
|
23
|
+
* // => true
|
|
24
|
+
*
|
|
25
|
+
* isKey('a.b', { a: { b: 2 } });
|
|
26
|
+
* // => false
|
|
27
|
+
*/
|
|
28
|
+
function isKey(value, object) {
|
|
29
|
+
if (isArray.isArray(value) || isObject.isObject(value)) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
if (isNumber.isNumber(value) || isBoolean.isBoolean(value) || isNull.isNull(value) || isSymbol.isSymbol(value)) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
return isString.isString(value) && (_IS_PLAIN_KEY.test(value) || !_IS_DEEP_KEY.test(value)) || object != null && Object.hasOwn(object, value);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
exports.isKey = isKey;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if `value` is a property name and not a property path. (It's ok that the `value` is not in the keys of the `object`)
|
|
3
|
+
* @param {unknown} value The value to check.
|
|
4
|
+
* @param {unknown} object The object to query.
|
|
5
|
+
* @returns {boolean} Returns `true` if `value` is a property name, else `false`.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* isKey('a', { a: 1 });
|
|
9
|
+
* // => true
|
|
10
|
+
*
|
|
11
|
+
* isKey('a.b', { a: { b: 2 } });
|
|
12
|
+
* // => false
|
|
13
|
+
*/
|
|
14
|
+
export declare function isKey(value?: unknown, object?: unknown): value is PropertyKey;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { isArray } from './is-array.mjs';
|
|
2
|
+
import { isBoolean } from './is-boolean.mjs';
|
|
3
|
+
import { isNull } from './is-null.mjs';
|
|
4
|
+
import { isNumber } from './is-number.mjs';
|
|
5
|
+
import { isObject } from './is-object.mjs';
|
|
6
|
+
import { isString } from './is-string.mjs';
|
|
7
|
+
import { isSymbol } from './is-symbol.mjs';
|
|
8
|
+
|
|
9
|
+
/** Matches any deep property path. (e.g. `a.b[0].c`)*/
|
|
10
|
+
var _IS_DEEP_KEY = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/;
|
|
11
|
+
/** Matches any word character (alphanumeric & underscore).*/
|
|
12
|
+
var _IS_PLAIN_KEY = /^\w*$/;
|
|
13
|
+
/**
|
|
14
|
+
* Checks if `value` is a property name and not a property path. (It's ok that the `value` is not in the keys of the `object`)
|
|
15
|
+
* @param {unknown} value The value to check.
|
|
16
|
+
* @param {unknown} object The object to query.
|
|
17
|
+
* @returns {boolean} Returns `true` if `value` is a property name, else `false`.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* isKey('a', { a: 1 });
|
|
21
|
+
* // => true
|
|
22
|
+
*
|
|
23
|
+
* isKey('a.b', { a: { b: 2 } });
|
|
24
|
+
* // => false
|
|
25
|
+
*/
|
|
26
|
+
function isKey(value, object) {
|
|
27
|
+
if (isArray(value) || isObject(value)) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
if (isNumber(value) || isBoolean(value) || isNull(value) || isSymbol(value)) {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
return isString(value) && (_IS_PLAIN_KEY.test(value) || !_IS_DEEP_KEY.test(value)) || object != null && Object.hasOwn(object, value);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { isKey };
|
package/dist/is/is-object.cjs
CHANGED
|
@@ -1,13 +1,34 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var _typeof = require('@babel/runtime/helpers/typeof');
|
|
4
|
+
var isFunction = require('./is-function.cjs');
|
|
5
|
+
var isNull = require('./is-null.cjs');
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
+
* Checks if the given value is an object. An object is a value that is
|
|
9
|
+
* not a primitive type (string, number, boolean, symbol, null, or undefined).
|
|
10
|
+
*
|
|
11
|
+
* This function tests whether the provided value is an object or not.
|
|
12
|
+
* It returns `true` if the value is an object, and `false` otherwise.
|
|
13
|
+
*
|
|
14
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to an object value.
|
|
15
|
+
*
|
|
16
|
+
* @param {unknown} value - The value to check if it is an object.
|
|
17
|
+
* @returns {value is object} `true` if the value is an object, `false` otherwise.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const value1 = {};
|
|
21
|
+
* const value2 = [1, 2, 3];
|
|
22
|
+
* const value3 = () => {};
|
|
23
|
+
* const value4 = null;
|
|
24
|
+
*
|
|
25
|
+
* console.log(isObject(value1)); // true
|
|
26
|
+
* console.log(isObject(value2)); // true
|
|
27
|
+
* console.log(isObject(value3)); // true
|
|
28
|
+
* console.log(isObject(value4)); // false
|
|
8
29
|
*/
|
|
9
|
-
|
|
10
|
-
return
|
|
11
|
-
}
|
|
30
|
+
function isObject(value) {
|
|
31
|
+
return !isNull.isNull(value) && (_typeof(value) === "object" || isFunction.isFunction(value));
|
|
32
|
+
}
|
|
12
33
|
|
|
13
34
|
exports.isObject = isObject;
|
package/dist/is/is-object.d.ts
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Checks if the given value is an object. An object is a value that is
|
|
3
|
+
* not a primitive type (string, number, boolean, symbol, null, or undefined).
|
|
4
|
+
*
|
|
5
|
+
* This function tests whether the provided value is an object or not.
|
|
6
|
+
* It returns `true` if the value is an object, and `false` otherwise.
|
|
7
|
+
*
|
|
8
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to an object value.
|
|
9
|
+
*
|
|
10
|
+
* @param {unknown} value - The value to check if it is an object.
|
|
11
|
+
* @returns {value is object} `true` if the value is an object, `false` otherwise.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const value1 = {};
|
|
15
|
+
* const value2 = [1, 2, 3];
|
|
16
|
+
* const value3 = () => {};
|
|
17
|
+
* const value4 = null;
|
|
18
|
+
*
|
|
19
|
+
* console.log(isObject(value1)); // true
|
|
20
|
+
* console.log(isObject(value2)); // true
|
|
21
|
+
* console.log(isObject(value3)); // true
|
|
22
|
+
* console.log(isObject(value4)); // false
|
|
4
23
|
*/
|
|
5
|
-
declare
|
|
6
|
-
export { isObject };
|
|
24
|
+
export declare function isObject(value?: unknown): value is object;
|
package/dist/is/is-object.mjs
CHANGED
|
@@ -1,11 +1,32 @@
|
|
|
1
1
|
import _typeof from '@babel/runtime/helpers/typeof';
|
|
2
|
+
import { isFunction } from './is-function.mjs';
|
|
3
|
+
import { isNull } from './is-null.mjs';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
+
* Checks if the given value is an object. An object is a value that is
|
|
7
|
+
* not a primitive type (string, number, boolean, symbol, null, or undefined).
|
|
8
|
+
*
|
|
9
|
+
* This function tests whether the provided value is an object or not.
|
|
10
|
+
* It returns `true` if the value is an object, and `false` otherwise.
|
|
11
|
+
*
|
|
12
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to an object value.
|
|
13
|
+
*
|
|
14
|
+
* @param {unknown} value - The value to check if it is an object.
|
|
15
|
+
* @returns {value is object} `true` if the value is an object, `false` otherwise.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* const value1 = {};
|
|
19
|
+
* const value2 = [1, 2, 3];
|
|
20
|
+
* const value3 = () => {};
|
|
21
|
+
* const value4 = null;
|
|
22
|
+
*
|
|
23
|
+
* console.log(isObject(value1)); // true
|
|
24
|
+
* console.log(isObject(value2)); // true
|
|
25
|
+
* console.log(isObject(value3)); // true
|
|
26
|
+
* console.log(isObject(value4)); // false
|
|
6
27
|
*/
|
|
7
|
-
|
|
8
|
-
return
|
|
9
|
-
}
|
|
28
|
+
function isObject(value) {
|
|
29
|
+
return !isNull(value) && (_typeof(value) === "object" || isFunction(value));
|
|
30
|
+
}
|
|
10
31
|
|
|
11
32
|
export { isObject };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _typeof = require('@babel/runtime/helpers/typeof');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Check whether a value is a symbol.
|
|
7
|
+
*
|
|
8
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `symbol`.
|
|
9
|
+
*
|
|
10
|
+
* @param {unknown} value The value to check.
|
|
11
|
+
* @returns {value is symbol} Returns `true` if `value` is a symbol, else `false`.
|
|
12
|
+
* @example
|
|
13
|
+
* isSymbol(Symbol.iterator);
|
|
14
|
+
* // => true
|
|
15
|
+
*
|
|
16
|
+
* isSymbol('abc');
|
|
17
|
+
* // => false
|
|
18
|
+
*/
|
|
19
|
+
function isSymbol(value) {
|
|
20
|
+
return _typeof(value) === "symbol" || value instanceof Symbol;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
exports.isSymbol = isSymbol;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check whether a value is a symbol.
|
|
3
|
+
*
|
|
4
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `symbol`.
|
|
5
|
+
*
|
|
6
|
+
* @param {unknown} value The value to check.
|
|
7
|
+
* @returns {value is symbol} Returns `true` if `value` is a symbol, else `false`.
|
|
8
|
+
* @example
|
|
9
|
+
* isSymbol(Symbol.iterator);
|
|
10
|
+
* // => true
|
|
11
|
+
*
|
|
12
|
+
* isSymbol('abc');
|
|
13
|
+
* // => false
|
|
14
|
+
*/
|
|
15
|
+
export declare function isSymbol(value?: unknown): value is symbol;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import _typeof from '@babel/runtime/helpers/typeof';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Check whether a value is a symbol.
|
|
5
|
+
*
|
|
6
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `symbol`.
|
|
7
|
+
*
|
|
8
|
+
* @param {unknown} value The value to check.
|
|
9
|
+
* @returns {value is symbol} Returns `true` if `value` is a symbol, else `false`.
|
|
10
|
+
* @example
|
|
11
|
+
* isSymbol(Symbol.iterator);
|
|
12
|
+
* // => true
|
|
13
|
+
*
|
|
14
|
+
* isSymbol('abc');
|
|
15
|
+
* // => false
|
|
16
|
+
*/
|
|
17
|
+
function isSymbol(value) {
|
|
18
|
+
return _typeof(value) === "symbol" || value instanceof Symbol;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { isSymbol };
|