From 680ef5b8b714b023b6532da4bc8cdb7dc9144bd9 Mon Sep 17 00:00:00 2001 From: Alexander Cerutti Date: Sat, 11 May 2019 20:48:58 +0200 Subject: [PATCH] Moved utils.js to typescript --- src/{utils.js => utils.ts} | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) rename src/{utils.js => utils.ts} (77%) diff --git a/src/utils.js b/src/utils.ts similarity index 77% rename from src/utils.js rename to src/utils.ts index 61c7504..77f1243 100644 --- a/src/utils.js +++ b/src/utils.ts @@ -1,5 +1,5 @@ -const moment = require("moment"); -const { EOL } = require("os"); +import moment from "moment"; +import { EOL } from "os"; /** * Checks if an rgb value is compliant with CSS-like syntax @@ -9,7 +9,7 @@ const { EOL } = require("os"); * @returns {Boolean} True if valid rgb, false otherwise */ -function isValidRGB(value) { +export function isValidRGB(value: string): boolean { if (!value || typeof value !== "string") { return false; } @@ -33,7 +33,7 @@ function isValidRGB(value) { * undefined otherwise */ -function dateToW3CString(date, format) { +export function dateToW3CString(date: string | Date, format?: string) { if (typeof date !== "string" && !(date instanceof Date)) { return ""; } @@ -55,7 +55,7 @@ function dateToW3CString(date, format) { * @return {String[]} */ -function removeHidden(from) { +export function removeHidden(from: Array): Array { return from.filter(e => e.charAt(0) !== "."); } @@ -68,7 +68,7 @@ function removeHidden(from) { * @see https://apple.co/2M9LWVu - String Resources */ -function generateStringFile(lang) { +export function generateStringFile(lang: { [index: string]: string }): Buffer { if (!Object.keys(lang).length) { return Buffer.from("", "utf8"); } @@ -77,7 +77,7 @@ function generateStringFile(lang) { // "key" = "value"; const strings = Object.keys(lang) - .map(key => `"${key}" = "${lang[key].replace(/"/g, /\\"/)}";`); + .map(key => `"${key}" = "${lang[key].replace(/"/g, '\"')}";`); return Buffer.from(strings.join(EOL), "utf8"); } @@ -88,14 +88,6 @@ function generateStringFile(lang) { * @param {Array>} source - the main sources of properties */ -function assignLength(length, ...sources) { +export function assignLength(length: number, ...sources: Array<{ [key: string]: any }>): Array<{ [key: string]: any }> { return Object.assign({ length }, ...sources); } - -module.exports = { - assignLength, - generateStringFile, - removeHidden, - dateToW3CString, - isValidRGB -};