@@ -24,40 +24,6 @@ export function delay(ms: number): Promise<void> {
2424 return new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
2525}
2626
27- /**
28- * Splits a range into smaller chunks based on a specified size.
29- * This function is useful for breaking down a large range of numbers into manageable parts,
30- * for example, when processing data in batches.
31- *
32- * @param min The minimum value of the range to split.
33- * @param max The maximum value of the range to split.
34- * @param rangeSize The size of each chunk.
35- * @returns An array of arrays, where each inner array represents a chunk with a start and end value.
36- */
37- export function splitIntoChunks ( min : number , max : number , rangeSize : number ) : number [ ] [ ] {
38- const chunks = [ ] ;
39- let current = max ;
40- if ( max - min <= rangeSize ) {
41- return [ [ min , max ] ] ;
42- }
43- while ( current > min ) {
44- const next = Math . max ( current - rangeSize , min ) ;
45- chunks . push ( [ next , current ] ) ;
46- current = next - 1 ;
47- }
48- return chunks ;
49- }
50-
51- /**
52- * Calculates the size of a data object in bytes.
53- *
54- * @param data The data object to size.
55- * @returns The size of the data in bytes.
56- */
57- export function calculateDataSize ( data : any ) {
58- return Buffer . byteLength ( JSON . stringify ( data ) , 'utf8' ) ;
59- }
60-
6127/**
6228 * Retrieves a required environment variable as a string.
6329 * Throws an error if the variable is not found, ensuring that the application configuration is correctly defined.
@@ -73,46 +39,3 @@ export function getRequiredEnvString(key: string): string {
7339 }
7440 return value ;
7541}
76-
77- /**
78- * Retrieves a required environment variable as a number.
79- * Parses the variable value as an integer and throws an error if the variable is not found or if it cannot be parsed as a number.
80- * This ensures that numeric environment configurations are valid and available before proceeding.
81- *
82- * @param key - The name of the environment variable to retrieve and parse as a number.
83- * @returns The parsed value of the environment variable as a number.
84- * @throws {Error } If the environment variable is not set or cannot be parsed as a valid number.
85- */
86- export function getRequiredEnvNumber ( key : string ) : number {
87- const value = process . env [ key ] ;
88- if ( ! value ) {
89- throw new Error ( `Environment variable ${ key } is required` ) ;
90- }
91- const parsed = parseInt ( value , 10 ) ;
92- if ( isNaN ( parsed ) ) {
93- throw new Error ( `Environment variable ${ key } must be a valid number` ) ;
94- }
95- return parsed ;
96- }
97-
98- /**
99- * Creates a signal object that can be used to manage shutdown or interrupt signals in asynchronous operations.
100- * It provides a mechanism to gracefully exit from a loop or terminate a process when an external signal is received.
101- * The signal object contains a boolean flag that is initially set to false and can be toggled to true using the
102- * trigger method. This flag can be checked periodically in asynchronous loops to determine if the process should
103- * continue running or begin shutdown procedures.
104- *
105- * @returns An object with properties 'isTriggered' to check the current state of the signal,
106- * and 'trigger' to change the state to triggered, indicating that a shutdown or interrupt has been requested.
107- */
108- export function createSignal ( ) {
109- let isTriggered = false ;
110- return {
111- get isTriggered ( ) {
112- return isTriggered ;
113- } ,
114- trigger ( ) {
115- isTriggered = true ;
116- } ,
117- } ;
118- }
0 commit comments