umaki 0.2.5 → 0.3.0
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/README.md +230 -79
- package/dist/_virtual/_commonjsHelpers.cjs.js +1 -1
- package/dist/_virtual/_commonjsHelpers.es.js +1 -1
- package/dist/_virtual/isBetween.cjs.js +1 -1
- package/dist/_virtual/isBetween.es.js +1 -1
- package/dist/index.cjs.js +5 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +5 -1
- package/dist/libs/control/bgScrollStop.cjs.js +1 -1
- package/dist/libs/control/bgScrollStop.es.js +1 -1
- package/dist/libs/control/pd.cjs.js +1 -1
- package/dist/libs/control/pd.es.js +1 -1
- package/dist/libs/control/scrollToHash.cjs.js +1 -1
- package/dist/libs/control/scrollToHash.es.js +1 -1
- package/dist/libs/control/videoPlayControl.cjs.js +1 -1
- package/dist/libs/control/videoPlayControl.es.js +1 -1
- package/dist/libs/convert/changeDateStringToSpecificFormat.cjs.js +1 -1
- package/dist/libs/convert/changeDateStringToSpecificFormat.es.js +1 -1
- package/dist/libs/convert/jsonStringToJsonObject.cjs.js +1 -1
- package/dist/libs/convert/jsonStringToJsonObject.es.js +1 -1
- package/dist/libs/eventControl/debounce.cjs.js +24 -0
- package/dist/libs/eventControl/debounce.d.ts +11 -0
- package/dist/libs/eventControl/debounce.es.js +24 -0
- package/dist/libs/eventControl/debounce.test.d.ts +1 -0
- package/dist/libs/eventControl/index.d.ts +5 -0
- package/dist/libs/eventControl/throttle.cjs.js +24 -0
- package/dist/libs/eventControl/throttle.d.ts +12 -0
- package/dist/libs/eventControl/throttle.es.js +24 -0
- package/dist/libs/eventControl/throttle.test.d.ts +1 -0
- package/dist/libs/get/getAspectRatio.cjs.js +1 -1
- package/dist/libs/get/getAspectRatio.es.js +1 -1
- package/dist/libs/get/getClassNames.cjs.js +1 -1
- package/dist/libs/get/getClassNames.es.js +1 -1
- package/dist/libs/get/getDocumentHeight.cjs.js +1 -1
- package/dist/libs/get/getDocumentHeight.es.js +1 -1
- package/dist/libs/get/getEventPaths.cjs.js +1 -1
- package/dist/libs/get/getEventPaths.es.js +1 -1
- package/dist/libs/get/getGcd.cjs.js +1 -1
- package/dist/libs/get/getGcd.es.js +1 -1
- package/dist/libs/get/getOrientation.cjs.js +1 -1
- package/dist/libs/get/getOrientation.es.js +1 -1
- package/dist/libs/get/getParentList.cjs.js +1 -1
- package/dist/libs/get/getParentList.es.js +1 -1
- package/dist/libs/get/getQueryParams.cjs.js +1 -1
- package/dist/libs/get/getQueryParams.es.js +1 -1
- package/dist/libs/get/getRem.cjs.js +1 -1
- package/dist/libs/get/getRem.es.js +1 -1
- package/dist/libs/get/getScrollbarWidth.cjs.js +1 -1
- package/dist/libs/get/getScrollbarWidth.es.js +1 -1
- package/dist/libs/get/getSessionStorage.cjs.js +1 -1
- package/dist/libs/get/getSessionStorage.es.js +1 -1
- package/dist/libs/get/getStringLength.cjs.js +1 -1
- package/dist/libs/get/getStringLength.es.js +1 -1
- package/dist/libs/get/getStylePropertyValue.cjs.js +1 -1
- package/dist/libs/get/getStylePropertyValue.es.js +1 -1
- package/dist/libs/get/getStylePropertyValueToNumber.cjs.js +1 -1
- package/dist/libs/get/getStylePropertyValueToNumber.es.js +1 -1
- package/dist/libs/get/getUaData.cjs.js +1 -1
- package/dist/libs/get/getUaData.es.js +1 -1
- package/dist/libs/is/isBetweenDateTime.cjs.js +1 -1
- package/dist/libs/is/isBetweenDateTime.es.js +1 -1
- package/dist/libs/is/isExistAllElements.cjs.js +1 -1
- package/dist/libs/is/isExistAllElements.es.js +1 -1
- package/dist/libs/is/isIpad.cjs.js +1 -1
- package/dist/libs/is/isIpad.es.js +1 -1
- package/dist/libs/is/isKeyExists.cjs.js +1 -1
- package/dist/libs/is/isKeyExists.es.js +1 -1
- package/dist/libs/is/isSafari.cjs.js +1 -1
- package/dist/libs/is/isSafari.es.js +1 -1
- package/dist/libs/is/isScrollable.cjs.js +1 -1
- package/dist/libs/is/isScrollable.es.js +1 -1
- package/dist/libs/is/isTouchSupport.cjs.js +1 -1
- package/dist/libs/is/isTouchSupport.es.js +1 -1
- package/dist/libs/remove/removeAllHtmlTags.cjs.js +1 -1
- package/dist/libs/remove/removeAllHtmlTags.es.js +1 -1
- package/dist/libs/remove/removeAttribute.cjs.js +1 -1
- package/dist/libs/remove/removeAttribute.es.js +1 -1
- package/dist/libs/remove/removeSessionStorage.cjs.js +1 -1
- package/dist/libs/remove/removeSessionStorage.es.js +1 -1
- package/dist/libs/remove/removeStylePropertyValue.cjs.js +1 -1
- package/dist/libs/remove/removeStylePropertyValue.es.js +1 -1
- package/dist/libs/set/set100vh.cjs.js +1 -1
- package/dist/libs/set/set100vh.es.js +1 -1
- package/dist/libs/set/set100vw.cjs.js +1 -1
- package/dist/libs/set/set100vw.es.js +1 -1
- package/dist/libs/set/setAttribute.cjs.js +1 -1
- package/dist/libs/set/setAttribute.es.js +1 -1
- package/dist/libs/set/setScrollPositionToCenter.cjs.js +1 -1
- package/dist/libs/set/setScrollPositionToCenter.es.js +1 -1
- package/dist/libs/set/setSessionStorage.cjs.js +1 -1
- package/dist/libs/set/setSessionStorage.es.js +1 -1
- package/dist/libs/set/setStylePropertyValue.cjs.js +1 -1
- package/dist/libs/set/setStylePropertyValue.es.js +1 -1
- package/dist/libs/to/toBoolean.cjs.js +1 -1
- package/dist/libs/to/toBoolean.es.js +1 -1
- package/dist/libs/to/toPositiveNumber.cjs.js +1 -1
- package/dist/libs/to/toPositiveNumber.es.js +1 -1
- package/dist/libs/transform/wrapTextWithSpans.cjs.js +1 -1
- package/dist/libs/transform/wrapTextWithSpans.es.js +1 -1
- package/dist/libs/wait/sleep.cjs.js +1 -1
- package/dist/libs/wait/sleep.es.js +1 -1
- package/dist/libs/wait/waitForAllMediaLoaded.cjs.js +1 -1
- package/dist/libs/wait/waitForAllMediaLoaded.es.js +1 -1
- package/dist/node_modules/dayjs/plugin/isBetween.cjs.js +1 -1
- package/dist/node_modules/dayjs/plugin/isBetween.es.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
# umaki
|
|
2
2
|
|
|
3
|
+
<p>
|
|
4
|
+
<img alt="NPM Version" src="https://img.shields.io/npm/v/umaki">
|
|
5
|
+
<img alt="NPM Type Definitions" src="https://img.shields.io/npm/types/umaki">
|
|
6
|
+
<img alt="NPM Downloads" src="https://img.shields.io/npm/dy/umaki">
|
|
7
|
+
</p>
|
|
8
|
+
|
|
3
9
|

