From 5fd2d8a4a2fd0fb664093644e52e68a8879ad563 Mon Sep 17 00:00:00 2001 From: retraigo Date: Tue, 29 Mar 2022 18:53:35 +0530 Subject: [PATCH 1/7] rearrange --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 4c12977..5d743c8 100644 --- a/index.js +++ b/index.js @@ -9,8 +9,8 @@ const keyList = { m: "minutes", s: "seconds", ms: "milliseconds", - ns: "nanoseconds", us: "microseconds", + ns: "nanoseconds", }; /** @@ -66,8 +66,8 @@ class Duration { { type: "m", value: this.m }, { type: "s", value: this.s }, { type: "ms", value: this.ms }, - { type: "ns", value: this.ns }, { type: "us", value: this.µs }, + { type: "ns", value: this.ns }, ]; } /** From 502e1fb6fe599067e2bcc8e2d6a619959e6b7b41 Mon Sep 17 00:00:00 2001 From: retraigo Date: Tue, 29 Mar 2022 19:42:16 +0530 Subject: [PATCH 2/7] ts rewrite --- index.js | 288 +----------------------------------------------- mod.js | 193 ++++++++++++++++++++++++++++++++ mod.ts | 328 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 523 insertions(+), 286 deletions(-) create mode 100644 mod.js create mode 100644 mod.ts diff --git a/index.js b/index.js index 5d743c8..6e60a44 100644 --- a/index.js +++ b/index.js @@ -1,286 +1,2 @@ -/** - * A simple JavaScript class used to parse time durations - * @module Duration - */ - -const keyList = { - d: "days", - h: "hours", - m: "minutes", - s: "seconds", - ms: "milliseconds", - us: "microseconds", - ns: "nanoseconds", -}; - -/** - * For the array of values - * @typedef {object} KeyValue - * @property {string} type - Type of key. One of d, h, m, s, ms - * @property {number} value - Value of the time unit - */ - -/** - * Duration Object - * @typedef {Object} DurationObj - * @property {Number} raw - Total number of milliseconds in the duration - * @property {Number} d - Number of days held by duration - * @property {Number} h - Number of hours held by duration - * @property {Number} m - Number of minutes held by duration - * @property {Number} s - Number of seconds held by duration - * @property {Number} ms - Number of milliseconds held by duration - * @property {Number} us - Number of microseconds held by duration - * @property {Number} ns - Number of nanoseconds held by duration - */ - -/** - * A duration class which parses milliseconds into human readable form. - * @class - */ - -class Duration { - /** - * Create a new Duration - * @param {number} timestamp - Duration in milliseconds - * @returns {} - */ - constructor(timestamp = Duration.getCurrentDuration()) { - if (timestamp < 0) timestamp = 0; // Prevent negative time - this.raw = timestamp; - this.d = Math.trunc(timestamp / 86400000); - this.h = Math.trunc(timestamp / 3600000) % 24; - this.m = Math.trunc(timestamp / 60000) % 60; - this.s = Math.trunc(timestamp / 1000) % 60; - this.ms = Math.trunc(timestamp) % 1000; - this.us = Math.trunc(timestamp * 1000) % 1000; - this.ns = Math.trunc(timestamp * 1000000) % 1000; - } - /** - * Data in the class mapped into an Array with properties "type" and "value" - * @returns {KeyValue[]} - */ - get array() { - return [ - { type: "d", value: this.d }, - { type: "h", value: this.h }, - { type: "m", value: this.m }, - { type: "s", value: this.s }, - { type: "ms", value: this.ms }, - { type: "us", value: this.µs }, - { type: "ns", value: this.ns }, - ]; - } - /** - * Alt way to get microseconds - */ - get µs() { - return this.us; - } - /** - * Data in the class mapped as a JavaScript Object. - * @returns {DurationObj} - */ - get json() { - return this.array.reduce( - (acc, stuff) => ((acc[stuff.type] = stuff.value), acc), - {}, - ); - } - /** - * @param {string[]} values - The values required to display - * @param {boolean} shortandsweet - If response should be a short string. - * @returns {string} formatted string - The formatted string result - */ - stringify(values = [], shortandsweet = false) { - if (!Array.isArray(values) || values.length == 0) { - if ( - !shortandsweet || - typeof shortandsweet !== "boolean" || - shortandsweet == false - ) { - return `${ - this.array - .map((x) => `${x.value} ${keyList[x.type]}`) - .join(", ") - }`; - } - return `${this.array.map((x) => `${x.value}${x.type}`).join(" ")}`; - } - if (values.length > 0) { - if ( - !shortandsweet || - typeof shortandsweet !== "boolean" || - shortandsweet == false - ) { - return `${ - this.array - .filter((x) => values.includes(x.type)) - .map((x) => `${x.value} ${keyList[x.type]}`) - .join(", ") - }`; - } - return `${ - this.array - .filter((x) => values.includes(x.type)) - .map((x) => `${x.value}${x.type}`) - .join(" ") - }`; - } - return `${ - this.array - .map((x) => `${x.value} ${keyList[x.type]}`) - .join(", ") - }`; - } - /** - * Get a duration formatted using colons (:) - * @param {string} fromT - Unit to display from - * @param {string} toT - Unit to display upto - * @returns {string} Formatted string - */ - getFormattedDuration(fromT = "d", toT = "µs") { - if ( - typeof fromT !== "string" || - typeof toT !== "string" || - !keyList.hasOwnProperty(fromT.toLowerCase()) || - !keyList.hasOwnProperty(toT.toLowerCase()) - ) { - return this.getSimpleFormattedDuration(); - } - const durations = []; - const next = - this.array[this.array.findIndex((x) => x.type === toT.toLowerCase()) + 1]; - for (const obj of this.array) { - if (obj.type !== fromT.toLowerCase() && durations.length === 0) continue; - if (obj.type === next.type) break; - durations.push(obj.value); - } - return durations.join(":"); - } - /** - * Get a simple formatted duration in the form dd:hh:mm:ss:ms - * @returns {string} Formatted string - */ - getSimpleFormattedDuration() { - return `${this.array.map((x) => x.value).join(":")}`; - } - /** - * Extra filler function that returns the class data in a single short string. - * @returns {string} Dumb string - */ - toString() { - return `[Duration ${this.stringify(["d", "h", "m", "s"], true)}]`; - } - /** - * Updated data to match any modification to values. - * @returns {} - */ - reload() { - const ts = this.d * 8.64e7 + - this.h * 3600000 + - this.m * 60000 + - this.s * 1000 + - this.ms + (this.us / 1000) + (this.ns / 1000000); - if (ts === this.raw) return this; - const newDuration = new Duration(ts); - this.d = newDuration.d; - this.h = newDuration.h; - this.m = newDuration.m; - this.s = newDuration.s; - this.ms = newDuration.ms; - this.ns = newDuration.ns; - this.us = newDuration.us; - this.raw = newDuration.raw; - return this; - } - /** - * Reads a given string and parses a duration from it. - * @param {string} str - A string which could contain a duration - * @param {string} doNotParse - Directly return the values read - * @returns {} - */ - static fromString(str, doNotParse = false) { - const { d, h, m, s, ms, ns, us } = Duration.readString(str); - const ts = d * 8.64e7 + h * 3600000 + m * 60000 + s * 1000 + ms + - (us / 1000) + - (ns / 1000000); - - const newDuration = new Duration(ts); - if (doNotParse) { - newDuration.d = d; - newDuration.h = h; - newDuration.m = m; - newDuration.s = s; - newDuration.ms = ms; - newDuration.ns = ns; - newDuration.us = us; - } - return newDuration; - } - /** - * Get the duration till next midnight in milliseconds. - * @returns {number} Duration in milliseconds till the next midnight - */ - static getCurrentDuration() { - return new Date().setHours(0, 0, 0, 0); - } - /** - * Read duration data from a string. - * @param {string} str - The string to read - * @returns {DurationObj} obj - Object with days, hours, mins, seconds and milliseconds - */ - static readString(str) { - str = str.replace(/\s\s/g, ""); - const days = matchReg(str, "d") || matchReg(str, "days") || - matchReg(str, "day"); - const hours = matchReg(str, "h") || matchReg(str, "hours") || - matchReg(str, "hour"); - const minutes = matchReg(str, "m") || - matchReg(str, "min") || - matchReg(str, "minute") || - matchReg(str, "mins") || - matchReg(str, "minutes"); - const seconds = matchReg(str, "s") || - matchReg(str, "sec") || - matchReg(str, "second") || - matchReg(str, "secs") || - matchReg(str, "seconds"); - const milliseconds = matchReg(str, "ms") || - matchReg(str, "millisecond") || - matchReg(str, "milliseconds"); - const nanoseconds = matchReg(str, "ns") || - matchReg(str, "nanosecond") || - matchReg(str, "nanoseconds"); - const microseconds = matchReg(str, "µs") || - matchReg(str, "microsecond") || - matchReg(str, "microseconds"); - matchReg(str, "us"); - return { - d: days, - h: hours, - m: minutes, - s: seconds, - ms: milliseconds, - ns: nanoseconds, - us: microseconds, - }; - } -} - -/** - * Match a unit in a string. Like "1kg", "3L", etc. - * @param {string} str - String to match from - * @param {string} t - Unit to look for. Doesn't support aliases. - * @returns {number} value - Value of the unit matched - */ -function matchReg(str, t) { - const reg = new RegExp(`(\\d+)\\s?${t}(?:[^a-z]|$)`, "i"); - const matched = reg.exec(str); - if (!matched) return 0; - return parseInt(matched[1].replace(t, "")); -} - -// module.exports = Duration; - -export default Duration; -export { Duration, matchReg as MatchUnit }; +// Will be removed at the next major version bump +export * from "./mod.js" \ No newline at end of file diff --git a/mod.js b/mod.js new file mode 100644 index 0000000..1fd7a2b --- /dev/null +++ b/mod.js @@ -0,0 +1,193 @@ +// deno-fmt-ignore-file +// deno-lint-ignore-file +// This code was bundled using `deno bundle` and it's not recommended to edit it manually + +const keyList = { + d: "days", + h: "hours", + m: "minutes", + s: "seconds", + ms: "milliseconds", + us: "microseconds", + ns: "nanoseconds" +}; +const BaseDurationObj = { + raw: 0, + d: 0, + h: 0, + m: 0, + s: 0, + ms: 0, + us: 0, + ns: 0 +}; +class Duration { + raw; + d; + h; + m; + s; + ms; + us; + ns; + constructor(timestamp = Duration.getCurrentDuration()){ + if (timestamp < 0) timestamp = 0; + this.raw = timestamp; + this.d = Math.trunc(timestamp / 86400000); + this.h = Math.trunc(timestamp / 3600000) % 24; + this.m = Math.trunc(timestamp / 60000) % 60; + this.s = Math.trunc(timestamp / 1000) % 60; + this.ms = Math.trunc(timestamp) % 1000; + this.us = Math.trunc(timestamp * 1000) % 1000; + this.ns = Math.trunc(timestamp * 1000000) % 1000; + } + get array() { + return [ + { + type: "d", + value: this.d + }, + { + type: "h", + value: this.h + }, + { + type: "m", + value: this.m + }, + { + type: "s", + value: this.s + }, + { + type: "ms", + value: this.ms + }, + { + type: "us", + value: this.µs + }, + { + type: "ns", + value: this.ns + }, + ]; + } + get µs() { + return this.us; + } + get json() { + return this.array.reduce((acc, stuff)=>(acc[stuff.type] = stuff.value, acc) + , BaseDurationObj); + } + stringify(values = [], shortandsweet = false) { + if (!Array.isArray(values) || values.length == 0) { + if (!shortandsweet || typeof shortandsweet !== "boolean") { + return `${this.array.map((x)=>`${x.value} ${keyList[x.type]}` + ).join(", ")}`; + } + return `${this.array.map((x)=>`${x.value}${x.type}` + ).join(" ")}`; + } + if (values.length > 0) { + if (!shortandsweet || typeof shortandsweet !== "boolean") { + return `${this.array.filter((x)=>values.includes(x.type) + ).map((x)=>`${x.value} ${keyList[x.type]}` + ).join(", ")}`; + } + return `${this.array.filter((x)=>values.includes(x.type) + ).map((x)=>`${x.value}${x.type}` + ).join(" ")}`; + } + return `${this.array.map((x)=>`${x.value} ${keyList[x.type]}` + ).join(", ")}`; + } + getFormattedDuration(fromT = "d", toT = "us") { + if (typeof fromT !== "string" || typeof toT !== "string" || !Object.hasOwn(keyList, fromT.toLowerCase()) || !Object.hasOwn(keyList, toT.toLowerCase())) { + return this.getSimpleFormattedDuration(); + } + const durations = []; + const next = this.array[this.array.findIndex((x)=>x.type === toT.toLowerCase() + ) + 1]; + for (const obj of this.array){ + if (obj.type !== fromT.toLowerCase() && durations.length === 0) continue; + if (!next) break; + if (obj.type === next.type) break; + durations.push(obj.value); + } + return durations.join(":"); + } + getSimpleFormattedDuration() { + return `${this.array.map((x)=>x.value + ).join(":")}`; + } + toString() { + return `[Duration ${this.stringify([ + "d", + "h", + "m", + "s" + ], true)}]`; + } + reload() { + const ts = this.d * 86400000 + this.h * 3600000 + this.m * 60000 + this.s * 1000 + this.ms + this.us / 1000 + this.ns / 1000000; + if (ts === this.raw) return this; + const newDuration = new Duration(ts); + this.d = newDuration.d; + this.h = newDuration.h; + this.m = newDuration.m; + this.s = newDuration.s; + this.ms = newDuration.ms; + this.ns = newDuration.ns; + this.us = newDuration.us; + this.raw = newDuration.raw; + return this; + } + static fromString(str, doNotParse = false) { + const { d , h , m , s , ms , ns , us } = Duration.readString(str); + const ts = d * 86400000 + h * 3600000 + m * 60000 + s * 1000 + ms + us / 1000 + ns / 1000000; + const newDuration = new Duration(ts); + if (doNotParse) { + newDuration.d = d; + newDuration.h = h; + newDuration.m = m; + newDuration.s = s; + newDuration.ms = ms; + newDuration.ns = ns; + newDuration.us = us; + } + return newDuration; + } + static getCurrentDuration() { + return new Date().setHours(0, 0, 0, 0); + } + static readString(str) { + str = str.replace(/\s\s/g, ""); + const days = matchReg(str, "d") || matchReg(str, "days") || matchReg(str, "day"); + const hours = matchReg(str, "h") || matchReg(str, "hours") || matchReg(str, "hour"); + const minutes = matchReg(str, "m") || matchReg(str, "min") || matchReg(str, "minute") || matchReg(str, "mins") || matchReg(str, "minutes"); + const seconds = matchReg(str, "s") || matchReg(str, "sec") || matchReg(str, "second") || matchReg(str, "secs") || matchReg(str, "seconds"); + const milliseconds = matchReg(str, "ms") || matchReg(str, "millisecond") || matchReg(str, "milliseconds"); + const nanoseconds = matchReg(str, "ns") || matchReg(str, "nanosecond") || matchReg(str, "nanoseconds"); + const microseconds = matchReg(str, "µs") || matchReg(str, "microsecond") || matchReg(str, "microseconds"); + matchReg(str, "us"); + return { + d: days, + h: hours, + m: minutes, + s: seconds, + ms: milliseconds, + ns: nanoseconds, + us: microseconds + }; + } +} +function matchReg(str, t) { + const reg = new RegExp(`(\\d+)\\s?${t}(?:[^a-z]|$)`, "i"); + const matched = reg.exec(str); + if (!matched) return 0; + return parseInt(matched[1].replace(t, "")); +} +export { matchReg as MatchUnit }; +export { Duration as Duration }; +export { Duration as default }; diff --git a/mod.ts b/mod.ts new file mode 100644 index 0000000..8e44e5c --- /dev/null +++ b/mod.ts @@ -0,0 +1,328 @@ +interface KeyList { + d: string; + h: string; + m: string; + s: string; + ms: string; + us: string; + ns: string; +} +const keyList: KeyList = { + d: "days", + h: "hours", + m: "minutes", + s: "seconds", + ms: "milliseconds", + us: "microseconds", + ns: "nanoseconds", +}; + +export type DurationKeys = "d" | "h" | "m" | "s" | "ms" | "us" | "ns"; + +/** + * For the array of values + * @typedef {object} KeyValue + * @property {string} type - Type of key. One of d, h, m, s, ms, us, ns + * @property {number} value - Value of the time unit + */ +export interface KeyValue { + type: DurationKeys; + value: number; +} + +/** + * Duration Object + * @typedef {Object} DurationObj + * @property {number} raw - Total number of milliseconds in the duration + * @property {number} d - Number of days held by duration + * @property {number} h - Number of hours held by duration + * @property {number} m - Number of minutes held by duration + * @property {number} s - Number of seconds held by duration + * @property {number} ms - Number of milliseconds held by duration + * @property {number} us - Number of microseconds held by duration + * @property {number} ns - Number of nanoseconds held by duration + */ +export interface DurationObj { + raw: number; + d: number; + h: number; + m: number; + s: number; + ms: number; + us: number; + ns: number; +} + +const BaseDurationObj: DurationObj = { + raw: 0, + d: 0, + h: 0, + m: 0, + s: 0, + ms: 0, + us: 0, + ns: 0, +}; + +/** + * A simple JavaScript class used to parse time durations + * @module Duration + * @class + */ + +export class Duration { + raw: number; + d: number; + h: number; + m: number; + s: number; + ms: number; + us: number; + ns: number; + /** + * Create a new Duration + * @param {number} timestamp - Duration in milliseconds + * @returns {} + */ + constructor(timestamp: number = Duration.getCurrentDuration()) { + if (timestamp < 0) timestamp = 0; // Prevent negative time + this.raw = timestamp; + this.d = Math.trunc(timestamp / 86400000); + this.h = Math.trunc(timestamp / 3600000) % 24; + this.m = Math.trunc(timestamp / 60000) % 60; + this.s = Math.trunc(timestamp / 1000) % 60; + this.ms = Math.trunc(timestamp) % 1000; + this.us = Math.trunc(timestamp * 1000) % 1000; + this.ns = Math.trunc(timestamp * 1000000) % 1000; + } + /** + * Data in the class mapped into an Array with properties "type" and "value" + * @returns {KeyValue[]} + */ + get array(): KeyValue[] { + return [ + { type: "d", value: this.d }, + { type: "h", value: this.h }, + { type: "m", value: this.m }, + { type: "s", value: this.s }, + { type: "ms", value: this.ms }, + { type: "us", value: this.µs }, + { type: "ns", value: this.ns }, + ]; + } + /** + * Alt way to get microseconds + */ + get µs(): number { + return this.us; + } + /** + * Data in the class mapped as a JavaScript Object. + * @returns {DurationObj} + */ + get json(): DurationObj { + return this.array.reduce( + (acc, stuff) => ((acc[stuff.type] = stuff.value), acc), + BaseDurationObj, + ); + } + /** + * @param {string[]} values - The values required to display + * @param {boolean} shortandsweet - If response should be a short string. + * @returns {string} formatted string - The formatted string result + */ + stringify(values: string[] = [], shortandsweet = false): string { + if (!Array.isArray(values) || values.length == 0) { + if ( + !shortandsweet || + typeof shortandsweet !== "boolean" + ) { + return `${ + this.array + .map((x) => `${x.value} ${keyList[x.type]}`) + .join(", ") + }`; + } + return `${this.array.map((x) => `${x.value}${x.type}`).join(" ")}`; + } + if (values.length > 0) { + if ( + !shortandsweet || + typeof shortandsweet !== "boolean" + ) { + return `${ + this.array + .filter((x) => values.includes(x.type)) + .map((x) => `${x.value} ${keyList[x.type]}`) + .join(", ") + }`; + } + return `${ + this.array + .filter((x) => values.includes(x.type)) + .map((x) => `${x.value}${x.type}`) + .join(" ") + }`; + } + return `${ + this.array + .map((x) => `${x.value} ${keyList[x.type]}`) + .join(", ") + }`; + } + /** + * Get a duration formatted using colons (:) + * @param {string} fromT - Unit to display from + * @param {string} toT - Unit to display upto + * @returns {string} Formatted string + */ + getFormattedDuration( + fromT: DurationKeys = "d", + toT: DurationKeys = "us", + ): string { + if ( + typeof fromT !== "string" || + typeof toT !== "string" || + !Object.hasOwn(keyList, fromT.toLowerCase()) || + !Object.hasOwn(keyList, toT.toLowerCase()) + ) { + return this.getSimpleFormattedDuration(); + } + const durations = []; + const next = + this.array[this.array.findIndex((x) => x.type === toT.toLowerCase()) + 1]; + for (const obj of this.array) { + if (obj.type !== fromT.toLowerCase() && durations.length === 0) continue; + if (!next) break; + if (obj.type === next.type) break; + durations.push(obj.value); + } + return durations.join(":"); + } + /** + * Get a simple formatted duration in the form dd:hh:mm:ss:ms + * @returns {string} Formatted string + */ + getSimpleFormattedDuration(): string { + return `${this.array.map((x) => x.value).join(":")}`; + } + /** + * Extra filler function that returns the class data in a single short string. + * @returns {string} Dumb string + */ + toString(): string { + return `[Duration ${this.stringify(["d", "h", "m", "s"], true)}]`; + } + /** + * Updated data to match any modification to values. + * @returns {} + */ + reload(): Duration { + const ts = this.d * 8.64e7 + + this.h * 3600000 + + this.m * 60000 + + this.s * 1000 + + this.ms + (this.us / 1000) + (this.ns / 1000000); + if (ts === this.raw) return this; + const newDuration = new Duration(ts); + this.d = newDuration.d; + this.h = newDuration.h; + this.m = newDuration.m; + this.s = newDuration.s; + this.ms = newDuration.ms; + this.ns = newDuration.ns; + this.us = newDuration.us; + this.raw = newDuration.raw; + return this; + } + /** + * Reads a given string and parses a duration from it. + * @param {string} str - A string which could contain a duration + * @param {string} doNotParse - Directly return the values read + * @returns {} + */ + static fromString(str: string, doNotParse = false): Duration { + const { d, h, m, s, ms, ns, us } = Duration.readString(str); + const ts = d * 8.64e7 + h * 3600000 + m * 60000 + s * 1000 + ms + + (us / 1000) + + (ns / 1000000); + + const newDuration = new Duration(ts); + if (doNotParse) { + newDuration.d = d; + newDuration.h = h; + newDuration.m = m; + newDuration.s = s; + newDuration.ms = ms; + newDuration.ns = ns; + newDuration.us = us; + } + return newDuration; + } + /** + * Get the duration till next midnight in milliseconds. + * @returns {number} Duration in milliseconds till the next midnight + */ + static getCurrentDuration(): number { + return new Date().setHours(0, 0, 0, 0); + } + /** + * Read duration data from a string. + * @param {string} str - The string to read + * @returns {DurationObj} obj - Object with days, hours, mins, seconds and milliseconds + */ + static readString(str: string) { + str = str.replace(/\s\s/g, ""); + const days = matchReg(str, "d") || matchReg(str, "days") || + matchReg(str, "day"); + const hours = matchReg(str, "h") || matchReg(str, "hours") || + matchReg(str, "hour"); + const minutes = matchReg(str, "m") || + matchReg(str, "min") || + matchReg(str, "minute") || + matchReg(str, "mins") || + matchReg(str, "minutes"); + const seconds = matchReg(str, "s") || + matchReg(str, "sec") || + matchReg(str, "second") || + matchReg(str, "secs") || + matchReg(str, "seconds"); + const milliseconds = matchReg(str, "ms") || + matchReg(str, "millisecond") || + matchReg(str, "milliseconds"); + const nanoseconds = matchReg(str, "ns") || + matchReg(str, "nanosecond") || + matchReg(str, "nanoseconds"); + const microseconds = matchReg(str, "µs") || + matchReg(str, "microsecond") || + matchReg(str, "microseconds"); + matchReg(str, "us"); + return { + d: days, + h: hours, + m: minutes, + s: seconds, + ms: milliseconds, + ns: nanoseconds, + us: microseconds, + }; + } +} + +/** + * Match a unit in a string. Like "1kg", "3L", etc. + * @param {string} str - String to match from + * @param {string} t - Unit to look for. Doesn't support aliases. + * @returns {number} value - Value of the unit matched + */ +function matchReg(str: string, t: string): number { + const reg = new RegExp(`(\\d+)\\s?${t}(?:[^a-z]|$)`, "i"); + const matched = reg.exec(str); + if (!matched) return 0; + return parseInt(matched[1].replace(t, "")); +} + +// module.exports = Duration; + +export default Duration; +export { matchReg as MatchUnit }; From d85c2577c81ab505f36ca4e9c177c5eae5826114 Mon Sep 17 00:00:00 2001 From: retraigo Date: Tue, 29 Mar 2022 19:42:30 +0530 Subject: [PATCH 3/7] change entrypoint, bump ver --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 1bd3ed1..bbae67c 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "name": "@retraigo/duration.js", - "version": "2.3.1", + "version": "2.3.2", "type": "module", "description": "Get the formatted time duration", - "main": "index.js", + "main": "mod.js", "scripts": { "test": "node test" }, From a8ba90bd0fe3e432ee38eb717d38f870a5ef808d Mon Sep 17 00:00:00 2001 From: retraigo Date: Tue, 29 Mar 2022 19:42:42 +0530 Subject: [PATCH 4/7] update url --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cde2116..25dcd35 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ $ pnpm install @retraigo/duration.js # PNPM // Node import Duration from "@retraigo/duration.js"; // Deno -import Duration from "https://deno.land/x/durationjs@v2.1.3/index.js"; +import Duration from "https://deno.land/x/durationjs@v2.3.2/mod.ts"; const Duration = await import("@retraigo/duration.js"); // Node with CommonJS @@ -57,6 +57,8 @@ Duration { m: 0, // Minutes s: 0, // Seconds ms: 0 // Milliseconds + us: 0 // Microseconds + ns: 0 // Nanoseconds }; ``` From ac131da82f1926ceaebc4d692e0fa7276049ae5c Mon Sep 17 00:00:00 2001 From: retraigo Date: Tue, 29 Mar 2022 19:43:01 +0530 Subject: [PATCH 5/7] mod --- test.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/test.js b/test.js index 6ee0d5a..db3ca2c 100644 --- a/test.js +++ b/test.js @@ -1,4 +1,4 @@ -import Duration from "./index.js"; +import {Duration} from "./mod.js"; /* const dur = new Duration(177013); // A random duration @@ -14,10 +14,11 @@ console.log(new Duration(114750).json); console.log(new Duration(245074).array); */ -// console.log(Duration.fromString("5 m s 54h 5d 44 s").stringify([], true)) +console.log(Duration.fromString("5 m s 54h 5d 44 s 34µs;").getFormattedDuration('h', 'ns')); const d = new Duration(6000.4353262); -d.m += 70 -console.log(d) // Only d.m changes. d.h remains the same -d.reload() -console.log(d) // d.m turns into 10 and d.h turns into 1 +console.log(d.µs) +d.m += 70; +console.log(d); // Only d.m changes. d.h remains the same +d.reload(); +console.log(d); // d.m turns into 10 and d.h turns into 1 From 3bcccecc8fa592be180a3038477266b4a4ae4ff2 Mon Sep 17 00:00:00 2001 From: retraigo Date: Tue, 29 Mar 2022 19:44:57 +0530 Subject: [PATCH 6/7] ignore vscode file --- .npmignore | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .npmignore diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..777978b --- /dev/null +++ b/.npmignore @@ -0,0 +1,4 @@ +.vscode +dumpster.js +.pnpm-debug.log +mod.ts \ No newline at end of file From ab7863be51b20f9b232dc1de86c0fd12b4ed395c Mon Sep 17 00:00:00 2001 From: retraigo Date: Tue, 29 Mar 2022 19:45:02 +0530 Subject: [PATCH 7/7] for dev --- .vscode/settings.json | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..b943dbc --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "deno.enable": true +} \ No newline at end of file