Compare commits
3 Commits
9e30508028
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 82cae6dc58 | |||
| 5079db901c | |||
| 283513d726 |
@@ -90,7 +90,6 @@ out
|
|||||||
|
|
||||||
# Nuxt.js build / generate output
|
# Nuxt.js build / generate output
|
||||||
.nuxt
|
.nuxt
|
||||||
dist
|
|
||||||
|
|
||||||
# Gatsby files
|
# Gatsby files
|
||||||
.cache/
|
.cache/
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ This library is written because of the problem with jsonwebtokens and cookies. I
|
|||||||
- Convert timestrings to minutes
|
- Convert timestrings to minutes
|
||||||
- Convert timestrings to hours
|
- Convert timestrings to hours
|
||||||
- Convert timestrings to days
|
- Convert timestrings to days
|
||||||
|
- Works in ESM CJS and typescript
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
|||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
export declare function ToSec(input: string): number;
|
||||||
|
export declare function ToMin(input: string): number;
|
||||||
|
export declare function ToHour(input: string): number;
|
||||||
|
export declare function ToDay(input: string): number;
|
||||||
|
export declare function ToMs(input: string): number;
|
||||||
Vendored
+76
@@ -0,0 +1,76 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.ToMs = exports.ToDay = exports.ToHour = exports.ToMin = exports.ToSec = void 0;
|
||||||
|
function parseVal(input) {
|
||||||
|
//check if string contains d,h,m,s and if not containts one of those add them to the string and set the value to 0 and place the value in the correct place
|
||||||
|
input = input.toLowerCase();
|
||||||
|
let data;
|
||||||
|
if (!input.includes("d") && !input.includes("h") && !input.includes("m") && !input.includes("s") && !input.includes("ms")) {
|
||||||
|
return "you need to add a value";
|
||||||
|
}
|
||||||
|
if (!input.includes("d")) {
|
||||||
|
input = "0d" + input;
|
||||||
|
}
|
||||||
|
if (!input.includes("h")) {
|
||||||
|
data = input.split("d");
|
||||||
|
input = data[0] + "d0h" + data[1];
|
||||||
|
}
|
||||||
|
if (!input.includes("m")) {
|
||||||
|
data = input.split("h");
|
||||||
|
input = data[0] + "h0m" + data[1];
|
||||||
|
}
|
||||||
|
if (!input.includes("s")) {
|
||||||
|
data = input.split("m");
|
||||||
|
input = data[0] + "m0s" + data[1];
|
||||||
|
}
|
||||||
|
if (!input.includes("ms")) {
|
||||||
|
data = input.split("s");
|
||||||
|
input = data[0] + "s0ms" + data[1];
|
||||||
|
}
|
||||||
|
let returnthis = input;
|
||||||
|
return returnthis;
|
||||||
|
}
|
||||||
|
function splitDate(input) {
|
||||||
|
input = parseVal(input);
|
||||||
|
let parts = input.split("d");
|
||||||
|
let days = parseInt(parts[0]);
|
||||||
|
parts = parts[1].split("h");
|
||||||
|
let hours = parseInt(parts[0]);
|
||||||
|
parts = parts[1].split("m");
|
||||||
|
let minutes = parseInt(parts[0]);
|
||||||
|
parts = parts[1].split("s");
|
||||||
|
let seconds = parseInt(parts[0]);
|
||||||
|
parts = parts[1].split("ms");
|
||||||
|
let milliseconds = parseInt(parts[0]);
|
||||||
|
return [days, hours, minutes, seconds, milliseconds];
|
||||||
|
}
|
||||||
|
function ToSec(input) {
|
||||||
|
let data = splitDate(input);
|
||||||
|
let total = data[0] * 86400 + data[1] * 3600 + data[2] * 60 + data[3] + data[4] / 1000;
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
exports.ToSec = ToSec;
|
||||||
|
function ToMin(input) {
|
||||||
|
let data = splitDate(input);
|
||||||
|
let total = data[0] * 1440 + data[1] * 60 + data[2] + data[3] / 60 + data[4] / 60000;
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
exports.ToMin = ToMin;
|
||||||
|
function ToHour(input) {
|
||||||
|
let data = splitDate(input);
|
||||||
|
let total = data[0] * 24 + data[1] + data[2] / 60 + data[3] / 3600 + data[4] / 3600000;
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
exports.ToHour = ToHour;
|
||||||
|
function ToDay(input) {
|
||||||
|
let data = splitDate(input);
|
||||||
|
let total = data[0] + data[1] / 24 + data[2] / 1440 + data[3] / 86400 + data[4] / 86400000;
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
exports.ToDay = ToDay;
|
||||||
|
function ToMs(input) {
|
||||||
|
let data = splitDate(input);
|
||||||
|
let total = data[0] * 86400000 + data[1] * 3600000 + data[2] * 60000 + data[3] * 1000 + data[4];
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
exports.ToMs = ToMs;
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
export declare function ToSec(input: string): number;
|
||||||
|
export declare function ToMin(input: string): number;
|
||||||
|
export declare function ToHour(input: string): number;
|
||||||
|
export declare function ToDay(input: string): number;
|
||||||
|
export declare function ToMs(input: string): number;
|
||||||
Vendored
+68
@@ -0,0 +1,68 @@
|
|||||||
|
function parseVal(input) {
|
||||||
|
//check if string contains d,h,m,s and if not containts one of those add them to the string and set the value to 0 and place the value in the correct place
|
||||||
|
input = input.toLowerCase();
|
||||||
|
let data;
|
||||||
|
if (!input.includes("d") && !input.includes("h") && !input.includes("m") && !input.includes("s") && !input.includes("ms")) {
|
||||||
|
return "you need to add a value";
|
||||||
|
}
|
||||||
|
if (!input.includes("d")) {
|
||||||
|
input = "0d" + input;
|
||||||
|
}
|
||||||
|
if (!input.includes("h")) {
|
||||||
|
data = input.split("d");
|
||||||
|
input = data[0] + "d0h" + data[1];
|
||||||
|
}
|
||||||
|
if (!input.includes("m")) {
|
||||||
|
data = input.split("h");
|
||||||
|
input = data[0] + "h0m" + data[1];
|
||||||
|
}
|
||||||
|
if (!input.includes("s")) {
|
||||||
|
data = input.split("m");
|
||||||
|
input = data[0] + "m0s" + data[1];
|
||||||
|
}
|
||||||
|
if (!input.includes("ms")) {
|
||||||
|
data = input.split("s");
|
||||||
|
input = data[0] + "s0ms" + data[1];
|
||||||
|
}
|
||||||
|
let returnthis = input;
|
||||||
|
return returnthis;
|
||||||
|
}
|
||||||
|
function splitDate(input) {
|
||||||
|
input = parseVal(input);
|
||||||
|
let parts = input.split("d");
|
||||||
|
let days = parseInt(parts[0]);
|
||||||
|
parts = parts[1].split("h");
|
||||||
|
let hours = parseInt(parts[0]);
|
||||||
|
parts = parts[1].split("m");
|
||||||
|
let minutes = parseInt(parts[0]);
|
||||||
|
parts = parts[1].split("s");
|
||||||
|
let seconds = parseInt(parts[0]);
|
||||||
|
parts = parts[1].split("ms");
|
||||||
|
let milliseconds = parseInt(parts[0]);
|
||||||
|
return [days, hours, minutes, seconds, milliseconds];
|
||||||
|
}
|
||||||
|
export function ToSec(input) {
|
||||||
|
let data = splitDate(input);
|
||||||
|
let total = data[0] * 86400 + data[1] * 3600 + data[2] * 60 + data[3] + data[4] / 1000;
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
export function ToMin(input) {
|
||||||
|
let data = splitDate(input);
|
||||||
|
let total = data[0] * 1440 + data[1] * 60 + data[2] + data[3] / 60 + data[4] / 60000;
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
export function ToHour(input) {
|
||||||
|
let data = splitDate(input);
|
||||||
|
let total = data[0] * 24 + data[1] + data[2] / 60 + data[3] / 3600 + data[4] / 3600000;
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
export function ToDay(input) {
|
||||||
|
let data = splitDate(input);
|
||||||
|
let total = data[0] + data[1] / 24 + data[2] / 1440 + data[3] / 86400 + data[4] / 86400000;
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
export function ToMs(input) {
|
||||||
|
let data = splitDate(input);
|
||||||
|
let total = data[0] * 86400000 + data[1] * 3600000 + data[2] * 60000 + data[3] * 1000 + data[4];
|
||||||
|
return total;
|
||||||
|
}
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
{"type": "module"}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
export declare function ToSec(input: string): number;
|
||||||
|
export declare function ToMin(input: string): number;
|
||||||
|
export declare function ToHour(input: string): number;
|
||||||
|
export declare function ToDay(input: string): number;
|
||||||
|
export declare function ToMs(input: string): number;
|
||||||
+16
-3
@@ -1,15 +1,28 @@
|
|||||||
{
|
{
|
||||||
"name": "timestringconverter",
|
"name": "timestringconverter",
|
||||||
"version": "2.0.0",
|
"version": "2.2.4",
|
||||||
"description": "generetes a number from a time string",
|
"description": "generetes a number from a time string",
|
||||||
"main": "src/index.ts",
|
"main": "dist/cjs/index.js",
|
||||||
|
"module": "dist/esm/index.js",
|
||||||
|
"files": [
|
||||||
|
"dist"
|
||||||
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
"start": "node index.js"
|
"start": "node index.js",
|
||||||
|
"compile": "tsc -b ./tsconfig.cjs.json ./tsconfig.esm.json ./tsconfig.types.json"
|
||||||
},
|
},
|
||||||
"author": "kaj van schalkwijk",
|
"author": "kaj van schalkwijk",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"ts-node": "^10.9.2"
|
"ts-node": "^10.9.2"
|
||||||
|
},
|
||||||
|
"exports": {
|
||||||
|
".": {
|
||||||
|
"types": "./dist/types/index.d.ts",
|
||||||
|
"require": "./dist/cjs/index.js",
|
||||||
|
"import": "./dist/esm/index.js",
|
||||||
|
"default": "./dist/esm/index.js"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-10
@@ -7,9 +7,6 @@ function parseVal(input: string){
|
|||||||
return "you need to add a value"
|
return "you need to add a value"
|
||||||
}
|
}
|
||||||
|
|
||||||
//order the string so it is in the correct order it must go d,h,m,s,ms so ms, s, m, d, h will return d,h,m,s,ms
|
|
||||||
|
|
||||||
|
|
||||||
if(!input.includes("d")){
|
if(!input.includes("d")){
|
||||||
input = "0d" + input;
|
input = "0d" + input;
|
||||||
}
|
}
|
||||||
@@ -34,17 +31,30 @@ function parseVal(input: string){
|
|||||||
input = data[0] + "s0ms" + data[1];
|
input = data[0] + "s0ms" + data[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
return input;
|
let returnthis = input;
|
||||||
|
|
||||||
|
return returnthis;
|
||||||
}
|
}
|
||||||
|
|
||||||
function splitDate(input: string): number[] {
|
function splitDate(input: string): number[] {
|
||||||
input = parseVal(input);
|
input = parseVal(input);
|
||||||
let days = parseInt(input.split("d")[0]);
|
|
||||||
let hours = parseInt(input.split("d")[1].split("h")[0]);
|
let parts = input.split("d");
|
||||||
let minutes = parseInt(input.split("d")[1].split("h")[1].split("m")[0]);
|
let days = parseInt(parts[0]);
|
||||||
let seconds = parseInt(input.split("d")[1].split("h")[1].split("m")[1].split("s")[0]);
|
|
||||||
let miliseconds = parseInt(input.split("d")[1].split("h")[1].split("m")[1].split("s")[1].split("ms")[0]);
|
parts = parts[1].split("h");
|
||||||
return [days, hours, minutes, seconds, miliseconds];
|
let hours = parseInt(parts[0]);
|
||||||
|
|
||||||
|
parts = parts[1].split("m");
|
||||||
|
let minutes = parseInt(parts[0]);
|
||||||
|
|
||||||
|
parts = parts[1].split("s");
|
||||||
|
let seconds = parseInt(parts[0]);
|
||||||
|
|
||||||
|
parts = parts[1].split("ms");
|
||||||
|
let milliseconds = parseInt(parts[0]);
|
||||||
|
|
||||||
|
return [days, hours, minutes, seconds, milliseconds];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ToSec(input: string){
|
export function ToSec(input: string){
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"extends": "./tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "./dist/cjs",
|
||||||
|
"module": "commonjs"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"extends": "./tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "./dist/esm",
|
||||||
|
"module": "esnext"
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-20
@@ -24,25 +24,6 @@
|
|||||||
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
||||||
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
||||||
|
|
||||||
/* Modules */
|
|
||||||
"module": "commonjs", /* Specify what module code is generated. */
|
|
||||||
"rootDir": "./src", /* Specify the root folder within your source files. */
|
|
||||||
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
|
|
||||||
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
|
||||||
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
|
||||||
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
|
||||||
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
|
||||||
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
|
||||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
||||||
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
|
||||||
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
|
|
||||||
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
|
|
||||||
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
|
|
||||||
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
|
|
||||||
// "resolveJsonModule": true, /* Enable importing .json files. */
|
|
||||||
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
|
|
||||||
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
|
||||||
|
|
||||||
/* JavaScript Support */
|
/* JavaScript Support */
|
||||||
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
||||||
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
||||||
@@ -105,5 +86,7 @@
|
|||||||
/* Completeness */
|
/* Completeness */
|
||||||
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
||||||
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
||||||
}
|
},
|
||||||
|
"exclude": ["node_modules", "**/*.test.ts"],
|
||||||
|
"include": ["src/**/*.ts"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"extends": "./tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "./dist/types",
|
||||||
|
"declaration": true,
|
||||||
|
"emitDeclarationOnly": true
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user