@barchart/common-js
Version:
Library of common JavaScript utilities
166 lines (160 loc) • 4.89 kB
JavaScript
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var DayFormatType_exports = {};
__export(DayFormatType_exports, {
default: () => DayFormatType
});
module.exports = __toCommonJS(DayFormatType_exports);
var import_Enum = __toESM(require("./Enum.js"));
class DayFormatType extends import_Enum.default {
#regex;
#yearIndex;
#monthIndex;
#dayIndex;
#yearShift;
/**
* @param {string} description
* @param {RegExp} regex
* @param {number} yearIndex
* @param {number} monthIndex
* @param {number} dayIndex
* @param {number} yearShift
*/
constructor(description, regex, yearIndex, monthIndex, dayIndex, yearShift) {
super(description, description);
this.#regex = regex;
this.#yearIndex = yearIndex;
this.#monthIndex = monthIndex;
this.#dayIndex = dayIndex;
this.#yearShift = yearShift;
}
/**
* A regular expression for parsing the day type.
*
* @public
* @returns {RegExp}
*/
get regex() {
return this.#regex;
}
/**
* The index used to read the year from a regular expression match.
*
* @public
* @returns {number}
*/
get yearIndex() {
return this.#yearIndex;
}
/**
* The index used to read the month from a regular expression match.
*
* @public
* @returns {number}
*/
get monthIndex() {
return this.#monthIndex;
}
/**
* The index used to read the day from a regular expression match.
*
* @public
* @returns {number}
*/
get dayIndex() {
return this.#dayIndex;
}
/**
* The amount to add to the year (extracted from a formatted string) to get the
* full year (e.g. for "11-31-25" of an MM-DD-YY string, the value will be 2000).
*
* @public
* @returns {number}
*/
get yearShift() {
return this.#yearShift;
}
/**
* Specifies date formatting as four-digit year, then month, then day (e.g. 2025-11-31).
*
* @public
* @static
* @returns {DayFormatType}
*/
static get YYYY_MM_DD() {
return yyyymmdd;
}
/**
* Specifies date formatting as month, then day, then four-digit year (e.g. 11-31-2025).
*
* @public
* @static
* @returns {DayFormatType}
*/
static get MM_DD_YYYY() {
return mmddyyyy;
}
/**
* Specifies date formatting as month, then day, then two-digit year (e.g. 11-31-25).
*
* @public
* @static
* @returns {DayFormatType}
*/
static get MM_DD_YY() {
return mmddyy;
}
/**
* Returns a string representation.
*
* @public
* @returns {string}
*/
toString() {
return `[DayFormatType (description=${this.description})]`;
}
}
function getMillenniumShift() {
const today = /* @__PURE__ */ new Date();
return Math.floor(today.getFullYear() / 100) * 100;
}
const yyyymmdd = new DayFormatType("YYYY_MM_DD", /^([0-9]{4})[-/.]?([0-9]{1,2})[-/.]?([0-9]{1,2})$/, 1, 2, 3, 0);
const mmddyyyy = new DayFormatType("MM_DD_YYYY", /^([0-9]{1,2})[-/.]?([0-9]{1,2})[-/.]?([0-9]{4})$/, 3, 1, 2, 0);
const mmddyy = new DayFormatType("MM_DD_YY", /^([0-9]{1,2})[-/.]?([0-9]{1,2})[-/.]?([0-9]{2})$/, 3, 1, 2, getMillenniumShift());
{
const cjsExports = module.exports;
const cjsDefaultExport = cjsExports && cjsExports.__esModule ? cjsExports.default : cjsExports;
if (cjsDefaultExport && (typeof cjsDefaultExport === 'function' || typeof cjsDefaultExport === 'object')) {
Object.keys(cjsExports).forEach((key) => {
if (key !== 'default' && key !== '__esModule') {
cjsDefaultExport[key] = cjsExports[key];
}
});
}
module.exports = cjsDefaultExport;
}