umaki 0.10.0 → 0.10.1

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 CHANGED
@@ -78,11 +78,12 @@ console.log(breakpoint); // e.g. 768 (default) or custom value if set
78
78
 
79
79
  - [Callback](#callback)
80
80
  - [tap](#tap)
81
- - [tapAsync](#tapasync)
81
+ - [tapAsync](#tapasync-promise)
82
82
  - [Control](#control)
83
83
  - [bgScrollStop](#bgscrollstop)
84
+ - [copyToClipboard](#copytoclipboard-promise)
84
85
  - [pd](#pd)
85
- - [scrollToHash](#scrolltohash)
86
+ - [scrollToHash](#scrolltohash-promise)
86
87
  - [videoPlayControl](#videoplaycontrol)
87
88
  - [Convert](#convert)
88
89
  - [changeDateStringToSpecificFormat](#changedatestringtospecificformat)
@@ -100,6 +101,8 @@ console.log(breakpoint); // e.g. 768 (default) or custom value if set
100
101
  - [getOrientation](#getorientation)
101
102
  - [getParentList](#getparentlist)
102
103
  - [getQueryParams](#getqueryparams)
104
+ - [getRandomInt](#getrandomint)
105
+ - [getRelativeTime](#getrelativetime)
103
106
  - [getRem](#getrem)
104
107
  - [getScrollbarWidth](#getscrollbarwidth)
105
108
  - [getSessionStorage](#getsessionstorage)
@@ -111,8 +114,10 @@ console.log(breakpoint); // e.g. 768 (default) or custom value if set
111
114
  - [isAfterDateTime](#isafterdatetime)
112
115
  - [isBetweenDateTime](#isbetweendatetime)
113
116
  - [isExistAllElements](#isexistallelements)
117
+ - [isInViewport](#isinviewport)
114
118
  - [isIpad](#isipad)
115
119
  - [isKeyExists](#iskeyexists)
120
+ - [isOnline](#isonline)
116
121
  - [isSafari](#issafari)
117
122
  - [isScrollable](#isscrollable)
118
123
  - [isTouchSupport](#istouchsupport)
@@ -135,8 +140,8 @@ console.log(breakpoint); // e.g. 768 (default) or custom value if set
135
140
  - [Transform](#transform)
136
141
  - [wrapTextWithSpans](#wraptextwithspans)
137
142
  - [Wait](#wait)
138
- - [sleep](#sleep)
139
- - [waitForAllMediaLoaded](#waitforallmedialoaded)
143
+ - [sleep](#sleep-promise)
144
+ - [waitForAllMediaLoaded](#waitforallmedialoaded-promise)
140
145
  - [Security](#security)
141
146
  - [sanitizeHtml](#sanitizehtml)
142
147
  - [Advanced Usage](#advanced-usage)
@@ -218,6 +223,30 @@ bgScrollStop(false); // scroll start
218
223
 
219
224
  [View file →](src/libs/control/bg-scroll-stop.ts)
220
225
 
226
+ ### copyToClipboard (Promise)
227
+
228
+ A function that copies text to the clipboard using the modern Clipboard API.
229
+
230
+ ```ts
231
+ import { copyToClipboard } from "umaki";
232
+
233
+ // Basic usage
234
+ const success = await copyToClipboard("Hello, World!");
235
+ if (success) {
236
+ console.log("Copied to clipboard!");
237
+ } else {
238
+ console.log("Failed to copy");
239
+ }
240
+
241
+ // Use in click handler
242
+ button.addEventListener("click", async () => {
243
+ const copied = await copyToClipboard(textToCopy);
244
+ showToast(copied ? "Copied!" : "Copy failed");
245
+ });
246
+ ```
247
+
248
+ [View file →](src/libs/control/copy-to-clipboard.ts)
249
+
221
250
  ### pd
222
251
 
223
252
  A function that prevents the default event behavior.
@@ -497,6 +526,53 @@ const customParamWithOptions = getQueryParams("id", {
497
526
 
498
527
  [View file →](src/libs/get/get-query-params.ts)
499
528
 
529
+ ### getRandomInt
530
+
531
+ A function that returns a random integer between min (inclusive) and max (inclusive).
532
+
533
+ ```ts
534
+ import { getRandomInt } from "umaki";
535
+
536
+ // Basic usage
537
+ const random = getRandomInt(1, 10);
538
+ console.log(random); // Random integer from 1 to 10
539
+
540
+ // Use for array index
541
+ const items = ["apple", "banana", "orange"];
542
+ const randomItem = items[getRandomInt(0, items.length - 1)];
543
+
544
+ // Generate random delay
545
+ const delay = getRandomInt(100, 500);
546
+ await sleep(delay / 1000);
547
+ ```
548
+
549
+ [View file →](src/libs/get/get-random-int.ts)
550
+
551
+ ### getRelativeTime
552
+
553
+ A function that returns a human-readable relative time string (e.g., "3 minutes ago", "2 days ago") using the Intl.RelativeTimeFormat API.
554
+
555
+ ```ts
556
+ import { getRelativeTime } from "umaki";
557
+
558
+ // Basic usage (Japanese locale by default)
559
+ const pastDate = new Date(Date.now() - 5 * 60 * 1000);
560
+ console.log(getRelativeTime(pastDate)); // "5 分前"
561
+
562
+ // English locale
563
+ console.log(getRelativeTime(pastDate, "en")); // "5 minutes ago"
564
+
565
+ // Future dates
566
+ const futureDate = new Date(Date.now() + 2 * 24 * 60 * 60 * 1000);
567
+ console.log(getRelativeTime(futureDate)); // "2 日後"
568
+
569
+ // With timestamp or ISO string
570
+ console.log(getRelativeTime(1702800000000, "en")); // relative to now
571
+ console.log(getRelativeTime("2024-01-15T12:00:00Z", "en"));
572
+ ```
573
+
574
+ [View file →](src/libs/get/get-relative-time.ts)
575
+
500
576
  ### getRem
501
577
 
502
578
  A function that converts a pixel value to rem units.
@@ -650,6 +726,31 @@ console.log(result); // true or false
650
726
 
651
727
  [View file →](src/libs/is/is-exist-all-elements.ts)
652
728
 
729
+ ### isInViewport
730
+
731
+ A function that checks if an element is currently visible within the viewport.
732
+
733
+ ```ts
734
+ import { isInViewport } from "umaki";
735
+
736
+ const element = document.getElementById("target");
737
+
738
+ // Check if any part of the element is visible
739
+ const isVisible = isInViewport(element);
740
+ console.log(isVisible); // true or false
741
+
742
+ // Check if the entire element is visible
743
+ const isFullyVisible = isInViewport(element, { threshold: 1 });
744
+
745
+ // Check if at least 50% of the element is visible
746
+ const isHalfVisible = isInViewport(element, { threshold: 0.5 });
747
+
748
+ // With expanded viewport bounds (trigger 100px before element enters viewport)
749
+ const isNearViewport = isInViewport(element, { rootMargin: "100px" });
750
+ ```
751
+
752
+ [View file →](src/libs/is/is-in-viewport.ts)
753
+
653
754
  ### isIpad
654
755
 
655
756
  A function that checks if the device is an iPad.
@@ -677,6 +778,32 @@ console.log(result); // true or false
677
778
 
678
779
  [View file →](src/libs/is/is-key-exists.ts)
679
780
 
781
+ ### isOnline
782
+
783
+ A function that checks if the browser is currently online using the Navigator.onLine API.
784
+
785
+ ```ts
786
+ import { isOnline } from "umaki";
787
+
788
+ // Basic usage
789
+ if (isOnline()) {
790
+ // Perform network request
791
+ fetchData();
792
+ } else {
793
+ // Show offline message
794
+ showOfflineMessage();
795
+ }
796
+
797
+ // Use with event listeners for online/offline detection
798
+ window.addEventListener("online", () => {
799
+ if (isOnline()) {
800
+ console.log("Back online!");
801
+ }
802
+ });
803
+ ```
804
+
805
+ [View file →](src/libs/is/is-online.ts)
806
+
680
807
  ### isSafari
681
808
 
682
809
  A function that checks if the browser is Safari.
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const getStylePropertyValue = require("./get-style-property-value.cjs.js");
4
- const getStylePropertyValueToNumber = (key) => Number.parseInt(getStylePropertyValue.getStylePropertyValue(key), 10) || 0;
4
+ const getStylePropertyValueToNumber = (key) => Number.parseFloat(getStylePropertyValue.getStylePropertyValue(key)) || 0;
5
5
  exports.getStylePropertyValueToNumber = getStylePropertyValueToNumber;
@@ -1,5 +1,5 @@
1
1
  import { getStylePropertyValue } from "./get-style-property-value.es.js";
2
- const getStylePropertyValueToNumber = (key) => Number.parseInt(getStylePropertyValue(key), 10) || 0;
2
+ const getStylePropertyValueToNumber = (key) => Number.parseFloat(getStylePropertyValue(key)) || 0;
3
3
  export {
4
4
  getStylePropertyValueToNumber
5
5
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "umaki",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
4
4
  "description": "A utility that is often used in web production.",
5
5
  "author": "TsubasaHiga",
6
6
  "homepage": "https://github.com/TsubasaHiga/umaki",