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