UNPKG

scriptable-testlab

Version:

A lightweight, efficient tool designed to manage and update scripts for Scriptable.

80 lines 2.35 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var date_formatter_exports = {}; __export(date_formatter_exports, { MockDateFormatter: () => MockDateFormatter }); module.exports = __toCommonJS(date_formatter_exports); var import_scriptable_abstract = require("scriptable-abstract"); class MockDateFormatter extends import_scriptable_abstract.AbsDateFormatter { constructor() { super({ locale: "en-US", dateFormat: "" }); } /** * Gets the locale identifier */ get locale() { return this.state.locale.replace("-", "_"); } /** * Sets the locale identifier */ set locale(value) { const [lang, region] = value.toLowerCase().split("_"); this.setState({ locale: `${lang}-${region?.toUpperCase() || ""}`.replace(/-$/, "") }); } /** * Gets the custom date format string */ get dateFormat() { return this.state.dateFormat; } /** * Sets the custom date format string */ set dateFormat(value) { this.setState({ dateFormat: value }); } /** * Formats a date into a string * @param date Date to format * @returns Formatted date string */ string(date) { if (this.dateFormat) { return date.toLocaleString(this.state.locale); } return date.toLocaleString(this.state.locale); } /** * Parses a string into a date * @param dateString String to parse * @returns Parsed date */ date(dateString) { return new Date(dateString); } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { MockDateFormatter }); //# sourceMappingURL=date-formatter.js.map