@discomedia/utils 1.0.19 → 1.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/dist/index-frontend.cjs +78 -4
- package/dist/index-frontend.cjs.map +1 -1
- package/dist/index-frontend.mjs +78 -4
- package/dist/index-frontend.mjs.map +1 -1
- package/dist/index.cjs +240 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +240 -4
- package/dist/index.mjs.map +1 -1
- package/dist/package.json +5 -9
- package/dist/test.js +5787 -1025
- package/dist/test.js.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/market-time.d.ts +97 -0
- package/dist/types/market-time.d.ts.map +1 -1
- package/dist/types-frontend/index.d.ts +1 -0
- package/dist/types-frontend/index.d.ts.map +1 -1
- package/dist/types-frontend/market-time.d.ts +97 -0
- package/dist/types-frontend/market-time.d.ts.map +1 -1
- package/package.json +5 -9
package/dist/index-frontend.mjs
CHANGED
|
@@ -247,7 +247,7 @@ const safeJSON = (text) => {
|
|
|
247
247
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
248
248
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
249
249
|
|
|
250
|
-
const VERSION = '5.10.
|
|
250
|
+
const VERSION = '5.10.2'; // x-release-please-version
|
|
251
251
|
|
|
252
252
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
253
253
|
const isRunningInBrowser = () => {
|
|
@@ -12852,7 +12852,7 @@ var config = {};
|
|
|
12852
12852
|
|
|
12853
12853
|
var main = {exports: {}};
|
|
12854
12854
|
|
|
12855
|
-
var version = "17.2.
|
|
12855
|
+
var version = "17.2.1";
|
|
12856
12856
|
var require$$4 = {
|
|
12857
12857
|
version: version};
|
|
12858
12858
|
|
|
@@ -12871,9 +12871,12 @@ function requireMain () {
|
|
|
12871
12871
|
|
|
12872
12872
|
// Array of tips to display randomly
|
|
12873
12873
|
const TIPS = [
|
|
12874
|
-
'🔐 encrypt with
|
|
12874
|
+
'🔐 encrypt with Dotenvx: https://dotenvx.com',
|
|
12875
12875
|
'🔐 prevent committing .env to code: https://dotenvx.com/precommit',
|
|
12876
12876
|
'🔐 prevent building .env in docker: https://dotenvx.com/prebuild',
|
|
12877
|
+
'📡 observe env with Radar: https://dotenvx.com/radar',
|
|
12878
|
+
'📡 auto-backup env with Radar: https://dotenvx.com/radar',
|
|
12879
|
+
'📡 version env with Radar: https://dotenvx.com/radar',
|
|
12877
12880
|
'🛠️ run anywhere with `dotenvx run -- yourcommand`',
|
|
12878
12881
|
'⚙️ specify custom .env file path with { path: \'/custom/path/.env\' }',
|
|
12879
12882
|
'⚙️ enable debug logging with { debug: true }',
|
|
@@ -13174,7 +13177,7 @@ function requireMain () {
|
|
|
13174
13177
|
}
|
|
13175
13178
|
}
|
|
13176
13179
|
|
|
13177
|
-
_log(`injecting env (${keysCount}) from ${shortPaths.join(',')} ${dim(
|
|
13180
|
+
_log(`injecting env (${keysCount}) from ${shortPaths.join(',')} ${dim(`-- tip: ${_getRandomTip()}`)}`);
|
|
13178
13181
|
}
|
|
13179
13182
|
|
|
13180
13183
|
if (lastError) {
|
|
@@ -13487,6 +13490,11 @@ const MARKET_CONFIG = {
|
|
|
13487
13490
|
EARLY_CLOSE: { hour: 13, minute: 0 }},
|
|
13488
13491
|
};
|
|
13489
13492
|
// Helper: Get NY offset for a given UTC date (DST rules for US)
|
|
13493
|
+
/**
|
|
13494
|
+
* Returns the NY timezone offset (in hours) for a given UTC date, accounting for US DST rules.
|
|
13495
|
+
* @param date - UTC date
|
|
13496
|
+
* @returns offset in hours (-5 for EST, -4 for EDT)
|
|
13497
|
+
*/
|
|
13490
13498
|
function getNYOffset(date) {
|
|
13491
13499
|
// US DST starts 2nd Sunday in March, ends 1st Sunday in November
|
|
13492
13500
|
const year = date.getUTCFullYear();
|
|
@@ -13499,6 +13507,14 @@ function getNYOffset(date) {
|
|
|
13499
13507
|
return MARKET_CONFIG.UTC_OFFSET_STANDARD;
|
|
13500
13508
|
}
|
|
13501
13509
|
// Helper: Get nth weekday of month in UTC
|
|
13510
|
+
/**
|
|
13511
|
+
* Returns the nth weekday of a given month in UTC.
|
|
13512
|
+
* @param year - Year
|
|
13513
|
+
* @param month - 1-based month (e.g. March = 3)
|
|
13514
|
+
* @param weekday - 0=Sunday, 1=Monday, ...
|
|
13515
|
+
* @param n - nth occurrence
|
|
13516
|
+
* @returns Date object for the nth weekday
|
|
13517
|
+
*/
|
|
13502
13518
|
function getNthWeekdayOfMonth(year, month, weekday, n) {
|
|
13503
13519
|
let count = 0;
|
|
13504
13520
|
for (let d = 1; d <= 31; d++) {
|
|
@@ -13515,6 +13531,11 @@ function getNthWeekdayOfMonth(year, month, weekday, n) {
|
|
|
13515
13531
|
return new Date(Date.UTC(year, month - 1, 28));
|
|
13516
13532
|
}
|
|
13517
13533
|
// Helper: Convert UTC date to NY time (returns new Date object)
|
|
13534
|
+
/**
|
|
13535
|
+
* Converts a UTC date to NY time (returns a new Date object).
|
|
13536
|
+
* @param date - UTC date
|
|
13537
|
+
* @returns Date object in NY time
|
|
13538
|
+
*/
|
|
13518
13539
|
function toNYTime(date) {
|
|
13519
13540
|
const offset = getNYOffset(date);
|
|
13520
13541
|
// NY offset in hours
|
|
@@ -13523,6 +13544,11 @@ function toNYTime(date) {
|
|
|
13523
13544
|
return new Date(nyMillis);
|
|
13524
13545
|
}
|
|
13525
13546
|
// Helper: Convert NY time to UTC (returns new Date object)
|
|
13547
|
+
/**
|
|
13548
|
+
* Converts a NY time date to UTC (returns a new Date object).
|
|
13549
|
+
* @param date - NY time date
|
|
13550
|
+
* @returns Date object in UTC
|
|
13551
|
+
*/
|
|
13526
13552
|
function fromNYTime(date) {
|
|
13527
13553
|
const offset = getNYOffset(date);
|
|
13528
13554
|
const nyMillis = date.getTime();
|
|
@@ -13530,11 +13556,24 @@ function fromNYTime(date) {
|
|
|
13530
13556
|
return new Date(utcMillis);
|
|
13531
13557
|
}
|
|
13532
13558
|
// Market calendar logic
|
|
13559
|
+
/**
|
|
13560
|
+
* Market calendar logic for holidays, weekends, and market days.
|
|
13561
|
+
*/
|
|
13533
13562
|
class MarketCalendar {
|
|
13563
|
+
/**
|
|
13564
|
+
* Checks if a date is a weekend in NY time.
|
|
13565
|
+
* @param date - Date object
|
|
13566
|
+
* @returns true if weekend, false otherwise
|
|
13567
|
+
*/
|
|
13534
13568
|
isWeekend(date) {
|
|
13535
13569
|
const day = toNYTime(date).getUTCDay();
|
|
13536
13570
|
return day === 0 || day === 6;
|
|
13537
13571
|
}
|
|
13572
|
+
/**
|
|
13573
|
+
* Checks if a date is a market holiday in NY time.
|
|
13574
|
+
* @param date - Date object
|
|
13575
|
+
* @returns true if holiday, false otherwise
|
|
13576
|
+
*/
|
|
13538
13577
|
isHoliday(date) {
|
|
13539
13578
|
const nyDate = toNYTime(date);
|
|
13540
13579
|
const year = nyDate.getUTCFullYear();
|
|
@@ -13546,6 +13585,11 @@ class MarketCalendar {
|
|
|
13546
13585
|
return false;
|
|
13547
13586
|
return Object.values(yearHolidays).some(holiday => holiday.date === formattedDate);
|
|
13548
13587
|
}
|
|
13588
|
+
/**
|
|
13589
|
+
* Checks if a date is an early close day in NY time.
|
|
13590
|
+
* @param date - Date object
|
|
13591
|
+
* @returns true if early close, false otherwise
|
|
13592
|
+
*/
|
|
13549
13593
|
isEarlyCloseDay(date) {
|
|
13550
13594
|
const nyDate = toNYTime(date);
|
|
13551
13595
|
const year = nyDate.getUTCFullYear();
|
|
@@ -13555,6 +13599,11 @@ class MarketCalendar {
|
|
|
13555
13599
|
const yearEarlyCloses = marketEarlyCloses[year];
|
|
13556
13600
|
return yearEarlyCloses && yearEarlyCloses[formattedDate] !== undefined;
|
|
13557
13601
|
}
|
|
13602
|
+
/**
|
|
13603
|
+
* Gets the early close time (in minutes from midnight) for a given date.
|
|
13604
|
+
* @param date - Date object
|
|
13605
|
+
* @returns minutes from midnight or null
|
|
13606
|
+
*/
|
|
13558
13607
|
getEarlyCloseTime(date) {
|
|
13559
13608
|
const nyDate = toNYTime(date);
|
|
13560
13609
|
const year = nyDate.getUTCFullYear();
|
|
@@ -13568,9 +13617,19 @@ class MarketCalendar {
|
|
|
13568
13617
|
}
|
|
13569
13618
|
return null;
|
|
13570
13619
|
}
|
|
13620
|
+
/**
|
|
13621
|
+
* Checks if a date is a market day (not weekend or holiday).
|
|
13622
|
+
* @param date - Date object
|
|
13623
|
+
* @returns true if market day, false otherwise
|
|
13624
|
+
*/
|
|
13571
13625
|
isMarketDay(date) {
|
|
13572
13626
|
return !this.isWeekend(date) && !this.isHoliday(date);
|
|
13573
13627
|
}
|
|
13628
|
+
/**
|
|
13629
|
+
* Gets the next market day after the given date.
|
|
13630
|
+
* @param date - Date object
|
|
13631
|
+
* @returns Date object for next market day
|
|
13632
|
+
*/
|
|
13574
13633
|
getNextMarketDay(date) {
|
|
13575
13634
|
let nextDay = new Date(date.getTime() + 24 * 60 * 60 * 1000);
|
|
13576
13635
|
while (!this.isMarketDay(nextDay)) {
|
|
@@ -13578,6 +13637,11 @@ class MarketCalendar {
|
|
|
13578
13637
|
}
|
|
13579
13638
|
return nextDay;
|
|
13580
13639
|
}
|
|
13640
|
+
/**
|
|
13641
|
+
* Gets the previous market day before the given date.
|
|
13642
|
+
* @param date - Date object
|
|
13643
|
+
* @returns Date object for previous market day
|
|
13644
|
+
*/
|
|
13581
13645
|
getPreviousMarketDay(date) {
|
|
13582
13646
|
let prevDay = new Date(date.getTime() - 24 * 60 * 60 * 1000);
|
|
13583
13647
|
while (!this.isMarketDay(prevDay)) {
|
|
@@ -13587,6 +13651,11 @@ class MarketCalendar {
|
|
|
13587
13651
|
}
|
|
13588
13652
|
}
|
|
13589
13653
|
// Get last full trading date
|
|
13654
|
+
/**
|
|
13655
|
+
* Returns the last full trading date (market close) for a given date.
|
|
13656
|
+
* @param currentDate - Date object (default: now)
|
|
13657
|
+
* @returns Date object for last full trading date
|
|
13658
|
+
*/
|
|
13590
13659
|
function getLastFullTradingDateImpl(currentDate = new Date()) {
|
|
13591
13660
|
const calendar = new MarketCalendar();
|
|
13592
13661
|
const nyDate = toNYTime(currentDate);
|
|
@@ -13621,6 +13690,11 @@ function getLastFullTradingDateImpl(currentDate = new Date()) {
|
|
|
13621
13690
|
/**
|
|
13622
13691
|
* Returns the last full trading date as a Date object.
|
|
13623
13692
|
*/
|
|
13693
|
+
/**
|
|
13694
|
+
* Returns the last full trading date as a Date object.
|
|
13695
|
+
* @param currentDate - Date object (default: now)
|
|
13696
|
+
* @returns Date object for last full trading date
|
|
13697
|
+
*/
|
|
13624
13698
|
function getLastFullTradingDate(currentDate = new Date()) {
|
|
13625
13699
|
return getLastFullTradingDateImpl(currentDate);
|
|
13626
13700
|
}
|