|
|
4
10
|
|
|
5
|
-
|
|
6
|
-
基本的には私がよく使っているものを中心に追加していきます。
|
|
7
|
-
パッケージの中身や種類のリクエストがあれば、Issueを立ててください。
|
|
11
|
+
A package that allows you to import frequently used utilities for web development in one place. Primarily, it includes utilities that I often use. If you have any requests for the contents or types of utilities, please open an issue.
|
|
8
12
|
|
|
9
|
-
##
|
|
13
|
+
## Usage
|
|
10
14
|
|
|
11
15
|
``` ts
|
|
12
16
|
import { foo } from 'umaki'
|
|
13
17
|
```
|
|
14
18
|
|
|
15
|
-
##
|
|
19
|
+
## List of Utilities
|
|
16
20
|
|
|
17
21
|
- [Control](#control)
|
|
18
22
|
- [bgScrollStop](#bgscrollstop)
|
|
@@ -22,6 +26,9 @@ import { foo } from 'umaki'
|
|
|
22
26
|
- [Convert](#convert)
|
|
23
27
|
- [changeDateStringToSpecificFormat](#changedatestringtospecificformat)
|
|
24
28
|
- [jsonStringToJsonObject](#jsonstringtojsonobject)
|
|
29
|
+
- [EventControl](#eventcontrol)
|
|
30
|
+
- [debounce](#debounce)
|
|
31
|
+
- [throttle](#throttle)
|
|
25
32
|
- [Get](#get)
|
|
26
33
|
- [getAspectRatio](#getaspectratio)
|
|
27
34
|
- [getClassNames](#getclassnames)
|
|
@@ -71,17 +78,20 @@ import { foo } from 'umaki'
|
|
|
71
78
|
|
|
72
79
|
### bgScrollStop
|
|
73
80
|
|
|
74
|
-
|
|
81
|
+
A function that stops scrolling.
|
|
75
82
|
|
|
76
83
|
``` ts
|
|
77
84
|
import { bgScrollStop } from 'umaki'
|
|
78
85
|
|
|
79
|
-
bgScrollStop()
|
|
86
|
+
bgScrollStop() // scroll stop
|
|
87
|
+
bgScrollStop(false) // scroll start
|
|
80
88
|
```
|
|
81
89
|
|
|
90
|
+
[View file →](src/libs/control/bgScrollStop.ts)
|
|
91
|
+
|
|
82
92
|
### pd
|
|
83
93
|
|
|
84
|
-
|
|
94
|
+
A function that prevents the default event behavior.
|
|
85
95
|
|
|
86
96
|
``` ts
|
|
87
97
|
import { pd } from 'umaki'
|
|
@@ -89,36 +99,48 @@ import { pd } from 'umaki'
|
|
|
89
99
|
document.getElementById('myElement').addEventListener('click', pd)
|
|
90
100
|
```
|
|
91
101
|
|
|
92
|
-
|
|
102
|
+
[View file →](src/libs/control/pd.ts)
|
|
103
|
+
|
|
104
|
+
### scrollToHash (Promise)
|
|
93
105
|
|
|
94
|
-
|
|
106
|
+
A function that scrolls to a specific hash position.
|
|
95
107
|
|
|
96
108
|
``` ts
|
|
97
109
|
import { scrollToHash } from 'umaki'
|
|
98
110
|
|
|
99
|
-
;(async(
|
|
111
|
+
;(async () => {
|
|
100
112
|
await scrollToHash('#target')
|
|
101
|
-
console.log('
|
|
102
|
-
|
|
113
|
+
console.log('Scrolled!')
|
|
114
|
+
|
|
115
|
+
// smooth scroll
|
|
116
|
+
await scrollToHash('#target', true)
|
|
117
|
+
|
|
118
|
+
// smooth scroll + offset
|
|
119
|
+
await scrollToHash('#target', true, 100)
|
|
120
|
+
})()
|
|
103
121
|
```
|
|
104
122
|
|
|
123
|
+
[View file →](src/libs/control/scrollToHash.ts)
|
|
124
|
+
|
|
105
125
|
### videoPlayControl
|
|
106
126
|
|
|
107
|
-
|
|
127
|
+
A function that controls the playback of a video element.
|
|
108
128
|
|
|
109
129
|
``` ts
|
|
110
130
|
import { videoPlayControl } from 'umaki'
|
|
111
131
|
|
|
112
132
|
const videoElement = document.getElementById('myVideo')
|
|
113
|
-
videoPlayControl(videoElement, true) //
|
|
114
|
-
videoPlayControl(videoElement, false) //
|
|
133
|
+
videoPlayControl(videoElement, true) // play
|
|
134
|
+
videoPlayControl(videoElement, false) // pause
|
|
115
135
|
```
|
|
116
136
|
|
|
137
|
+
[View file →](src/libs/control/videoPlayControl.ts)
|
|
138
|
+
|
|
117
139
|
## Convert
|
|
118
140
|
|
|
119
141
|
### changeDateStringToSpecificFormat
|
|
120
142
|
|
|
121
|
-
|
|
143
|
+
A function that converts a date string to a specific format.
|
|
122
144
|
|
|
123
145
|
```ts
|
|
124
146
|
import { changeDateStringToSpecificFormat } from 'umaki'
|
|
@@ -128,9 +150,11 @@ const formattedDate = changeDateStringToSpecificFormat(date, 'MM/DD/YYYY')
|
|
|
128
150
|
console.log(formattedDate) // '10/05/2023'
|
|
129
151
|
```
|
|
130
152
|
|
|
153
|
+
[View file →](src/libs/convert/changeDateStringToSpecificFormat.ts)
|
|
154
|
+
|
|
131
155
|
### jsonStringToJsonObject
|
|
132
156
|
|
|
133
|
-
JSON
|
|
157
|
+
A function that converts a JSON string to a JSON object.
|
|
134
158
|
|
|
135
159
|
```ts
|
|
136
160
|
import { jsonStringToJsonObject } from 'umaki'
|
|
@@ -140,11 +164,47 @@ const jsonObject = jsonStringToJsonObject(jsonString)
|
|
|
140
164
|
console.log(jsonObject) // { name: 'John', age: 30 }
|
|
141
165
|
```
|
|
142
166
|
|
|
167
|
+
[View file →](src/libs/convert/jsonStringToJsonObject.ts)
|
|
168
|
+
|
|
169
|
+
## EventControl
|
|
170
|
+
|
|
171
|
+
### debounce
|
|
172
|
+
|
|
173
|
+
A function that limits the number of times a function is called to at most one time over a specified time period.
|
|
174
|
+
|
|
175
|
+
```ts
|
|
176
|
+
import { debounce } from 'umaki'
|
|
177
|
+
|
|
178
|
+
const debouncedFunction = debounce(() => {
|
|
179
|
+
console.log('Debounced!')
|
|
180
|
+
}, 300)
|
|
181
|
+
|
|
182
|
+
window.addEventListener('resize', debouncedFunction)
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
[View file →](src/libs/eventControl/debounce.ts)
|
|
186
|
+
|
|
187
|
+
### throttle
|
|
188
|
+
|
|
189
|
+
A function that limits the number of times a function is called to a maximum of once in a specified period.
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
import { throttle } from 'umaki'
|
|
193
|
+
|
|
194
|
+
const throttledFunction = throttle(() => {
|
|
195
|
+
console.log('Throttled!')
|
|
196
|
+
}, 300)
|
|
197
|
+
|
|
198
|
+
window.addEventListener('scroll', throttledFunction)
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
[View file →](src/libs/eventControl/throttle.ts)
|
|
202
|
+
|
|
143
203
|
## Get
|
|
144
204
|
|
|
145
205
|
### getAspectRatio
|
|
146
206
|
|
|
147
|
-
|
|
207
|
+
A function that returns the aspect ratio of the specified width and height.
|
|
148
208
|
|
|
149
209
|
```ts
|
|
150
210
|
import { getAspectRatio } from 'umaki'
|
|
@@ -153,9 +213,11 @@ const aspectRatio = getAspectRatio(1920, 1080)
|
|
|
153
213
|
console.log(aspectRatio) // { w: 16, h: 9 }
|
|
154
214
|
```
|
|
155
215
|
|
|
216
|
+
[View file →](src/libs/get/getAspectRatio.ts)
|
|
217
|
+
|
|
156
218
|
### getClassNames
|
|
157
219
|
|
|
158
|
-
|
|
220
|
+
A function that retrieves the class names of the specified HTML element as an array.
|
|
159
221
|
|
|
160
222
|
```ts
|
|
161
223
|
import { getClassNames } from 'umaki'
|
|
@@ -166,33 +228,39 @@ const classNames = getClassNames(element)
|
|
|
166
228
|
console.log(classNames) // ['class1', 'class2', 'class3']
|
|
167
229
|
```
|
|
168
230
|
|
|
231
|
+
[View file →](src/libs/get/getClassNames.ts)
|
|
232
|
+
|
|
169
233
|
### getDocumentHeight
|
|
170
234
|
|
|
171
|
-
|
|
235
|
+
A function that retrieves the height of the document.
|
|
172
236
|
|
|
173
237
|
```ts
|
|
174
238
|
import { getDocumentHeight } from 'umaki'
|
|
175
239
|
|
|
176
240
|
const height = getDocumentHeight()
|
|
177
|
-
console.log(height)
|
|
241
|
+
console.log(height)
|
|
178
242
|
```
|
|
179
243
|
|
|
244
|
+
[View file →](src/libs/get/getDocumentHeight.ts)
|
|
245
|
+
|
|
180
246
|
### getEventPaths
|
|
181
247
|
|
|
182
|
-
|
|
248
|
+
A function that retrieves the event paths.
|
|
183
249
|
|
|
184
250
|
```ts
|
|
185
251
|
import { getEventPaths } from 'umaki'
|
|
186
252
|
|
|
187
253
|
document.addEventListener('click', (event) => {
|
|
188
254
|
const paths = getEventPaths(event)
|
|
189
|
-
console.log(paths)
|
|
255
|
+
console.log(paths)
|
|
190
256
|
})
|
|
191
257
|
```
|
|
192
258
|
|
|
259
|
+
[View file →](src/libs/get/getEventPaths.ts)
|
|
260
|
+
|
|
193
261
|
### getGcd
|
|
194
262
|
|
|
195
|
-
|
|
263
|
+
A function that calculates the greatest common divisor of two numbers.
|
|
196
264
|
|
|
197
265
|
```ts
|
|
198
266
|
import { getGcd } from 'umaki'
|
|
@@ -201,43 +269,56 @@ const gcd = getGcd(48, 18)
|
|
|
201
269
|
console.log(gcd) // 6
|
|
202
270
|
```
|
|
203
271
|
|
|
272
|
+
[View file →](src/libs/get/getGcd.ts)
|
|
273
|
+
|
|
204
274
|
### getOrientation
|
|
205
275
|
|
|
206
|
-
|
|
276
|
+
A function that retrieves the current orientation of the device.
|
|
207
277
|
|
|
208
278
|
```ts
|
|
209
279
|
import { getOrientation } from 'umaki'
|
|
210
280
|
|
|
211
281
|
const orientation = getOrientation()
|
|
212
|
-
console.log(orientation) // 'landscape'
|
|
282
|
+
console.log(orientation) // 'landscape' or 'portrait'
|
|
213
283
|
```
|
|
214
284
|
|
|
285
|
+
[View file →](src/libs/get/getOrientation.ts)
|
|
286
|
+
|
|
215
287
|
### getParentList
|
|
216
288
|
|
|
217
|
-
|
|
289
|
+
A function that recursively retrieves the parent elements of the specified HTML element.
|
|
218
290
|
|
|
219
291
|
```ts
|
|
220
292
|
import { getParentList } from 'umaki'
|
|
221
293
|
|
|
222
294
|
const element = document.createElement('div')
|
|
223
295
|
const parentList = getParentList(element)
|
|
224
|
-
console.log(parentList)
|
|
296
|
+
console.log(parentList)
|
|
225
297
|
```
|
|
226
298
|
|
|
299
|
+
[View file →](src/libs/get/getParentList.ts)
|
|
300
|
+
|
|
227
301
|
### getQueryParams
|
|
228
302
|
|
|
229
|
-
URL
|
|
303
|
+
A function that retrieves the query parameters from the URL.
|
|
304
|
+
This is a wrapper around query-string, so you can specify [options](https://github.com/sindresorhus/query-string) in the second argument.
|
|
230
305
|
|
|
231
306
|
```ts
|
|
232
307
|
import { getQueryParams } from 'umaki'
|
|
233
308
|
|
|
234
|
-
const params = getQueryParams('test')
|
|
235
|
-
console.log(params) //
|
|
309
|
+
const params = getQueryParams('test') // https://example.com?test=123
|
|
310
|
+
console.log(params) // 123
|
|
311
|
+
|
|
312
|
+
// Example of specifying options
|
|
313
|
+
const params = getQueryParams('test', { parseNumbers: false })
|
|
314
|
+
console.log(params) // '123'
|
|
236
315
|
```
|
|
237
316
|
|
|
317
|
+
[View file →](src/libs/get/getQueryParams.ts)
|
|
318
|
+
|
|
238
319
|
### getRem
|
|
239
320
|
|
|
240
|
-
|
|
321
|
+
A function that converts a pixel value to rem units.
|
|
241
322
|
|
|
242
323
|
```ts
|
|
243
324
|
import { getRem } from 'umaki'
|
|
@@ -246,31 +327,37 @@ const remValue = getRem(16)
|
|
|
246
327
|
console.log(remValue) // '1rem'
|
|
247
328
|
```
|
|
248
329
|
|
|
330
|
+
[View file →](src/libs/get/getRem.ts)
|
|
331
|
+
|
|
249
332
|
### getScrollbarWidth
|
|
250
333
|
|
|
251
|
-
|
|
334
|
+
A function that retrieves the width of the scrollbar.
|
|
252
335
|
|
|
253
336
|
```ts
|
|
254
337
|
import { getScrollbarWidth } from 'umaki'
|
|
255
338
|
|
|
256
339
|
const scrollbarWidth = getScrollbarWidth()
|
|
257
|
-
console.log(scrollbarWidth) //
|
|
340
|
+
console.log(scrollbarWidth) // 15
|
|
258
341
|
```
|
|
259
342
|
|
|
343
|
+
[View file →](src/libs/get/getScrollbarWidth.ts)
|
|
344
|
+
|
|
260
345
|
### getSessionStorage
|
|
261
346
|
|
|
262
|
-
|
|
347
|
+
A function that retrieves a value from session storage.
|
|
263
348
|
|
|
264
349
|
```ts
|
|
265
350
|
import { getSessionStorage } from 'umaki'
|
|
266
351
|
|
|
267
352
|
const value = getSessionStorage('testKey')
|
|
268
|
-
console.log(value) //
|
|
353
|
+
console.log(value) // 'testValue'
|
|
269
354
|
```
|
|
270
355
|
|
|
356
|
+
[View file →](src/libs/get/getSessionStorage.ts)
|
|
357
|
+
|
|
271
358
|
### getStringLength
|
|
272
359
|
|
|
273
|
-
|
|
360
|
+
A function that retrieves the length of a string (considering Unicode characters).
|
|
274
361
|
|
|
275
362
|
```ts
|
|
276
363
|
import { getStringLength } from 'umaki'
|
|
@@ -279,44 +366,60 @@ const length = getStringLength('こんにちは')
|
|
|
279
366
|
console.log(length) // 5
|
|
280
367
|
```
|
|
281
368
|
|
|
369
|
+
[View file →](src/libs/get/getStringLength.ts)
|
|
370
|
+
|
|
282
371
|
### getStylePropertyValue
|
|
283
372
|
|
|
284
|
-
|
|
373
|
+
A function that retrieves the value of the specified CSS custom property.
|
|
285
374
|
|
|
286
375
|
```ts
|
|
287
376
|
import { getStylePropertyValue } from 'umaki'
|
|
288
377
|
|
|
289
378
|
const value = getStylePropertyValue('--custom-property')
|
|
290
|
-
console.log(value)
|
|
379
|
+
console.log(value)
|
|
291
380
|
```
|
|
292
381
|
|
|
382
|
+
[View file →](src/libs/get/getStylePropertyValue.ts)
|
|
383
|
+
|
|
293
384
|
### getStylePropertyValueToNumber
|
|
294
385
|
|
|
295
|
-
|
|
386
|
+
A function that retrieves the value of the specified CSS custom property as a number.
|
|
296
387
|
|
|
297
388
|
```ts
|
|
298
389
|
import { getStylePropertyValueToNumber } from 'umaki'
|
|
299
390
|
|
|
300
391
|
const value = getStylePropertyValueToNumber('--custom-property')
|
|
301
|
-
console.log(value)
|
|
392
|
+
console.log(value)
|
|
302
393
|
```
|
|
303
394
|
|
|
395
|
+
[View file →](src/libs/get/getStylePropertyValueToNumber.ts)
|
|
396
|
+
|
|
304
397
|
### getUaData
|
|
305
398
|
|
|
306
|
-
|
|
399
|
+
A function that retrieves user agent information.
|
|
307
400
|
|
|
308
401
|
```ts
|
|
309
402
|
import { getUaData } from 'umaki'
|
|
310
403
|
|
|
311
404
|
const uaData = getUaData()
|
|
312
|
-
console.log(uaData)
|
|
405
|
+
console.log(uaData)
|
|
406
|
+
// {
|
|
407
|
+
// browserName: 'chrome',
|
|
408
|
+
// browserVersion: '91.0.4472.124',
|
|
409
|
+
// browserEngine: 'blink',
|
|
410
|
+
// osName: 'windows',
|
|
411
|
+
// type: 'desktop',
|
|
412
|
+
// touchSupport: false
|
|
413
|
+
// }
|
|
313
414
|
```
|
|
314
415
|
|
|
416
|
+
[View file →](src/libs/get/getUaData.ts)
|
|
417
|
+
|
|
315
418
|
## Is
|
|
316
419
|
|
|
317
420
|
### isBetweenDateTime
|
|
318
421
|
|
|
319
|
-
|
|
422
|
+
A function that checks if the current date is between two specified dates.
|
|
320
423
|
|
|
321
424
|
```ts
|
|
322
425
|
import { isBetweenDateTime } from 'umaki'
|
|
@@ -324,58 +427,68 @@ import { isBetweenDateTime } from 'umaki'
|
|
|
324
427
|
const dateA = '2023-10-01'
|
|
325
428
|
const dateB = '2023-10-10'
|
|
326
429
|
const result = isBetweenDateTime(dateA, dateB)
|
|
327
|
-
console.log(result) // true
|
|
430
|
+
console.log(result) // true or false
|
|
328
431
|
```
|
|
329
432
|
|
|
433
|
+
[View file →](src/libs/is/isBetweenDateTime.ts)
|
|
434
|
+
|
|
330
435
|
### isExistAllElements
|
|
331
436
|
|
|
332
|
-
|
|
437
|
+
A function that checks if all elements exist.
|
|
333
438
|
|
|
334
439
|
```ts
|
|
335
440
|
import { isExistAllElements } from 'umaki'
|
|
336
441
|
|
|
337
442
|
const elements = [document.createElement('div'), document.createElement('span')]
|
|
338
443
|
const result = isExistAllElements(elements)
|
|
339
|
-
console.log(result) // true
|
|
444
|
+
console.log(result) // true or false
|
|
340
445
|
```
|
|
341
446
|
|
|
447
|
+
[View file →](src/libs/is/isExistAllElements.ts)
|
|
448
|
+
|
|
342
449
|
### isIpad
|
|
343
450
|
|
|
344
|
-
|
|
451
|
+
A function that checks if the device is an iPad.
|
|
345
452
|
|
|
346
453
|
```ts
|
|
347
454
|
import { isIpad } from 'umaki'
|
|
348
455
|
|
|
349
456
|
const result = isIpad()
|
|
350
|
-
console.log(result) // true
|
|
457
|
+
console.log(result) // true or false
|
|
351
458
|
```
|
|
352
459
|
|
|
460
|
+
[View file →](src/libs/is/isIpad.ts)
|
|
461
|
+
|
|
353
462
|
### isKeyExists
|
|
354
463
|
|
|
355
|
-
|
|
464
|
+
A function that checks if a specific key exists in an object.
|
|
356
465
|
|
|
357
466
|
```ts
|
|
358
467
|
import { isKeyExists } from 'umaki'
|
|
359
468
|
|
|
360
469
|
const obj = { a: 1, b: 2 }
|
|
361
470
|
const result = isKeyExists(obj, 'a')
|
|
362
|
-
console.log(result) // true
|
|
471
|
+
console.log(result) // true or false
|
|
363
472
|
```
|
|
364
473
|
|
|
474
|
+
[View file →](src/libs/is/isKeyExists.ts)
|
|
475
|
+
|
|
365
476
|
### isSafari
|
|
366
477
|
|
|
367
|
-
|
|
478
|
+
A function that checks if the browser is Safari.
|
|
368
479
|
|
|
369
480
|
```ts
|
|
370
481
|
import { isSafari } from 'umaki'
|
|
371
482
|
|
|
372
483
|
const result = isSafari()
|
|
373
|
-
console.log(result) // true
|
|
484
|
+
console.log(result) // true or false
|
|
374
485
|
```
|
|
375
486
|
|
|
487
|
+
[View file →](src/libs/is/isSafari.ts)
|
|
488
|
+
|
|
376
489
|
### isScrollable
|
|
377
490
|
|
|
378
|
-
|
|
491
|
+
A function that checks if an element is scrollable.
|
|
379
492
|
|
|
380
493
|
```ts
|
|
381
494
|
import { isScrollable } from 'umaki'
|
|
@@ -384,25 +497,29 @@ const element = document.createElement('div')
|
|
|
384
497
|
element.style.overflow = 'auto'
|
|
385
498
|
element.innerHTML = '<div style="height: 200px;"></div>'
|
|
386
499
|
const result = isScrollable(element)
|
|
387
|
-
console.log(result) // true
|
|
500
|
+
console.log(result) // true or false
|
|
388
501
|
```
|
|
389
502
|
|
|
503
|
+
[View file →](src/libs/is/isScrollable.ts)
|
|
504
|
+
|
|
390
505
|
### isTouchSupport
|
|
391
506
|
|
|
392
|
-
|
|
507
|
+
A function that checks if the device supports touch.
|
|
393
508
|
|
|
394
509
|
```ts
|
|
395
510
|
import { isTouchSupport } from 'umaki'
|
|
396
511
|
|
|
397
512
|
const result = isTouchSupport()
|
|
398
|
-
console.log(result) // true
|
|
513
|
+
console.log(result) // true or false
|
|
399
514
|
```
|
|
400
515
|
|
|
516
|
+
[View file →](src/libs/is/isTouchSupport.ts)
|
|
517
|
+
|
|
401
518
|
## Remove
|
|
402
519
|
|
|
403
520
|
### removeAllHtmlTags
|
|
404
521
|
|
|
405
|
-
|
|
522
|
+
A function that removes all HTML tags from a string.
|
|
406
523
|
|
|
407
524
|
```ts
|
|
408
525
|
import { removeAllHtmlTags } from 'umaki'
|
|
@@ -412,9 +529,11 @@ const output = removeAllHtmlTags(input)
|
|
|
412
529
|
console.log(output) // 'Hello World!'
|
|
413
530
|
```
|
|
414
531
|
|
|
532
|
+
[View file →](src/libs/remove/removeAllHtmlTags.ts)
|
|
533
|
+
|
|
415
534
|
### removeAttribute
|
|
416
535
|
|
|
417
|
-
|
|
536
|
+
A function that removes an attribute from the specified HTML element.
|
|
418
537
|
|
|
419
538
|
```ts
|
|
420
539
|
import { removeAttribute } from 'umaki'
|
|
@@ -425,9 +544,11 @@ removeAttribute(element, 'data-test')
|
|
|
425
544
|
console.log(element.hasAttribute('data-test')) // false
|
|
426
545
|
```
|
|
427
546
|
|
|
547
|
+
[View file →](src/libs/remove/removeAttribute.ts)
|
|
548
|
+
|
|
428
549
|
### removeSessionStorage
|
|
429
550
|
|
|
430
|
-
|
|
551
|
+
A function that removes an item with the specified key from session storage.
|
|
431
552
|
|
|
432
553
|
```ts
|
|
433
554
|
import { removeSessionStorage } from 'umaki'
|
|
@@ -437,9 +558,11 @@ removeSessionStorage(key)
|
|
|
437
558
|
console.log(sessionStorage.getItem(key)) // null
|
|
438
559
|
```
|
|
439
560
|
|
|
561
|
+
[View file →](src/libs/remove/removeSessionStorage.ts)
|
|
562
|
+
|
|
440
563
|
### removeStylePropertyValue
|
|
441
564
|
|
|
442
|
-
|
|
565
|
+
A function that removes the specified CSS custom property.
|
|
443
566
|
|
|
444
567
|
```ts
|
|
445
568
|
import { removeStylePropertyValue } from 'umaki'
|
|
@@ -449,11 +572,13 @@ removeStylePropertyValue(key)
|
|
|
449
572
|
console.log(getComputedStyle(document.documentElement).getPropertyValue(key)) // ''
|
|
450
573
|
```
|
|
451
574
|
|
|
575
|
+
[View file →](src/libs/remove/removeStylePropertyValue.ts)
|
|
576
|
+
|
|
452
577
|
## Set
|
|
453
578
|
|
|
454
579
|
### set100vh
|
|
455
580
|
|
|
456
|
-
|
|
581
|
+
A function that sets a CSS variable to 100vh to address viewport unit issues on mobile devices.
|
|
457
582
|
|
|
458
583
|
```ts
|
|
459
584
|
import { set100vh } from 'umaki'
|
|
@@ -461,9 +586,11 @@ import { set100vh } from 'umaki'
|
|
|
461
586
|
set100vh()
|
|
462
587
|
```
|
|
463
588
|
|
|
589
|
+
[View file →](src/libs/set/set100vh.ts)
|
|
590
|
+
|
|
464
591
|
### set100vw
|
|
465
592
|
|
|
466
|
-
|
|
593
|
+
A function that sets a CSS variable to 100vw minus the scrollbar width.
|
|
467
594
|
|
|
468
595
|
```ts
|
|
469
596
|
import { set100vw } from 'umaki'
|
|
@@ -471,9 +598,11 @@ import { set100vw } from 'umaki'
|
|
|
471
598
|
set100vw()
|
|
472
599
|
```
|
|
473
600
|
|
|
601
|
+
[View file →](src/libs/set/set100vw.ts)
|
|
602
|
+
|
|
474
603
|
### setAttribute
|
|
475
604
|
|
|
476
|
-
|
|
605
|
+
A function that sets an attribute on the specified HTML element.
|
|
477
606
|
|
|
478
607
|
```ts
|
|
479
608
|
import { setAttribute } from 'umaki'
|
|
@@ -483,9 +612,11 @@ setAttribute(element, 'data-test', 'value')
|
|
|
483
612
|
console.log(element.getAttribute('data-test')) // 'value'
|
|
484
613
|
```
|
|
485
614
|
|
|
615
|
+
[View file →](src/libs/set/setAttribute.ts)
|
|
616
|
+
|
|
486
617
|
### setScrollPositionToCenter
|
|
487
618
|
|
|
488
|
-
|
|
619
|
+
A function that adjusts the horizontal scroll position of the root element to center the target element.
|
|
489
620
|
|
|
490
621
|
```ts
|
|
491
622
|
import { setScrollPositionToCenter } from 'umaki'
|
|
@@ -495,9 +626,11 @@ const targetElement = document.getElementById('target')
|
|
|
495
626
|
setScrollPositionToCenter(rootElement, targetElement)
|
|
496
627
|
```
|
|
497
628
|
|
|
629
|
+
[View file →](src/libs/set/setScrollPositionToCenter.ts)
|
|
630
|
+
|
|
498
631
|
### setSessionStorage
|
|
499
632
|
|
|
500
|
-
|
|
633
|
+
A function that sets a value in session storage.
|
|
501
634
|
|
|
502
635
|
```ts
|
|
503
636
|
import { setSessionStorage } from 'umaki'
|
|
@@ -508,9 +641,11 @@ setSessionStorage(key, value)
|
|
|
508
641
|
console.log(sessionStorage.getItem(key)) // 'testValue'
|
|
509
642
|
```
|
|
510
643
|
|
|
644
|
+
[View file →](src/libs/set/setSessionStorage.ts)
|
|
645
|
+
|
|
511
646
|
### setStylePropertyValue
|
|
512
647
|
|
|
513
|
-
|
|
648
|
+
A function that sets a CSS custom property on the root element.
|
|
514
649
|
|
|
515
650
|
```ts
|
|
516
651
|
import { setStylePropertyValue } from 'umaki'
|
|
@@ -521,11 +656,13 @@ setStylePropertyValue(key, value)
|
|
|
521
656
|
console.log(getComputedStyle(document.documentElement).getPropertyValue(key)) // 'blue'
|
|
522
657
|
```
|
|
523
658
|
|
|
659
|
+
[View file →](src/libs/set/setStylePropertyValue.ts)
|
|
660
|
+
|
|
524
661
|
## To
|
|
525
662
|
|
|
526
663
|
### toBoolean
|
|
527
664
|
|
|
528
|
-
|
|
665
|
+
A function that converts a string to a boolean value.
|
|
529
666
|
|
|
530
667
|
```ts
|
|
531
668
|
import { toBoolean } from 'umaki'
|
|
@@ -535,9 +672,11 @@ console.log(toBoolean('false')) // false
|
|
|
535
672
|
console.log(toBoolean('random')) // false
|
|
536
673
|
```
|
|
537
674
|
|
|
675
|
+
[View file →](src/libs/to/toBoolean.ts)
|
|
676
|
+
|
|
538
677
|
### toPositiveNumber
|
|
539
678
|
|
|
540
|
-
|
|
679
|
+
A function that converts a number to a positive number. Returns the absolute value if the number is negative.
|
|
541
680
|
|
|
542
681
|
```ts
|
|
543
682
|
import { toPositiveNumber } from 'umaki'
|
|
@@ -549,11 +688,13 @@ console.log(toPositiveNumber(-3.14)) // 3.14
|
|
|
549
688
|
console.log(toPositiveNumber(3.14)) // 3.14
|
|
550
689
|
```
|
|
551
690
|
|
|
691
|
+
[View file →](src/libs/to/toPositiveNumber.ts)
|
|
692
|
+
|
|
552
693
|
## Transform
|
|
553
694
|
|
|
554
695
|
### wrapTextWithSpans
|
|
555
696
|
|
|
556
|
-
HTML
|
|
697
|
+
A function that wraps each character of the text content of an HTML element with individual `<span>` elements.
|
|
557
698
|
|
|
558
699
|
```ts
|
|
559
700
|
import { wrapTextWithSpans } from 'umaki'
|
|
@@ -564,42 +705,52 @@ wrapTextWithSpans(element)
|
|
|
564
705
|
console.log(element.innerHTML) // '<span>h</span><span>e</span><span>l</span><span>l</span><span>o</span>'
|
|
565
706
|
```
|
|
566
707
|
|
|
708
|
+
[View file →](src/libs/transform/wrapTextWithSpans.ts)
|
|
709
|
+
|
|
567
710
|
## Wait
|
|
568
711
|
|
|
569
|
-
### sleep
|
|
712
|
+
### sleep (Promise)
|
|
570
713
|
|
|
571
|
-
|
|
714
|
+
A function that pauses execution for a specified amount of time.
|
|
572
715
|
|
|
573
716
|
```ts
|
|
574
717
|
import { sleep } from 'umaki'
|
|
575
718
|
|
|
576
719
|
;(async () => {
|
|
577
720
|
console.log('Start')
|
|
578
|
-
await sleep(1) //
|
|
721
|
+
await sleep(1) // 1ms wait
|
|
579
722
|
console.log('End')
|
|
580
723
|
})()
|
|
581
724
|
```
|
|
582
725
|
|
|
583
|
-
|
|
726
|
+
[View file →](src/libs/wait/sleep.ts)
|
|
727
|
+
|
|
728
|
+
### waitForAllMediaLoaded (Promise)
|
|
584
729
|
|
|
585
|
-
|
|
730
|
+
A function that waits until all images and videos in the document are fully loaded.
|
|
586
731
|
|
|
587
732
|
```ts
|
|
588
733
|
import { waitForAllMediaLoaded } from 'umaki'
|
|
589
734
|
|
|
590
735
|
;(async () => {
|
|
591
736
|
const allMediaLoaded = await waitForAllMediaLoaded()
|
|
592
|
-
console.log(allMediaLoaded) // true
|
|
737
|
+
console.log(allMediaLoaded) // true or false
|
|
738
|
+
|
|
739
|
+
// first view only
|
|
740
|
+
const firstViewMediaLoaded = await waitForAllMediaLoaded(true)
|
|
741
|
+
console.log(firstViewMediaLoaded) // true or false
|
|
593
742
|
})()
|
|
594
743
|
```
|
|
595
744
|
|
|
745
|
+
[View file →](src/libs/wait/waitForAllMediaLoaded.ts)
|
|
746
|
+
|
|
596
747
|
## Using for framework and tools
|
|
597
748
|
|
|
598
|
-
|
|
749
|
+
Specific usage for frameworks or various tools is described below.
|
|
599
750
|
|
|
600
751
|
### Astro or Vite
|
|
601
752
|
|
|
602
|
-
Astro
|
|
753
|
+
When using with Astro for SSR, add `umaki` to `vite.ssr.noExternal.`
|
|
603
754
|
|
|
604
755
|
``` ts
|
|
605
756
|
// astro.config.ts
|