@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/README.md
CHANGED
|
@@ -12,6 +12,11 @@ NPM repo: https://www.npmjs.com/package/@discomedia/utils
|
|
|
12
12
|
npm install @discomedia/utils
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
+
> **Note:**
|
|
16
|
+
> The [`tslib`](https://www.npmjs.com/package/tslib) package is required for building this library on GitHub Actions and other CI environments.
|
|
17
|
+
> It is included as a dependency because Rollup and TypeScript emit helpers that require `tslib` at build time.
|
|
18
|
+
> Do not remove `tslib` from dependencies, or CI builds will fail.
|
|
19
|
+
|
|
15
20
|
## Usage
|
|
16
21
|
|
|
17
22
|
This package provides two different entry points depending on your environment:
|
package/dist/index-frontend.cjs
CHANGED
|
@@ -249,7 +249,7 @@ const safeJSON = (text) => {
|
|
|
249
249
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
250
250
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
251
251
|
|
|
252
|
-
const VERSION = '5.10.
|
|
252
|
+
const VERSION = '5.10.2'; // x-release-please-version
|
|
253
253
|
|
|
254
254
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
255
255
|
const isRunningInBrowser = () => {
|
|
@@ -12854,7 +12854,7 @@ var config = {};
|
|
|
12854
12854
|
|
|
12855
12855
|
var main = {exports: {}};
|
|
12856
12856
|
|
|
12857
|
-
var version = "17.2.
|
|
12857
|
+
var version = "17.2.1";
|
|
12858
12858
|
var require$$4 = {
|
|
12859
12859
|
version: version};
|
|
12860
12860
|
|
|
@@ -12873,9 +12873,12 @@ function requireMain () {
|
|
|
12873
12873
|
|
|
12874
12874
|
// Array of tips to display randomly
|
|
12875
12875
|
const TIPS = [
|
|
12876
|
-
'🔐 encrypt with
|
|
12876
|
+
'🔐 encrypt with Dotenvx: https://dotenvx.com',
|
|
12877
12877
|
'🔐 prevent committing .env to code: https://dotenvx.com/precommit',
|
|
12878
12878
|
'🔐 prevent building .env in docker: https://dotenvx.com/prebuild',
|
|
12879
|
+
'📡 observe env with Radar: https://dotenvx.com/radar',
|
|
12880
|
+
'📡 auto-backup env with Radar: https://dotenvx.com/radar',
|
|
12881
|
+
'📡 version env with Radar: https://dotenvx.com/radar',
|
|
12879
12882
|
'🛠️ run anywhere with `dotenvx run -- yourcommand`',
|
|
12880
12883
|
'⚙️ specify custom .env file path with { path: \'/custom/path/.env\' }',
|
|
12881
12884
|
'⚙️ enable debug logging with { debug: true }',
|
|
@@ -13176,7 +13179,7 @@ function requireMain () {
|
|
|
13176
13179
|
}
|
|
13177
13180
|
}
|
|
13178
13181
|
|
|
13179
|
-
_log(`injecting env (${keysCount}) from ${shortPaths.join(',')} ${dim(
|
|
13182
|
+
_log(`injecting env (${keysCount}) from ${shortPaths.join(',')} ${dim(`-- tip: ${_getRandomTip()}`)}`);
|
|
13180
13183
|
}
|
|
13181
13184
|
|
|
13182
13185
|
if (lastError) {
|
|
@@ -13489,6 +13492,11 @@ const MARKET_CONFIG = {
|
|
|
13489
13492
|
EARLY_CLOSE: { hour: 13, minute: 0 }},
|
|
13490
13493
|
};
|
|
13491
13494
|
// Helper: Get NY offset for a given UTC date (DST rules for US)
|
|
13495
|
+
/**
|
|
13496
|
+
* Returns the NY timezone offset (in hours) for a given UTC date, accounting for US DST rules.
|
|
13497
|
+
* @param date - UTC date
|
|
13498
|
+
* @returns offset in hours (-5 for EST, -4 for EDT)
|
|
13499
|
+
*/
|
|
13492
13500
|
function getNYOffset(date) {
|
|
13493
13501
|
// US DST starts 2nd Sunday in March, ends 1st Sunday in November
|
|
13494
13502
|
const year = date.getUTCFullYear();
|
|
@@ -13501,6 +13509,14 @@ function getNYOffset(date) {
|
|
|
13501
13509
|
return MARKET_CONFIG.UTC_OFFSET_STANDARD;
|
|
13502
13510
|
}
|
|
13503
13511
|
// Helper: Get nth weekday of month in UTC
|
|
13512
|
+
/**
|
|
13513
|
+
* Returns the nth weekday of a given month in UTC.
|
|
13514
|
+
* @param year - Year
|
|
13515
|
+
* @param month - 1-based month (e.g. March = 3)
|
|
13516
|
+
* @param weekday - 0=Sunday, 1=Monday, ...
|
|
13517
|
+
* @param n - nth occurrence
|
|
13518
|
+
* @returns Date object for the nth weekday
|
|
13519
|
+
*/
|
|
13504
13520
|
function getNthWeekdayOfMonth(year, month, weekday, n) {
|
|
13505
13521
|
let count = 0;
|
|
13506
13522
|
for (let d = 1; d <= 31; d++) {
|
|
@@ -13517,6 +13533,11 @@ function getNthWeekdayOfMonth(year, month, weekday, n) {
|
|
|
13517
13533
|
return new Date(Date.UTC(year, month - 1, 28));
|
|
13518
13534
|
}
|
|
13519
13535
|
// Helper: Convert UTC date to NY time (returns new Date object)
|
|
13536
|
+
/**
|
|
13537
|
+
* Converts a UTC date to NY time (returns a new Date object).
|
|
13538
|
+
* @param date - UTC date
|
|
13539
|
+
* @returns Date object in NY time
|
|
13540
|
+
*/
|
|
13520
13541
|
function toNYTime(date) {
|
|
13521
13542
|
const offset = getNYOffset(date);
|
|
13522
13543
|
// NY offset in hours
|
|
@@ -13525,6 +13546,11 @@ function toNYTime(date) {
|
|
|
13525
13546
|
return new Date(nyMillis);
|
|
13526
13547
|
}
|
|
13527
13548
|
// Helper: Convert NY time to UTC (returns new Date object)
|
|
13549
|
+
/**
|
|
13550
|
+
* Converts a NY time date to UTC (returns a new Date object).
|
|
13551
|
+
* @param date - NY time date
|
|
13552
|
+
* @returns Date object in UTC
|
|
13553
|
+
*/
|
|
13528
13554
|
function fromNYTime(date) {
|
|
13529
13555
|
const offset = getNYOffset(date);
|
|
13530
13556
|
const nyMillis = date.getTime();
|
|
@@ -13532,11 +13558,24 @@ function fromNYTime(date) {
|
|
|
13532
13558
|
return new Date(utcMillis);
|
|
13533
13559
|
}
|
|
13534
13560
|
// Market calendar logic
|
|
13561
|
+
/**
|
|
13562
|
+
* Market calendar logic for holidays, weekends, and market days.
|
|
13563
|
+
*/
|
|
13535
13564
|
class MarketCalendar {
|
|
13565
|
+
/**
|
|
13566
|
+
* Checks if a date is a weekend in NY time.
|
|
13567
|
+
* @param date - Date object
|
|
13568
|
+
* @returns true if weekend, false otherwise
|
|
13569
|
+
*/
|
|
13536
13570
|
isWeekend(date) {
|
|
13537
13571
|
const day = toNYTime(date).getUTCDay();
|
|
13538
13572
|
return day === 0 || day === 6;
|
|
13539
13573
|
}
|
|
13574
|
+
/**
|
|
13575
|
+
* Checks if a date is a market holiday in NY time.
|
|
13576
|
+
* @param date - Date object
|
|
13577
|
+
* @returns true if holiday, false otherwise
|
|
13578
|
+
*/
|
|
13540
13579
|
isHoliday(date) {
|
|
13541
13580
|
const nyDate = toNYTime(date);
|
|
13542
13581
|
const year = nyDate.getUTCFullYear();
|
|
@@ -13548,6 +13587,11 @@ class MarketCalendar {
|
|
|
13548
13587
|
return false;
|
|
13549
13588
|
return Object.values(yearHolidays).some(holiday => holiday.date === formattedDate);
|
|
13550
13589
|
}
|
|
13590
|
+
/**
|
|
13591
|
+
* Checks if a date is an early close day in NY time.
|
|
13592
|
+
* @param date - Date object
|
|
13593
|
+
* @returns true if early close, false otherwise
|
|
13594
|
+
*/
|
|
13551
13595
|
isEarlyCloseDay(date) {
|
|
13552
13596
|
const nyDate = toNYTime(date);
|
|
13553
13597
|
const year = nyDate.getUTCFullYear();
|
|
@@ -13557,6 +13601,11 @@ class MarketCalendar {
|
|
|
13557
13601
|
const yearEarlyCloses = marketEarlyCloses[year];
|
|
13558
13602
|
return yearEarlyCloses && yearEarlyCloses[formattedDate] !== undefined;
|
|
13559
13603
|
}
|
|
13604
|
+
/**
|
|
13605
|
+
* Gets the early close time (in minutes from midnight) for a given date.
|
|
13606
|
+
* @param date - Date object
|
|
13607
|
+
* @returns minutes from midnight or null
|
|
13608
|
+
*/
|
|
13560
13609
|
getEarlyCloseTime(date) {
|
|
13561
13610
|
const nyDate = toNYTime(date);
|
|
13562
13611
|
const year = nyDate.getUTCFullYear();
|
|
@@ -13570,9 +13619,19 @@ class MarketCalendar {
|
|
|
13570
13619
|
}
|
|
13571
13620
|
return null;
|
|
13572
13621
|
}
|
|
13622
|
+
/**
|
|
13623
|
+
* Checks if a date is a market day (not weekend or holiday).
|
|
13624
|
+
* @param date - Date object
|
|
13625
|
+
* @returns true if market day, false otherwise
|
|
13626
|
+
*/
|
|
13573
13627
|
isMarketDay(date) {
|
|
13574
13628
|
return !this.isWeekend(date) && !this.isHoliday(date);
|
|
13575
13629
|
}
|
|
13630
|
+
/**
|
|
13631
|
+
* Gets the next market day after the given date.
|
|
13632
|
+
* @param date - Date object
|
|
13633
|
+
* @returns Date object for next market day
|
|
13634
|
+
*/
|
|
13576
13635
|
getNextMarketDay(date) {
|
|
13577
13636
|
let nextDay = new Date(date.getTime() + 24 * 60 * 60 * 1000);
|
|
13578
13637
|
while (!this.isMarketDay(nextDay)) {
|
|
@@ -13580,6 +13639,11 @@ class MarketCalendar {
|
|
|
13580
13639
|
}
|
|
13581
13640
|
return nextDay;
|
|
13582
13641
|
}
|
|
13642
|
+
/**
|
|
13643
|
+
* Gets the previous market day before the given date.
|
|
13644
|
+
* @param date - Date object
|
|
13645
|
+
* @returns Date object for previous market day
|
|
13646
|
+
*/
|
|
13583
13647
|
getPreviousMarketDay(date) {
|
|
13584
13648
|
let prevDay = new Date(date.getTime() - 24 * 60 * 60 * 1000);
|
|
13585
13649
|
while (!this.isMarketDay(prevDay)) {
|
|
@@ -13589,6 +13653,11 @@ class MarketCalendar {
|
|
|
13589
13653
|
}
|
|
13590
13654
|
}
|
|
13591
13655
|
// Get last full trading date
|
|
13656
|
+
/**
|
|
13657
|
+
* Returns the last full trading date (market close) for a given date.
|
|
13658
|
+
* @param currentDate - Date object (default: now)
|
|
13659
|
+
* @returns Date object for last full trading date
|
|
13660
|
+
*/
|
|
13592
13661
|
function getLastFullTradingDateImpl(currentDate = new Date()) {
|
|
13593
13662
|
const calendar = new MarketCalendar();
|
|
13594
13663
|
const nyDate = toNYTime(currentDate);
|
|
@@ -13623,6 +13692,11 @@ function getLastFullTradingDateImpl(currentDate = new Date()) {
|
|
|
13623
13692
|
/**
|
|
13624
13693
|
* Returns the last full trading date as a Date object.
|
|
13625
13694
|
*/
|
|
13695
|
+
/**
|
|
13696
|
+
* Returns the last full trading date as a Date object.
|
|
13697
|
+
* @param currentDate - Date object (default: now)
|
|
13698
|
+
* @returns Date object for last full trading date
|
|
13699
|
+
*/
|
|
13626
13700
|
function getLastFullTradingDate(currentDate = new Date()) {
|
|
13627
13701
|
return getLastFullTradingDateImpl(currentDate);
|
|
13628
13702
|
}
|