1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2025-01-18 13:07:58 +00:00

Converted some JS files to TypeScript

This commit is contained in:
Romein van Buren 2023-08-07 17:08:22 +02:00
parent 5b15782d7d
commit 82796d5a8c
Signed by: romein
GPG Key ID: 0EFF8478ADDF6C49
6 changed files with 36 additions and 24 deletions

View File

@ -22,6 +22,7 @@
"include": [
"src/**/*.d.ts",
"src/**/*.js",
"src/**/*.ts",
"src/**/*.svelte"
]
}

View File

@ -14,7 +14,7 @@ export default function input(node, { autofocus, type, onValid, onInvalid, manda
node.setAttribute('autocomplete', false);
const getMessage = () => {
const checkInteger = () => (isInt(node.value) ? false : 'Value must be an integer');
const checkInteger = () => (Number.isInteger(node.value) ? false : 'Value must be an integer');
const checkNumberBoundaries = boundaries => {
if (node.value < boundaries[0]) {
return `Input is too low for type ${type}`;

View File

@ -1,7 +0,0 @@
// Months
export const months = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ];
export const monthsAbbr = months.map(m => m.slice(0, 3));
// Days
export const days = [ 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday' ];
export const daysAbbr = days.map(d => d.slice(0, 3));

View File

@ -0,0 +1,27 @@
export const months = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
];
export const days = [
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
'Sunday'
];
export const daysAbbr = days.map(d => d.slice(0, 3));
export const monthsAbbr = months.map(m => m.slice(0, 3));

View File

@ -1,13 +1,4 @@
// https://stackoverflow.com/a/14794066
export function isInt(value) {
if (isNaN(value)) {
return false;
}
const x = parseFloat(value);
return (x | 0) === x;
}
export function randInt(min, max) {
export function randInt(min: number, max: number) {
return Math.round(Math.random() * (max - min) + min);
}

View File

@ -1,19 +1,19 @@
export function capitalise(string = '') {
export function capitalise(string = ''): string {
const capitalised = string.charAt(0).toUpperCase() + string.slice(1);
return capitalised;
}
export function jsonLooseParse(json) {
const obj = new Function(`return (${json})`)();
export function jsonLooseParse<T>(json: string): T {
const obj: T = new Function(`return (${json})`)();
return obj;
}
export function convertLooseJson(json) {
export function convertLooseJson(json: any) {
const j = JSON.stringify(jsonLooseParse(json));
return j;
}
export function looseJsonIsValid(json) {
export function looseJsonIsValid(json: string): boolean {
try {
jsonLooseParse(json);
return true;
@ -23,6 +23,6 @@ export function looseJsonIsValid(json) {
}
}
export function stringCouldBeID(string) {
export function stringCouldBeID(string: string) {
return /^[a-zA-Z0-9_-]{1,}$/.test(string);
}