| declare const _default: { | ||
| timeToMs: (time: string) => number; | ||
| parseMs: (ms: number) => import("./interfaces/parsed_ms").parsedMs; | ||
| msToTime: (ms: number) => string; | ||
| }; | ||
| export = _default; |
| "use strict"; | ||
| // ### BASIC-MS | ||
| // ### By Deliever42 | ||
| // ### 2022 Copyright (C) Deliever42 | ||
| const time_to_ms_1 = require("./methods/time_to_ms"); | ||
| const ms_to_time_1 = require("./methods/ms_to_time"); | ||
| const parse_ms_1 = require("./methods/parse_ms"); | ||
| module.exports = { timeToMs: time_to_ms_1.timeToMs, parseMs: parse_ms_1.parseMs, msToTime: ms_to_time_1.msToTime }; |
| export interface parsedMs { | ||
| years: number; | ||
| months: number; | ||
| weeks: number; | ||
| days: number; | ||
| hours: number; | ||
| minutes: number; | ||
| seconds: number; | ||
| milliseconds: number; | ||
| } |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); |
| export declare const msToTime: (ms: number) => string; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.msToTime = void 0; | ||
| const tslib_1 = require("tslib"); | ||
| const units = (0, tslib_1.__importStar)(require("../utils/units")); | ||
| const msToTime = (ms) => { | ||
| if (!ms || typeof ms !== 'number') | ||
| throw new ReferenceError('Unknown time!'); | ||
| if (ms >= units.y) | ||
| return Math.round(ms / units.y) + 'y'; | ||
| if (ms >= units.mo) | ||
| return Math.round(ms / units.mo) + 'mo'; | ||
| if (ms >= units.w) | ||
| return Math.round(ms / units.w) + 'w'; | ||
| if (ms >= units.d) | ||
| return Math.round(ms / units.d) + 'd'; | ||
| if (ms >= units.h) | ||
| return Math.round(ms / units.h) + 'h'; | ||
| if (ms >= units.m) | ||
| return Math.round(ms / units.m) + 'm'; | ||
| if (ms >= units.s) | ||
| return Math.round(ms / units.s) + 's'; | ||
| return ms + 'ms'; | ||
| }; | ||
| exports.msToTime = msToTime; |
| import type { parsedMs } from '../interfaces/parsed_ms'; | ||
| export declare const parseMs: (ms: number) => parsedMs; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.parseMs = void 0; | ||
| const tslib_1 = require("tslib"); | ||
| const units = (0, tslib_1.__importStar)(require("../utils/units")); | ||
| const parseMs = (ms) => { | ||
| if (!ms || typeof ms !== 'number') | ||
| throw new ReferenceError('Unknown time!'); | ||
| return { | ||
| years: Math.round(ms / units.y), | ||
| months: Math.round(ms / units.mo), | ||
| weeks: Math.round(ms / units.w), | ||
| days: Math.round(ms / units.d), | ||
| hours: Math.round(ms / units.h), | ||
| minutes: Math.round(ms / units.m), | ||
| seconds: Math.round(ms / units.s), | ||
| milliseconds: Math.round(ms) % 1000 | ||
| }; | ||
| }; | ||
| exports.parseMs = parseMs; |
| export declare const timeToMs: (time: string) => number; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.timeToMs = void 0; | ||
| const tslib_1 = require("tslib"); | ||
| const is_time_1 = require("../utils/is_time"); | ||
| const units = (0, tslib_1.__importStar)(require("../utils/units")); | ||
| const get_ms_in_time_1 = require("../utils/get_ms_in_time"); | ||
| const get_unit_in_time_1 = require("../utils/get_unit_in_time"); | ||
| const timeToMs = (time) => { | ||
| if (!time || !(0, is_time_1.isTime)(time)) | ||
| throw new ReferenceError('Unknown time!'); | ||
| const ms = (0, get_ms_in_time_1.getMsInTime)(time); | ||
| const unit = (0, get_unit_in_time_1.getUnitInTime)(time); | ||
| if (unit === 's') | ||
| return Math.round(ms) * units.s; | ||
| if (unit === 'mo') | ||
| return Math.round(ms) * units.mo; | ||
| if (unit === 'm') | ||
| return Math.round(ms) * units.m; | ||
| if (unit === 'h') | ||
| return Math.round(ms) * units.h; | ||
| if (unit === 'd') | ||
| return Math.round(ms) * units.d; | ||
| if (unit === 'w') | ||
| return Math.round(ms) * units.w; | ||
| if (unit === 'y') | ||
| return Math.round(ms) * units.y; | ||
| throw new ReferenceError('Unknown time!'); | ||
| }; | ||
| exports.timeToMs = timeToMs; |
| export declare const getMsInTime: (time: string) => number; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.getMsInTime = void 0; | ||
| const getMsInTime = (time) => { | ||
| return Number(time.match(/\d+/g)[0]); | ||
| }; | ||
| exports.getMsInTime = getMsInTime; |
| export declare const getUnitInTime: (time: string) => string; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.getUnitInTime = void 0; | ||
| const getUnitInTime = (time) => { | ||
| return time.replace(/\d|[^\w\s]/g, ''); | ||
| }; | ||
| exports.getUnitInTime = getUnitInTime; |
| export declare const isTime: (time: string) => boolean; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.isTime = void 0; | ||
| const isTime = (time) => { | ||
| return /^s|m|h|d|w|mo|y/g.test(time); | ||
| }; | ||
| exports.isTime = isTime; |
| export declare const s = 1000; | ||
| export declare const m: number; | ||
| export declare const h: number; | ||
| export declare const d: number; | ||
| export declare const w: number; | ||
| export declare const mo: number; | ||
| export declare const y: number; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.y = exports.mo = exports.w = exports.d = exports.h = exports.m = exports.s = void 0; | ||
| exports.s = 1000; | ||
| exports.m = exports.s * 60; | ||
| exports.h = exports.m * 60; | ||
| exports.d = exports.h * 24; | ||
| exports.w = exports.d * 7; | ||
| exports.mo = exports.w * 4; | ||
| exports.y = exports.d * 365.25; |
+10
-12
| { | ||
| "name": "basic-ms", | ||
| "version": "1.0.8", | ||
| "description": "Basic MS Module.", | ||
| "main": "index.js", | ||
| "version": "1.1.1", | ||
| "description": "Easy MS Module", | ||
| "main": "dist/index.js", | ||
| "scripts": { | ||
| "test": "echo \"Error: no test specified\" && exit 1" | ||
| "build": "tsc", | ||
| "test": "ts-node ./test/index.ts" | ||
| }, | ||
| "types": "index.d.ts", | ||
| "types": "dist/index.d.ts", | ||
| "keywords": [ | ||
| "basic-ms", | ||
| "ms", | ||
| "erax.db", | ||
| "fast", | ||
| "quick", | ||
| "wio.db", | ||
| "easy", | ||
@@ -33,9 +32,8 @@ "time", | ||
| "homepage": "https://github.com/deliever42/basic-ms#readme", | ||
| "dependencies": { | ||
| "chalk": "^4.1.2" | ||
| }, | ||
| "devDependencies": { | ||
| "eslint": "^7.31.0", | ||
| "prettierrc": "0.0.0-5" | ||
| "eslint": "^8.10.0", | ||
| "prettier": "^2.5.1", | ||
| "ts-node": "^10.6.0", | ||
| "typescript": "^4.6.2" | ||
| } | ||
| } |
+7
-28
@@ -11,3 +11,3 @@  | ||
| ```npm | ||
| - Fixed Errors. | ||
| - Added parse ms and ms to time. | ||
| ``` | ||
@@ -18,33 +18,12 @@ | ||
| ```js | ||
| const ms = require("basic-ms"); | ||
| const { timeToMs, parseMs, msToTime } = require('basic-ms'); | ||
| //Time To Ms | ||
| ms("1s"); //1000 | ||
| ms("1m"); //60000 | ||
| ms("1h"); //3600000 | ||
| ms("1d"); //86400000 | ||
| ms("1w"); //604800016 | ||
| ms("1mo"); //2629800000 | ||
| ms("1y"); //31557600000 | ||
| timeToMs('1h'); // 3600000 | ||
| //Ms To Time (Long = false) | ||
| ms(1, { long: false }); //1ms | ||
| ms(1000, { long: false }); //1s | ||
| ms(60000), { long: false }; //1m | ||
| ms(3600000, { long: false }); //1h | ||
| ms(86400000, { long: false }); //1d | ||
| ms(604800016, { long: false }); //1w | ||
| ms(2629800000, { long: false }); //1mo | ||
| ms(31557600000, { long: false }); //1y | ||
| //Ms To Time | ||
| msToTime(3600000); // 1h | ||
| //Ms To Time (Long = true) | ||
| ms(1, { long: true }); //1milliseconds | ||
| ms(1000, { long: true }); //1seconds | ||
| ms(60000), { long: true }; //1minutes | ||
| ms(3600000, { long: true }); //1hours | ||
| ms(86400000, { long: true }); //1days | ||
| ms(604800016, { long: true }); //1weeks | ||
| ms(2629800000, { long: true }); //1months | ||
| ms(31557600000, { long: true }); //1years | ||
| //parseMs | ||
| parseMs(3600000); // { years: 0, months: 0, weeks: 0, days: 0, hours: 10, minutes: 600, seconds: 36000, milliseconds: 0 } | ||
| ``` |
| const chalk = require("chalk"); | ||
| /** | ||
| * | ||
| * @class | ||
| */ | ||
| class ErrorManager extends Error { | ||
| /** | ||
| * @constructor | ||
| * @param {string} message | ||
| */ | ||
| constructor(message) { | ||
| const errorMessage = `${chalk.red("[ BasicMS ]")} ${chalk.blue("=>")} ${chalk.gray( | ||
| message | ||
| )}`; | ||
| super(errorMessage); | ||
| } | ||
| } | ||
| module.exports = ErrorManager; |
-14
| declare module "basic-ms" { | ||
| export default function NodeMS(time: string | number, _options?: { long: boolean }): number | string; | ||
| export class Util { | ||
| private static TimeToMilliseconds(time: string): number; | ||
| private static MillisecondsToTime(time: number, long: boolean): string; | ||
| private static isTimeExists(time: string): boolean; | ||
| private static parseMilliseconds(milliseconds: number): number; | ||
| } | ||
| export class ErrorManager extends Error { | ||
| public constructor(message: string); | ||
| } | ||
| } |
-23
| const ErrorManager = require("./ErrorManager"); | ||
| const Util = require("./Util"); | ||
| /** | ||
| * | ||
| * @param {string | number} time | ||
| * @param {{ long: boolean }} _options | ||
| * @returns {string | number} | ||
| */ | ||
| module.exports = function NodeMS(time, _options = { long: false }) { | ||
| if (time === null || time === undefined) throw new ErrorManager("You must specify a time!"); | ||
| switch (typeof time) { | ||
| case "string": | ||
| return Util.TimeToMilliseconds(time); | ||
| break; | ||
| case "number": | ||
| return Util.MillisecondsToTime(time, _options.long); | ||
| break; | ||
| default: | ||
| throw new ErrorManager("Unknown time type! (string, number)"); | ||
| } | ||
| }; |
-121
| const ErrorManager = require("./ErrorManager"); | ||
| const s = 1000; | ||
| const m = s * 60; | ||
| const h = m * 60; | ||
| const d = h * 24; | ||
| const w = d * 7; | ||
| const mo = w * 4; | ||
| const y = d * 365.25; | ||
| /** | ||
| * | ||
| * @class | ||
| */ | ||
| class Util { | ||
| /** | ||
| * | ||
| * @param {string} time | ||
| * @returns {number} | ||
| */ | ||
| static TimeToMilliseconds(time) { | ||
| if (!this.isTimeExists(time)) | ||
| throw new ErrorManager("Invalid arguments! (s, m, h, d, w, mo, y)"); | ||
| if (time.endsWith("s")) { | ||
| return Math.round(time.split("s")[0]) * s; | ||
| } else if (time.endsWith("mo")) { | ||
| return Math.round(time.split("mo")[0]) * mo; | ||
| } else if (time.endsWith("m")) { | ||
| return Math.round(time.split("m")[0]) * m; | ||
| } else if (time.endsWith("h")) { | ||
| return Math.round(time.split("h")[0]) * h; | ||
| } else if (time.endsWith("d")) { | ||
| return Math.round(time.split("d")[0]) * d; | ||
| } else if (time.endsWith("w")) { | ||
| return Math.round(time.split("w")[0]) * w; | ||
| } else if (time.endsWith("y")) { | ||
| return Math.round(time.split("y")[0]) * y; | ||
| } | ||
| } | ||
| /** | ||
| * | ||
| * @param {number} milliseconds | ||
| * @param {boolean} long | ||
| * @returns {string} | ||
| */ | ||
| static MillisecondsToTime(milliseconds, long = false) { | ||
| const parsedMilliseconds = this.parseMilliseconds(milliseconds); | ||
| if (long === true) { | ||
| if (parsedMilliseconds >= y) { | ||
| return Math.round((milliseconds /= y)) + "years"; | ||
| } | ||
| if (parsedMilliseconds >= mo) { | ||
| return Math.round((milliseconds /= mo)) + "months"; | ||
| } | ||
| if (parsedMilliseconds >= w) { | ||
| return Math.round((milliseconds /= w)) + "weeks"; | ||
| } | ||
| if (parsedMilliseconds >= d) { | ||
| return Math.round((milliseconds /= d)) + "days"; | ||
| } | ||
| if (parsedMilliseconds >= h) { | ||
| return Math.round((milliseconds /= h)) + "hours"; | ||
| } | ||
| if (parsedMilliseconds >= m) { | ||
| return Math.round((milliseconds /= m)) + "minutes"; | ||
| } | ||
| if (parsedMilliseconds >= s) { | ||
| return Math.round((milliseconds /= s)) + "seconds"; | ||
| } else return milliseconds + "milliseconds"; | ||
| } else if (long === false) { | ||
| if (parsedMilliseconds >= y) { | ||
| return Math.round((milliseconds /= y)) + "y"; | ||
| } | ||
| if (parsedMilliseconds >= mo) { | ||
| return Math.round((milliseconds /= mo)) + "mo"; | ||
| } | ||
| if (parsedMilliseconds >= w) { | ||
| return Math.round((milliseconds /= w)) + "w"; | ||
| } | ||
| if (parsedMilliseconds >= d) { | ||
| return Math.round((milliseconds /= d)) + "d"; | ||
| } | ||
| if (parsedMilliseconds >= h) { | ||
| return Math.round((milliseconds /= h)) + "h"; | ||
| } | ||
| if (parsedMilliseconds >= m) { | ||
| return Math.round((milliseconds /= m)) + "m"; | ||
| } | ||
| if (parsedMilliseconds >= s) { | ||
| return Math.round((milliseconds /= s)) + "s"; | ||
| } else return milliseconds + "ms"; | ||
| } else return milliseconds + "ms"; | ||
| } | ||
| /** | ||
| * | ||
| * @param {string} time | ||
| * @returns {boolean} | ||
| */ | ||
| static isTimeExists(time) { | ||
| const args = ["s", "m", "h", "d", "w", "mo", "y"]; | ||
| let i = false; | ||
| for (let arg of args) { | ||
| if (time.endsWith(arg)) i = true; | ||
| } | ||
| return i; | ||
| } | ||
| /** | ||
| * | ||
| * @param {number} milliseconds | ||
| * @returns {number} | ||
| */ | ||
| static parseMilliseconds(milliseconds) { | ||
| return Math.abs(milliseconds); | ||
| } | ||
| } | ||
| module.exports = Util; |
Unpublished package
Supply chain riskPackage version was not found on the registry. It may exist on a different registry and need to be configured to pull from that registry.
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
Unpopular package
QualityThis package is not very popular.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
0
-100%21
200%0
-100%0
-100%18246
-5.06%4
100%146
-11.52%28
-42.86%- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed