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:
parent
5b15782d7d
commit
82796d5a8c
@ -22,6 +22,7 @@
|
||||
"include": [
|
||||
"src/**/*.d.ts",
|
||||
"src/**/*.js",
|
||||
"src/**/*.ts",
|
||||
"src/**/*.svelte"
|
||||
]
|
||||
}
|
||||
|
@ -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}`;
|
||||
|
@ -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));
|
27
frontend/src/lib/constants.ts
Normal file
27
frontend/src/lib/constants.ts
Normal 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));
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user