@hyurl/utils
Advanced tools
Comparing version 0.3.0 to 0.3.1
@@ -25,7 +25,14 @@ "use strict"; | ||
else { | ||
if (/^\d{1,2}:\d{2}(:\d{2})?/.test(dateTime)) { // time only | ||
let match = null; | ||
if (match = dateTime.match(/^(\d{1,2}):\d{2}(:\d{2})?/)) { // time only | ||
if (match[1].length !== 2) { | ||
dateTime = "0" + dateTime; | ||
} | ||
if (!match[2]) { | ||
dateTime += ":00"; | ||
} | ||
date = new Date(); | ||
dateTime = date.getFullYear() | ||
+ "-" + (date.getMonth() + 1) | ||
+ "-" + date.getDate() | ||
+ "-" + String(date.getMonth() + 1).padStart(2, "0") | ||
+ "-" + String(date.getDate()).padStart(2, "0") | ||
+ " " + dateTime; | ||
@@ -39,2 +46,3 @@ } | ||
else { | ||
console.log(dateTime); | ||
throw new Error("The input argument is not a valid date-time string"); | ||
@@ -41,0 +49,0 @@ } |
@@ -16,3 +16,3 @@ "use strict"; | ||
if (type === "function") { | ||
if ((0, could_be_class_1.default)(target)) { | ||
if ((0, could_be_class_1.couldBeClass)(target)) { | ||
return "class"; | ||
@@ -19,0 +19,0 @@ } |
@@ -27,4 +27,4 @@ import { isAsyncGenerator as isAsyncGenerator_1, isGenerator as isGenerator_1 } from '../../check-iterable/index.js'; | ||
function mergeIfNotExists(proto, source, mergeSuper = false) { | ||
let props = Reflect.ownKeys(source); | ||
for (let prop of props) { | ||
const props = Reflect.ownKeys(source); | ||
for (const prop of props) { | ||
if (prop == "constructor") { | ||
@@ -51,3 +51,3 @@ continue; | ||
mergeIfNotExists(ctor.prototype, mixin.prototype, mergeSuper); | ||
let _super = Object.getPrototypeOf(mixin); | ||
const _super = Object.getPrototypeOf(mixin); | ||
// Every user defined class or functions that can be instantiated have their | ||
@@ -64,3 +64,3 @@ // own names, if no name appears, that means the function has traveled to | ||
function setProp(proto, source, prop) { | ||
let desc = Object.getOwnPropertyDescriptor(source, prop); | ||
const desc = Object.getOwnPropertyDescriptor(source, prop); | ||
if (desc) { | ||
@@ -93,3 +93,3 @@ Object.defineProperty(proto, prop, desc); | ||
try { | ||
let { done, value } = await returns.next(input); | ||
const { done, value } = await returns.next(input); | ||
if (done) { | ||
@@ -114,3 +114,3 @@ result = value; | ||
} | ||
return Promise.resolve([null, result]); | ||
return [null, result]; | ||
})(); | ||
@@ -124,3 +124,3 @@ } | ||
try { | ||
let { done, value } = returns.next(input); | ||
const { done, value } = returns.next(input); | ||
if (done) { | ||
@@ -166,3 +166,3 @@ result = value; | ||
try { | ||
let { done, value } = await returns.next(input); | ||
const { done, value } = await returns.next(input); | ||
if (done) { | ||
@@ -194,3 +194,3 @@ result = { value, error: null }; | ||
else { | ||
return Promise.resolve(result.value); | ||
return result.value; | ||
} | ||
@@ -206,3 +206,3 @@ })(); | ||
try { | ||
let { done, value } = returns.next(input); | ||
const { done, value } = returns.next(input); | ||
if (done) { | ||
@@ -331,3 +331,3 @@ result = { value, error: null }; | ||
}; // make sure this class has no name | ||
for (let mixin of mixins) { | ||
for (const mixin of mixins) { | ||
if (typeof mixin == "function") { | ||
@@ -529,3 +529,3 @@ mergeHierarchy(obj.ctor, mixin); | ||
async run(script, args = undefined, options = undefined) { | ||
var _a; | ||
var _a, _b; | ||
const msg = { | ||
@@ -558,3 +558,3 @@ type: "ffi", | ||
let terminate = () => Promise.resolve(void 0); | ||
let timeout = (options === null || options === void 0 ? void 0 : options.timeout) ? setTimeout(() => { | ||
const timeout = (options === null || options === void 0 ? void 0 : options.timeout) ? setTimeout(() => { | ||
const err = new Error(`operation timeout after ${options.timeout}ms`); | ||
@@ -739,3 +739,4 @@ if (resolver) { | ||
worker = new Worker(entry); | ||
workerId = worker.threadId; | ||
// `threadId` may not exist in Bun. | ||
workerId = (_a = worker.threadId) !== null && _a !== void 0 ? _a : workerIdCounter.next().value; | ||
ok = await new Promise((resolve) => { | ||
@@ -803,3 +804,3 @@ worker.once("exit", () => { | ||
let blob; | ||
if ((_a = res.headers.get("content-type")) === null || _a === void 0 ? void 0 : _a.startsWith("application/javascript")) { | ||
if ((_b = res.headers.get("content-type")) === null || _b === void 0 ? void 0 : _b.startsWith("application/javascript")) { | ||
blob = await res.blob(); | ||
@@ -806,0 +807,0 @@ } |
@@ -12,3 +12,3 @@ /** Returns `true` if the given value is a float number, `false` otherwise. */ | ||
function isNumeric(value) { | ||
let type = typeof value; | ||
const type = typeof value; | ||
if (type === "number" || type === "bigint") { | ||
@@ -15,0 +15,0 @@ return true; |
@@ -11,3 +11,3 @@ function hasOwn(obj, key) { | ||
var _a; | ||
let proto = Object.getPrototypeOf(obj); | ||
const proto = Object.getPrototypeOf(obj); | ||
if (!proto || !hasOwn(proto, method)) { | ||
@@ -47,3 +47,3 @@ return false; | ||
let _type; | ||
let primitiveMap = { | ||
const primitiveMap = { | ||
"string": String, | ||
@@ -50,0 +50,0 @@ "number": Number, |
@@ -1,2 +0,2 @@ | ||
import { __exports as checkIterable } from '../../_virtual/index3.js'; | ||
import { __exports as checkIterable } from '../../_virtual/index2.js'; | ||
@@ -3,0 +3,0 @@ Object.defineProperty(checkIterable, "__esModule", { |
@@ -1,3 +0,1 @@ | ||
import { __exports as couldBeClass$1 } from '../../_virtual/index.js'; | ||
/** | ||
@@ -53,6 +51,5 @@ * Checks if an object could be an instantiable class. | ||
couldBeClass$1.couldBeClass = couldBeClass; | ||
couldBeClass$1.default = couldBeClass; | ||
var couldBeClass_2 = couldBeClass; | ||
export { couldBeClass$1 as default }; | ||
export { couldBeClass_2 as couldBeClass }; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import { __exports as isLike } from '../../_virtual/index2.js'; | ||
import { __exports as isLike } from '../../_virtual/index.js'; | ||
@@ -3,0 +3,0 @@ Object.defineProperty(isLike, "__esModule", { |
@@ -1,4 +0,4 @@ | ||
var couldBeClass = {}; | ||
var isLike = {}; | ||
export { couldBeClass as __exports }; | ||
export { isLike as __exports }; | ||
//# sourceMappingURL=index.js.map |
@@ -1,4 +0,4 @@ | ||
var isLike = {}; | ||
var checkIterable = {}; | ||
export { isLike as __exports }; | ||
export { checkIterable as __exports }; | ||
//# sourceMappingURL=index2.js.map |
@@ -23,7 +23,14 @@ import isNumeric from './isNumeric.js'; | ||
else { | ||
if (/^\d{1,2}:\d{2}(:\d{2})?/.test(dateTime)) { // time only | ||
let match = null; | ||
if (match = dateTime.match(/^(\d{1,2}):\d{2}(:\d{2})?/)) { // time only | ||
if (match[1].length !== 2) { | ||
dateTime = "0" + dateTime; | ||
} | ||
if (!match[2]) { | ||
dateTime += ":00"; | ||
} | ||
date = new Date(); | ||
dateTime = date.getFullYear() | ||
+ "-" + (date.getMonth() + 1) | ||
+ "-" + date.getDate() | ||
+ "-" + String(date.getMonth() + 1).padStart(2, "0") | ||
+ "-" + String(date.getDate()).padStart(2, "0") | ||
+ " " + dateTime; | ||
@@ -37,2 +44,3 @@ } | ||
else { | ||
console.log(dateTime); | ||
throw new Error("The input argument is not a valid date-time string"); | ||
@@ -39,0 +47,0 @@ } |
import isVoid from './isVoid.js'; | ||
import './_external/could-be-class/index.js'; | ||
import { __exports as couldBeClass } from './_virtual/index.js'; | ||
import { couldBeClass as couldBeClass_2 } from './_external/could-be-class/index.js'; | ||
@@ -16,3 +15,3 @@ /** | ||
if (type === "function") { | ||
if (couldBeClass(target)) { | ||
if (couldBeClass_2(target)) { | ||
return "class"; | ||
@@ -19,0 +18,0 @@ } |
{ | ||
"name": "@hyurl/utils", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "Utility functions of HyURL collection.", | ||
@@ -144,3 +144,4 @@ "exports": { | ||
"scripts": { | ||
"test": "mocha", | ||
"test": "mocha -r ts-node/register", | ||
"test:bun": "bun run ./node_modules/mocha/bin/mocha", | ||
"build": "tsc && rollup -c rollup.config.mjs && webpack", | ||
@@ -180,3 +181,3 @@ "prepublishOnly": "npm run build" | ||
"dependencies": { | ||
"@ayonli/jsext": "^0.4.2", | ||
"@ayonli/jsext": "^0.4.3", | ||
"could-be-class": "^0.2.1", | ||
@@ -207,5 +208,2 @@ "is-like": "^0.1.12", | ||
"mocha": { | ||
"require": [ | ||
"ts-node/register" | ||
], | ||
"spec": [ | ||
@@ -212,0 +210,0 @@ "*.test.ts" |
@@ -37,7 +37,17 @@ import isNumeric from './isNumeric'; | ||
} else { | ||
if (/^\d{1,2}:\d{2}(:\d{2})?/.test(dateTime)) { // time only | ||
let match: RegExpMatchArray | null = null; | ||
if (match = dateTime.match(/^(\d{1,2}):\d{2}(:\d{2})?/)) { // time only | ||
if (match[1].length !== 2) { | ||
dateTime = "0" + dateTime; | ||
} | ||
if (!match[2]) { | ||
dateTime += ":00"; | ||
} | ||
date = new Date(); | ||
dateTime = date.getFullYear() | ||
+ "-" + (date.getMonth() + 1) | ||
+ "-" + date.getDate() | ||
+ "-" + String(date.getMonth() + 1).padStart(2, "0") | ||
+ "-" + String(date.getDate()).padStart(2, "0") | ||
+ " " + dateTime; | ||
@@ -52,2 +62,3 @@ } | ||
} else { | ||
console.log(dateTime); | ||
throw new Error("The input argument is not a valid date-time string"); | ||
@@ -71,2 +82,2 @@ } | ||
return date; | ||
} | ||
} |
import isVoid from './isVoid'; | ||
import isClass from "could-be-class"; | ||
import { couldBeClass as isClass } from "could-be-class"; | ||
import type { Constructor } from "@ayonli/jsext"; | ||
@@ -4,0 +4,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
536476
5908
2
Updated@ayonli/jsext@^0.4.3