mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 22:25:24 +00:00
Moved utils.js to typescript
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
const moment = require("moment");
|
import moment from "moment";
|
||||||
const { EOL } = require("os");
|
import { EOL } from "os";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if an rgb value is compliant with CSS-like syntax
|
* 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
|
* @returns {Boolean} True if valid rgb, false otherwise
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function isValidRGB(value) {
|
export function isValidRGB(value: string): boolean {
|
||||||
if (!value || typeof value !== "string") {
|
if (!value || typeof value !== "string") {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -33,7 +33,7 @@ function isValidRGB(value) {
|
|||||||
* undefined otherwise
|
* undefined otherwise
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function dateToW3CString(date, format) {
|
export function dateToW3CString(date: string | Date, format?: string) {
|
||||||
if (typeof date !== "string" && !(date instanceof Date)) {
|
if (typeof date !== "string" && !(date instanceof Date)) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@@ -55,7 +55,7 @@ function dateToW3CString(date, format) {
|
|||||||
* @return {String[]}
|
* @return {String[]}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function removeHidden(from) {
|
export function removeHidden(from: Array<string>): Array<string> {
|
||||||
return from.filter(e => e.charAt(0) !== ".");
|
return from.filter(e => e.charAt(0) !== ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ function removeHidden(from) {
|
|||||||
* @see https://apple.co/2M9LWVu - String Resources
|
* @see https://apple.co/2M9LWVu - String Resources
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function generateStringFile(lang) {
|
export function generateStringFile(lang: { [index: string]: string }): Buffer {
|
||||||
if (!Object.keys(lang).length) {
|
if (!Object.keys(lang).length) {
|
||||||
return Buffer.from("", "utf8");
|
return Buffer.from("", "utf8");
|
||||||
}
|
}
|
||||||
@@ -77,7 +77,7 @@ function generateStringFile(lang) {
|
|||||||
// "key" = "value";
|
// "key" = "value";
|
||||||
|
|
||||||
const strings = Object.keys(lang)
|
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");
|
return Buffer.from(strings.join(EOL), "utf8");
|
||||||
}
|
}
|
||||||
@@ -88,14 +88,6 @@ function generateStringFile(lang) {
|
|||||||
* @param {Array<Object<string, any>>} source - the main sources of properties
|
* @param {Array<Object<string, any>>} 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);
|
return Object.assign({ length }, ...sources);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
assignLength,
|
|
||||||
generateStringFile,
|
|
||||||
removeHidden,
|
|
||||||
dateToW3CString,
|
|
||||||
isValidRGB
|
|
||||||
};
|
|
||||||
Reference in New Issue
Block a user