umaki 0.9.2 → 0.9.3

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.
@@ -3,11 +3,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const getScrollbarWidth = require("../get/get-scrollbar-width.cjs.js");
4
4
  const bgScrollStop = (isStop = true) => {
5
5
  document.body.style.paddingRight = isStop ? `${getScrollbarWidth.getScrollbarWidth()}px` : "";
6
- if (isStop) {
7
- document.body.style.overflow = "hidden";
8
- }
9
- if (!isStop) {
10
- document.body.style.overflow = "";
11
- }
6
+ document.body.style.overflow = isStop ? "hidden" : "";
12
7
  };
13
8
  exports.bgScrollStop = bgScrollStop;
@@ -1,12 +1,7 @@
1
1
  import { getScrollbarWidth } from "../get/get-scrollbar-width.es.js";
2
2
  const bgScrollStop = (isStop = true) => {
3
3
  document.body.style.paddingRight = isStop ? `${getScrollbarWidth()}px` : "";
4
- if (isStop) {
5
- document.body.style.overflow = "hidden";
6
- }
7
- if (!isStop) {
8
- document.body.style.overflow = "";
9
- }
4
+ document.body.style.overflow = isStop ? "hidden" : "";
10
5
  };
11
6
  export {
12
7
  bgScrollStop
@@ -3,7 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const toBoolean = require("../to/to-boolean.cjs.js");
4
4
  const videoPlayControl = async (videoElement, state, currentTime) => {
5
5
  if (state && videoElement.paused) {
6
- const isPlaying = toBoolean.toBoolean(videoElement.dataset.playing);
6
+ const isPlaying = toBoolean.toBoolean(videoElement.dataset.playing ?? "");
7
7
  if (isPlaying) return;
8
8
  const playPromise = videoElement.play();
9
9
  if (playPromise === void 0) return;
@@ -1,7 +1,7 @@
1
1
  import { toBoolean } from "../to/to-boolean.es.js";
2
2
  const videoPlayControl = async (videoElement, state, currentTime) => {
3
3
  if (state && videoElement.paused) {
4
- const isPlaying = toBoolean(videoElement.dataset.playing);
4
+ const isPlaying = toBoolean(videoElement.dataset.playing ?? "");
5
5
  if (isPlaying) return;
6
6
  const playPromise = videoElement.play();
7
7
  if (playPromise === void 0) return;
@@ -3,10 +3,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const dayjs = require("dayjs");
4
4
  const timezone = require("../../_virtual/timezone.cjs.js");
5
5
  const utc = require("../../_virtual/utc.cjs.js");
6
+ dayjs.extend(utc.default);
7
+ dayjs.extend(timezone.default);
6
8
  const changeDateStringToSpecificFormat = (date, format = "YYYY年MM月DD日", tz) => {
7
9
  if (tz) {
8
- dayjs.extend(utc.default);
9
- dayjs.extend(timezone.default);
10
10
  return dayjs(date).tz(tz).format(format);
11
11
  }
12
12
  return dayjs(date).format(format);
@@ -1,10 +1,10 @@
1
1
  import dayjs from "dayjs";
2
2
  import timezone from "../../_virtual/timezone.es.js";
3
3
  import utc from "../../_virtual/utc.es.js";
4
+ dayjs.extend(utc);
5
+ dayjs.extend(timezone);
4
6
  const changeDateStringToSpecificFormat = (date, format = "YYYY年MM月DD日", tz) => {
5
7
  if (tz) {
6
- dayjs.extend(utc);
7
- dayjs.extend(timezone);
8
8
  return dayjs(date).tz(tz).format(format);
9
9
  }
10
10
  return dayjs(date).format(format);
@@ -3,7 +3,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const jsonStringToJsonObject = (string) => {
4
4
  try {
5
5
  return JSON.parse(string);
6
- } catch (error) {
6
+ } catch {
7
+ return void 0;
7
8
  }
8
9
  };
9
10
  exports.jsonStringToJsonObject = jsonStringToJsonObject;
@@ -4,4 +4,4 @@
4
4
  * @param string - The JSON string to be parsed.
5
5
  * @returns The parsed JSON object, or undefined if parsing fails.
6
6
  */
7
- export declare const jsonStringToJsonObject: (string: string) => any;
7
+ export declare const jsonStringToJsonObject: (string: string) => unknown;
@@ -1,7 +1,8 @@
1
1
  const jsonStringToJsonObject = (string) => {
2
2
  try {
3
3
  return JSON.parse(string);
4
- } catch (error) {
4
+ } catch {
5
+ return void 0;
5
6
  }
6
7
  };
7
8
  export {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const getEventPaths = (evt) => {
4
4
  let path = evt.composedPath?.() || null;
5
5
  const target = evt.target;
6
- if (path != null) {
6
+ if (path !== null) {
7
7
  path = path.indexOf(window) < 0 ? path.concat([window]) : path;
8
8
  return path;
9
9
  }
@@ -1,7 +1,7 @@
1
1
  const getEventPaths = (evt) => {
2
2
  let path = evt.composedPath?.() || null;
3
3
  const target = evt.target;
4
- if (path != null) {
4
+ if (path !== null) {
5
5
  path = path.indexOf(window) < 0 ? path.concat([window]) : path;
6
6
  return path;
7
7
  }
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const toPositiveNumber = require("../to/to-positive-number.cjs.js");
4
4
  const getGcd = (a, b) => {
5
- const positiveA = toPositiveNumber.toPositiveNumber(Math.abs(a));
6
- const positiveB = toPositiveNumber.toPositiveNumber(Math.abs(b));
5
+ const positiveA = toPositiveNumber.toPositiveNumber(a);
6
+ const positiveB = toPositiveNumber.toPositiveNumber(b);
7
7
  if (positiveB === 0) return positiveA;
8
8
  return getGcd(positiveB, positiveA % positiveB);
9
9
  };
@@ -1,7 +1,7 @@
1
1
  import { toPositiveNumber } from "../to/to-positive-number.es.js";
2
2
  const getGcd = (a, b) => {
3
- const positiveA = toPositiveNumber(Math.abs(a));
4
- const positiveB = toPositiveNumber(Math.abs(b));
3
+ const positiveA = toPositiveNumber(a);
4
+ const positiveB = toPositiveNumber(b);
5
5
  if (positiveB === 0) return positiveA;
6
6
  return getGcd(positiveB, positiveA % positiveB);
7
7
  };
@@ -4,4 +4,4 @@
4
4
  * @param key - The key of the session storage item to retrieve.
5
5
  * @returns The value associated with the key, or null if the key does not exist.
6
6
  */
7
- export declare const getSessionStorage: (key: string) => unknown | null;
7
+ export declare const getSessionStorage: (key: string) => unknown;
@@ -5,7 +5,7 @@ const isTouchSupport = () => {
5
5
  const hasTouchStart = "ontouchstart" in window && window.ontouchstart !== void 0;
6
6
  const hasTouchPoints = typeof navigator !== "undefined" && typeof navigator.maxTouchPoints === "number" && navigator.maxTouchPoints > 0;
7
7
  const hasMsTouchPoints = typeof navigator !== "undefined" && // We need to use type assertion since msMaxTouchPoints is not in standard Navigator type
8
- typeof navigator.msMaxTouchPoints === "number" && navigator.msMaxTouchPoints > 0;
8
+ typeof navigator.msMaxTouchPoints === "number" && (navigator.msMaxTouchPoints ?? 0) > 0;
9
9
  return hasTouchStart || hasTouchPoints || hasMsTouchPoints;
10
10
  };
11
11
  exports.isTouchSupport = isTouchSupport;
@@ -3,7 +3,7 @@ const isTouchSupport = () => {
3
3
  const hasTouchStart = "ontouchstart" in window && window.ontouchstart !== void 0;
4
4
  const hasTouchPoints = typeof navigator !== "undefined" && typeof navigator.maxTouchPoints === "number" && navigator.maxTouchPoints > 0;
5
5
  const hasMsTouchPoints = typeof navigator !== "undefined" && // We need to use type assertion since msMaxTouchPoints is not in standard Navigator type
6
- typeof navigator.msMaxTouchPoints === "number" && navigator.msMaxTouchPoints > 0;
6
+ typeof navigator.msMaxTouchPoints === "number" && (navigator.msMaxTouchPoints ?? 0) > 0;
7
7
  return hasTouchStart || hasTouchPoints || hasMsTouchPoints;
8
8
  };
9
9
  export {
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const DOMPurify = require("isomorphic-dompurify");
4
- function htmlSanitize(html, config = {}) {
4
+ const htmlSanitize = (html, config = {}) => {
5
5
  return DOMPurify.sanitize(html, config);
6
- }
6
+ };
7
7
  exports.htmlSanitize = htmlSanitize;
@@ -6,4 +6,4 @@ import { default as DOMPurify } from 'isomorphic-dompurify';
6
6
  * @param config - Optional configuration for DOMPurify.
7
7
  * @returns The sanitized HTML string.
8
8
  */
9
- export declare function htmlSanitize(html: string, config?: Parameters<typeof DOMPurify.sanitize>[1]): string;
9
+ export declare const htmlSanitize: (html: string, config?: Parameters<typeof DOMPurify.sanitize>[1]) => string;
@@ -1,7 +1,7 @@
1
1
  import DOMPurify from "isomorphic-dompurify";
2
- function htmlSanitize(html, config = {}) {
2
+ const htmlSanitize = (html, config = {}) => {
3
3
  return DOMPurify.sanitize(html, config);
4
- }
4
+ };
5
5
  export {
6
6
  htmlSanitize
7
7
  };
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const setScrollPositionToCenter = (rootElement, targetElement, behavior = "smooth") => {
4
4
  const rootHalfW = rootElement.getBoundingClientRect().width / 2;
5
- const buttonHalfW = targetElement.getBoundingClientRect().width / 2;
6
- const currentPosLeft = targetElement.offsetLeft + buttonHalfW;
5
+ const targetHalfW = targetElement.getBoundingClientRect().width / 2;
6
+ const currentPosLeft = targetElement.offsetLeft + targetHalfW;
7
7
  const posLeft = currentPosLeft - rootHalfW;
8
8
  rootElement.scrollTo({ left: posLeft, behavior });
9
9
  };
@@ -1,7 +1,7 @@
1
1
  const setScrollPositionToCenter = (rootElement, targetElement, behavior = "smooth") => {
2
2
  const rootHalfW = rootElement.getBoundingClientRect().width / 2;
3
- const buttonHalfW = targetElement.getBoundingClientRect().width / 2;
4
- const currentPosLeft = targetElement.offsetLeft + buttonHalfW;
3
+ const targetHalfW = targetElement.getBoundingClientRect().width / 2;
4
+ const currentPosLeft = targetElement.offsetLeft + targetHalfW;
5
5
  const posLeft = currentPosLeft - rootHalfW;
6
6
  rootElement.scrollTo({ left: posLeft, behavior });
7
7
  };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const sleep = (time) => {
4
- return new Promise((resolve) => setTimeout(resolve, time * 1e3, "foo"));
4
+ return new Promise((resolve) => setTimeout(resolve, time * 1e3));
5
5
  };
6
6
  exports.sleep = sleep;
@@ -1,5 +1,5 @@
1
1
  const sleep = (time) => {
2
- return new Promise((resolve) => setTimeout(resolve, time * 1e3, "foo"));
2
+ return new Promise((resolve) => setTimeout(resolve, time * 1e3));
3
3
  };
4
4
  export {
5
5
  sleep
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const waitForAllMediaLoaded = async (firstViewOnly = false) => {
4
- if (!document.images) return Promise.resolve(true);
5
- if (document.images.length === 0) return Promise.resolve(true);
4
+ if (!document.images) return true;
5
+ if (document.images.length === 0) return true;
6
6
  const images = Array.from(document.images).filter(
7
7
  (img) => img.getAttribute("loading") !== "lazy"
8
8
  );
@@ -20,7 +20,7 @@ const waitForAllMediaLoaded = async (firstViewOnly = false) => {
20
20
  return rect.top < firstViewHeight && rect.bottom > 0;
21
21
  });
22
22
  }
23
- if (mediaElements.length === 0) return Promise.resolve(true);
23
+ if (mediaElements.length === 0) return true;
24
24
  await Promise.all(
25
25
  mediaElements.map((media) => {
26
26
  if (media instanceof HTMLImageElement && media.complete)
@@ -1,6 +1,6 @@
1
1
  const waitForAllMediaLoaded = async (firstViewOnly = false) => {
2
- if (!document.images) return Promise.resolve(true);
3
- if (document.images.length === 0) return Promise.resolve(true);
2
+ if (!document.images) return true;
3
+ if (document.images.length === 0) return true;
4
4
  const images = Array.from(document.images).filter(
5
5
  (img) => img.getAttribute("loading") !== "lazy"
6
6
  );
@@ -18,7 +18,7 @@ const waitForAllMediaLoaded = async (firstViewOnly = false) => {
18
18
  return rect.top < firstViewHeight && rect.bottom > 0;
19
19
  });
20
20
  }
21
- if (mediaElements.length === 0) return Promise.resolve(true);
21
+ if (mediaElements.length === 0) return true;
22
22
  await Promise.all(
23
23
  mediaElements.map((media) => {
24
24
  if (media instanceof HTMLImageElement && media.complete)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "umaki",
3
- "version": "0.9.2",
3
+ "version": "0.9.3",
4
4
  "description": "A utility that is often used in web production.",
5
5
  "author": "TsubasaHiga",
6
6
  "homepage": "https://github.com/TsubasaHiga/umaki",