Greasy Fork

Monkey Utils

Useful library with JavaScript utilities.

当前为 2020-06-22 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.greasyfork.icu/scripts/405813/819175/Monkey%20Utils.js

// ==UserScript==
// @name Monkey Utils
// @namespace https://rafaelgssa.gitlab.io/monkey-scripts
// @version 1.0.2
// @author rafaelgssa
// @description Useful library with JavaScript utilities.
// @match *://*/*
// ==/UserScript==

// eslint-disable-next-line
const MonkeyUtils = (() => {
	/**
	 * Checks if a value is set.
	 * @template T
	 * @param {T} value The value to check.
	 * @returns {value is NonNullable<T>}
	 */
	const isSet = (value) => {
		return typeof value !== 'undefined' && value !== null;
	};

	/**
	 * Sleeps for a number of seconds.
	 * @param {number} seconds
	 * @returns {Promise<void>}
	 */
	const sleep = (seconds) => {
		return new Promise((resolve) => window.setTimeout(resolve, seconds * 1000));
	};

	return {
		isSet,
		sleep,
	};
})();