nhb-toolbox 3.2.0 → 3.3.0
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/dist/date/greet.d.ts +9 -0
- package/dist/date/greet.d.ts.map +1 -0
- package/dist/date/greet.js +45 -0
- package/dist/date/guards.d.ts +9 -0
- package/dist/date/guards.d.ts.map +1 -0
- package/dist/date/guards.js +18 -0
- package/dist/date/types.d.ts +34 -0
- package/dist/date/types.d.ts.map +1 -0
- package/dist/date/types.js +1 -0
- package/dist/date/utils.d.ts +16 -0
- package/dist/date/utils.d.ts.map +1 -0
- package/dist/date/utils.js +20 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -2
- package/dist/number/basics.d.ts +11 -39
- package/dist/number/basics.d.ts.map +1 -1
- package/dist/number/basics.js +14 -49
- package/dist/number/guards.d.ts +37 -0
- package/dist/number/guards.d.ts.map +1 -0
- package/dist/number/guards.js +46 -0
- package/dist/number/range.d.ts.map +1 -1
- package/dist/number/range.js +2 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { GreetingConfigs } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* * Returns a greeting message based on the provided time or current time.
|
|
4
|
+
*
|
|
5
|
+
* @param configs - Configuration options for greeting times and messages.
|
|
6
|
+
* @returns The appropriate greeting message.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getGreeting(configs?: GreetingConfigs): string;
|
|
9
|
+
//# sourceMappingURL=greet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"greet.d.ts","sourceRoot":"","sources":["../../src/date/greet.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,MAAM,CAgD7D"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { isValidTime } from './guards';
|
|
2
|
+
import { extractHourMinute, getTotalMinutes } from './utils';
|
|
3
|
+
/**
|
|
4
|
+
* * Returns a greeting message based on the provided time or current time.
|
|
5
|
+
*
|
|
6
|
+
* @param configs - Configuration options for greeting times and messages.
|
|
7
|
+
* @returns The appropriate greeting message.
|
|
8
|
+
*/
|
|
9
|
+
export function getGreeting(configs) {
|
|
10
|
+
const { morningEnds = '11:59', noonEnds = '12:59', afternoonEnds = '17:59', eveningEnds = '23:59', midnightEnds = '02:59', currentTime, morningMessage = 'Good Morning!', noonMessage = 'Good Noon!', afternoonMessage = 'Good Afternoon!', eveningMessage = 'Good Evening!', midnightMessage = 'Hello, Night Owl!', defaultMessage = 'Greetings!', } = configs || {};
|
|
11
|
+
let hour;
|
|
12
|
+
let minute;
|
|
13
|
+
if (currentTime && isValidTime(currentTime)) {
|
|
14
|
+
[hour, minute] = extractHourMinute(currentTime);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
const now = new Date();
|
|
18
|
+
hour = now.getHours();
|
|
19
|
+
minute = now.getMinutes();
|
|
20
|
+
}
|
|
21
|
+
const currentTotalMinutes = hour * 60 + minute;
|
|
22
|
+
const morningEndMinutes = getTotalMinutes(morningEnds);
|
|
23
|
+
const noonEndMinutes = getTotalMinutes(noonEnds);
|
|
24
|
+
const afternoonEndMinutes = getTotalMinutes(afternoonEnds);
|
|
25
|
+
const eveningEndMinutes = getTotalMinutes(eveningEnds);
|
|
26
|
+
const midnightEndMinutes = getTotalMinutes(midnightEnds);
|
|
27
|
+
if (currentTotalMinutes <= midnightEndMinutes) {
|
|
28
|
+
return midnightMessage;
|
|
29
|
+
}
|
|
30
|
+
else if (currentTotalMinutes <= morningEndMinutes) {
|
|
31
|
+
return morningMessage;
|
|
32
|
+
}
|
|
33
|
+
else if (currentTotalMinutes <= noonEndMinutes) {
|
|
34
|
+
return noonMessage;
|
|
35
|
+
}
|
|
36
|
+
else if (currentTotalMinutes <= afternoonEndMinutes) {
|
|
37
|
+
return afternoonMessage;
|
|
38
|
+
}
|
|
39
|
+
else if (currentTotalMinutes <= eveningEndMinutes) {
|
|
40
|
+
return eveningMessage;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
return defaultMessage;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Time } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* * Checks if the provided value is a valid time string in "HH:MM" format.
|
|
4
|
+
*
|
|
5
|
+
* @param value - The value to check.
|
|
6
|
+
* @returns `true` if the value is a valid time string, `false` otherwise.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isValidTime(value: unknown): value is Time;
|
|
9
|
+
//# sourceMappingURL=guards.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../../src/date/guards.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAEpC;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,IAAI,CAWzD"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { isString } from '../guards/primitives';
|
|
2
|
+
import { isNumericString } from '../guards/specials';
|
|
3
|
+
/**
|
|
4
|
+
* * Checks if the provided value is a valid time string in "HH:MM" format.
|
|
5
|
+
*
|
|
6
|
+
* @param value - The value to check.
|
|
7
|
+
* @returns `true` if the value is a valid time string, `false` otherwise.
|
|
8
|
+
*/
|
|
9
|
+
export function isValidTime(value) {
|
|
10
|
+
if (!isString(value))
|
|
11
|
+
return false;
|
|
12
|
+
const [hourStr, minuteStr] = value.split(':');
|
|
13
|
+
if (!isNumericString(hourStr) || !isNumericString(minuteStr))
|
|
14
|
+
return false;
|
|
15
|
+
const hour = Number(hourStr);
|
|
16
|
+
const minute = Number(minuteStr);
|
|
17
|
+
return hour >= 0 && hour <= 23 && minute >= 0 && minute <= 59;
|
|
18
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** - Minute in numeric string from `00` to `23` */
|
|
2
|
+
export type Hour = '00' | '01' | '02' | '03' | '04' | '05' | '06' | '07' | '08' | '09' | '10' | '11' | '12' | '13' | '14' | '15' | '16' | '17' | '18' | '19' | '20' | '21' | '22' | '23';
|
|
3
|
+
/** - Minute in numeric string from `00` to `59` */
|
|
4
|
+
export type Minute = '00' | '01' | '02' | '03' | '04' | '05' | '06' | '07' | '08' | '09' | '10' | '11' | '12' | '13' | '14' | '15' | '16' | '17' | '18' | '19' | '20' | '21' | '22' | '23' | '24' | '25' | '26' | '27' | '28' | '29' | '30' | '31' | '32' | '33' | '34' | '35' | '36' | '37' | '38' | '39' | '40' | '41' | '42' | '43' | '44' | '45' | '46' | '47' | '48' | '49' | '50' | '51' | '52' | '53' | '54' | '55' | '56' | '57' | '58' | '59';
|
|
5
|
+
/** - Time in "HH:MM" format. */
|
|
6
|
+
export type Time = `${Hour}:${Minute}`;
|
|
7
|
+
/** - Configuration options for greeting. */
|
|
8
|
+
export interface GreetingConfigs {
|
|
9
|
+
/** Time when the morning period ends (HH:MM format). Defaults to `11:59` */
|
|
10
|
+
morningEnds?: Time;
|
|
11
|
+
/** Time when the noon period ends (HH:MM format). Defaults to `12:59` */
|
|
12
|
+
noonEnds?: Time;
|
|
13
|
+
/** Time when the afternoon period ends (HH:MM format). Defaults to `17:59` */
|
|
14
|
+
afternoonEnds?: Time;
|
|
15
|
+
/** Time when the evening period ends (HH:MM format). Defaults to `23:59` */
|
|
16
|
+
eveningEnds?: Time;
|
|
17
|
+
/** Time when the midnight period ends (HH:MM format). Defaults to `02:59` */
|
|
18
|
+
midnightEnds?: Time;
|
|
19
|
+
/** Current time in "HH:MM" format for some weird reason. Defaults to current time `new Date()` */
|
|
20
|
+
currentTime?: Time;
|
|
21
|
+
/** Custom greeting message for the morning period. */
|
|
22
|
+
morningMessage?: string;
|
|
23
|
+
/** Custom greeting message for the noon period. */
|
|
24
|
+
noonMessage?: string;
|
|
25
|
+
/** Custom greeting message for the afternoon period. */
|
|
26
|
+
afternoonMessage?: string;
|
|
27
|
+
/** Custom greeting message for the evening period. */
|
|
28
|
+
eveningMessage?: string;
|
|
29
|
+
/** Custom greeting message for the midnight period. */
|
|
30
|
+
midnightMessage?: string;
|
|
31
|
+
/** Default greeting message if no period matches. */
|
|
32
|
+
defaultMessage?: string;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/date/types.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,MAAM,MAAM,IAAI,GACb,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,CAAC;AAER,mDAAmD;AACnD,MAAM,MAAM,MAAM,GACf,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GAC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
|
+
* * Extracts the hour and minute from a time string in `HH:MM` format.
|
|
4
|
+
*
|
|
5
|
+
* @param time - The time string to extract from.
|
|
6
|
+
* @return The extracted hour and minute as number tuple.
|
|
7
|
+
*/
|
|
8
|
+
export declare function extractHourMinute(time: Time): [number, number];
|
|
9
|
+
/**
|
|
10
|
+
* * Converts a time string `HH:MM` into total minutes from `00:00`.
|
|
11
|
+
*
|
|
12
|
+
* @param time - The time in `HH:MM` format.
|
|
13
|
+
* @returns The total minutes elapsed since `00:00`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getTotalMinutes(time: Time): number;
|
|
16
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/date/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAEpC;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAI9D;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAIlD"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* * Extracts the hour and minute from a time string in `HH:MM` format.
|
|
3
|
+
*
|
|
4
|
+
* @param time - The time string to extract from.
|
|
5
|
+
* @return The extracted hour and minute as number tuple.
|
|
6
|
+
*/
|
|
7
|
+
export function extractHourMinute(time) {
|
|
8
|
+
const [hour, minute] = time.split(':').map(Number);
|
|
9
|
+
return [hour, minute];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* * Converts a time string `HH:MM` into total minutes from `00:00`.
|
|
13
|
+
*
|
|
14
|
+
* @param time - The time in `HH:MM` format.
|
|
15
|
+
* @returns The total minutes elapsed since `00:00`.
|
|
16
|
+
*/
|
|
17
|
+
export function getTotalMinutes(time) {
|
|
18
|
+
const [h, m] = extractHourMinute(time);
|
|
19
|
+
return h * 60 + m;
|
|
20
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,15 +3,19 @@ export { generateAnagrams } from './string/anagram';
|
|
|
3
3
|
export { isCamelCase, isEmojiOnly, isKebabCase, isPalindrome, isPascalCase, isSnakeCase, } from './string/guards';
|
|
4
4
|
export { convertStringCase, extractEmails, extractURLs, maskString, normalizeString, replaceAllInString, reverseString, slugifyString, } from './string/convert';
|
|
5
5
|
export { extractNumbersFromString, getLevenshteinDistance, getLevenshteinDistance as levenshteinDistance, } from './string/utilities';
|
|
6
|
-
export { calculateHCF as calculateGCD, calculateHCF, calculateLCM as calculateLCD, calculateLCM, convertToDecimal, getFibonacciSeries as getFibonacci, getFibonacciSeries as getFibonacciNumbers, getFibonacciSeries, getRandomNumber,
|
|
6
|
+
export { calculateHCF as calculateGCD, calculateHCF, calculateLCM as calculateLCD, calculateLCM, convertToDecimal, getFibonacciSeries as getFibonacci, getFibonacciSeries as getFibonacciNumbers, getFibonacciSeries, getRandomNumber, sumNumbers as getSumOfNumbers, reverseNumber, sumDigits, sumNumbers, sumNumbers as sumOfNumbers, } from './number/basics';
|
|
7
|
+
export { isEven, isEven as isEvenNumber, isFibonacci, isMultiple, isOdd, isOdd as isOddNumber, isFibonacci as isParOfFibonacci, isFibonacci as isParOfFibonacciSeries, isPerfectSquare, } from './number/guards';
|
|
7
8
|
export { numberToWords as convertNumberToWords, convertToRomanNumerals, numberToWords, } from './number/convert';
|
|
8
|
-
export { findPrimeNumbers, isPrime, isPrime as isPrimeNumber, } from './number/prime';
|
|
9
|
+
export { findPrimeNumbers, findPrimeNumbers as getPrimeNumbers, isPrime, isPrime as isPrimeNumber, } from './number/prime';
|
|
9
10
|
export { clampNumber, formatCurrency as convertNumberToCurrency, formatCurrency, getRandomFloat as getRandomDecimal, getRandomFloat, roundToNearest as roundNumber, roundToNearest as roundNumberToNearestInterval, roundToNearest, roundToNearest as roundToNearestInterval, } from './number/utilities';
|
|
10
11
|
export { getNumbersInRange } from './number/range';
|
|
11
12
|
export { getColorForInitial } from './colors/initials';
|
|
12
13
|
export { generateRandomColorInHexRGB, generateRandomHSLColor, } from './colors/random';
|
|
13
14
|
export { convertColorCode, convertHex8ToHsla, convertHex8ToRgba, convertHexToHsl, convertHexToRgb, convertHslaToHex8, convertHslaToRgba, convertHslToHex, convertHslToRgb, convertRgbaToHex8, convertRgbaToHsla, convertRgbToHex, convertRgbToHsl, convertRgbToRgba, } from './colors/convert';
|
|
14
15
|
export { Color, Color as Colour } from './colors/Color';
|
|
16
|
+
export { getGreeting as generateGreeting, getGreeting, getGreeting as greet, } from './date/greet';
|
|
17
|
+
export { isValidTime, isValidTime as isValidTimeString } from './date/guards';
|
|
18
|
+
export { extractHourMinute, getTotalMinutes } from './date/utils';
|
|
15
19
|
export { filterArrayOfObjects, flattenArray, getLastArrayElement, isInvalidOrEmptyArray, isInvalidOrEmptyArray as isValidEmptyArray, shuffleArray, } from './array/basics';
|
|
16
20
|
export { sortAnArray } from './array/sort';
|
|
17
21
|
export { createOptionsArray, moveArrayElement, removeDuplicatesFromArray, rotateArray, splitArray, } from './array/transform';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACN,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,EACV,cAAc,GACd,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,EACN,WAAW,EACX,WAAW,EACX,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,WAAW,GACX,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACN,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,UAAU,EACV,eAAe,EACf,kBAAkB,EAClB,aAAa,EACb,aAAa,GACb,MAAM,kBAAkB,CAAC;AAE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,EACN,QAAQ,EACR,iBAAiB,EACjB,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,WAAW,GACX,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EACN,kBAAkB,IAAI,iBAAiB,EACvC,OAAO,EACP,aAAa,EACb,YAAY,IAAI,iBAAiB,EACjC,QAAQ,EACR,MAAM,EACN,aAAa,EACb,aAAa,IAAI,kBAAkB,EACnC,OAAO,EACP,UAAU,EACV,MAAM,EACN,MAAM,IAAI,YAAY,EACtB,KAAK,EACL,gBAAgB,EAChB,QAAQ,EACR,aAAa,IAAI,aAAa,EAC9B,gBAAgB,EAChB,SAAS,EACT,QAAQ,EACR,QAAQ,IAAI,mBAAmB,EAC/B,kBAAkB,EAClB,KAAK,EACL,YAAY,EACZ,MAAM,IAAI,WAAW,EACrB,KAAK,IAAI,UAAU,EACnB,gBAAgB,IAAI,aAAa,EACjC,KAAK,IAAI,UAAU,GACnB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EACN,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,OAAO,EACP,YAAY,EACZ,aAAa,EACb,aAAa,IAAI,iBAAiB,EAClC,WAAW,EACX,MAAM,EACN,aAAa,IAAI,SAAS,EAC1B,aAAa,IAAI,iBAAiB,EAClC,eAAe,EACf,aAAa,EACb,KAAK,EACL,MAAM,EACN,OAAO,IAAI,YAAY,EACvB,KAAK,IAAI,UAAU,GACnB,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -5,9 +5,10 @@ export { isCamelCase, isEmojiOnly, isKebabCase, isPalindrome, isPascalCase, isSn
|
|
|
5
5
|
export { convertStringCase, extractEmails, extractURLs, maskString, normalizeString, replaceAllInString, reverseString, slugifyString, } from './string/convert';
|
|
6
6
|
export { extractNumbersFromString, getLevenshteinDistance, getLevenshteinDistance as levenshteinDistance, } from './string/utilities';
|
|
7
7
|
// ! Number Utilities
|
|
8
|
-
export { calculateHCF as calculateGCD, calculateHCF, calculateLCM as calculateLCD, calculateLCM, convertToDecimal, getFibonacciSeries as getFibonacci, getFibonacciSeries as getFibonacciNumbers, getFibonacciSeries, getRandomNumber,
|
|
8
|
+
export { calculateHCF as calculateGCD, calculateHCF, calculateLCM as calculateLCD, calculateLCM, convertToDecimal, getFibonacciSeries as getFibonacci, getFibonacciSeries as getFibonacciNumbers, getFibonacciSeries, getRandomNumber, sumNumbers as getSumOfNumbers, reverseNumber, sumDigits, sumNumbers, sumNumbers as sumOfNumbers, } from './number/basics';
|
|
9
|
+
export { isEven, isEven as isEvenNumber, isFibonacci, isMultiple, isOdd, isOdd as isOddNumber, isFibonacci as isParOfFibonacci, isFibonacci as isParOfFibonacciSeries, isPerfectSquare, } from './number/guards';
|
|
9
10
|
export { numberToWords as convertNumberToWords, convertToRomanNumerals, numberToWords, } from './number/convert';
|
|
10
|
-
export { findPrimeNumbers, isPrime, isPrime as isPrimeNumber, } from './number/prime';
|
|
11
|
+
export { findPrimeNumbers, findPrimeNumbers as getPrimeNumbers, isPrime, isPrime as isPrimeNumber, } from './number/prime';
|
|
11
12
|
export { clampNumber, formatCurrency as convertNumberToCurrency, formatCurrency, getRandomFloat as getRandomDecimal, getRandomFloat, roundToNearest as roundNumber, roundToNearest as roundNumberToNearestInterval, roundToNearest, roundToNearest as roundToNearestInterval, } from './number/utilities';
|
|
12
13
|
export { getNumbersInRange } from './number/range';
|
|
13
14
|
// ! Color Utilities
|
|
@@ -15,6 +16,10 @@ export { getColorForInitial } from './colors/initials';
|
|
|
15
16
|
export { generateRandomColorInHexRGB, generateRandomHSLColor, } from './colors/random';
|
|
16
17
|
export { convertColorCode, convertHex8ToHsla, convertHex8ToRgba, convertHexToHsl, convertHexToRgb, convertHslaToHex8, convertHslaToRgba, convertHslToHex, convertHslToRgb, convertRgbaToHex8, convertRgbaToHsla, convertRgbToHex, convertRgbToHsl, convertRgbToRgba, } from './colors/convert';
|
|
17
18
|
export { Color, Color as Colour } from './colors/Color';
|
|
19
|
+
// ! Date & Time Utilities
|
|
20
|
+
export { getGreeting as generateGreeting, getGreeting, getGreeting as greet, } from './date/greet';
|
|
21
|
+
export { isValidTime, isValidTime as isValidTimeString } from './date/guards';
|
|
22
|
+
export { extractHourMinute, getTotalMinutes } from './date/utils';
|
|
18
23
|
// ! Array Utilities
|
|
19
24
|
export { filterArrayOfObjects, flattenArray, getLastArrayElement, isInvalidOrEmptyArray, isInvalidOrEmptyArray as isValidEmptyArray, shuffleArray, } from './array/basics';
|
|
20
25
|
export { sortAnArray } from './array/sort';
|
package/dist/number/basics.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Numeric } from '../types';
|
|
1
2
|
import type { ConvertedDecimal, DecimalOptions, RandomNumberOptions } from './types';
|
|
2
3
|
/**
|
|
3
4
|
* * Utility to generate a random number between a given range.
|
|
@@ -15,7 +16,7 @@ export declare const getRandomNumber: (options?: RandomNumberOptions) => number;
|
|
|
15
16
|
* @param options - Options for rounding behavior, including decimal places and return type.
|
|
16
17
|
* @returns Converted number as `number` (default) or `string` (if `isString` is `true`).
|
|
17
18
|
*/
|
|
18
|
-
export declare const convertToDecimal: <T extends boolean | undefined = false>(input:
|
|
19
|
+
export declare const convertToDecimal: <T extends boolean | undefined = false>(input: Numeric, options?: DecimalOptions<T>) => ConvertedDecimal<T>;
|
|
19
20
|
/**
|
|
20
21
|
* * Calculates the HCF/GCD of multiple numbers.
|
|
21
22
|
*
|
|
@@ -30,42 +31,6 @@ export declare const calculateHCF: (...numbers: number[]) => number;
|
|
|
30
31
|
* @returns The LCM/LCD of all the provided numbers.
|
|
31
32
|
*/
|
|
32
33
|
export declare const calculateLCM: (...numbers: number[]) => number;
|
|
33
|
-
/**
|
|
34
|
-
* * Check if a number is even or not.
|
|
35
|
-
*
|
|
36
|
-
* @param input The number to check.
|
|
37
|
-
* @returns Boolean: `true` if even and `false` if not even.
|
|
38
|
-
*/
|
|
39
|
-
export declare const isEven: (input: number) => boolean;
|
|
40
|
-
/**
|
|
41
|
-
* * Checks if a number is odd or not.
|
|
42
|
-
*
|
|
43
|
-
* @param input The number to check.
|
|
44
|
-
* @returns Boolean: `true` if odd and `false` if not odd.
|
|
45
|
-
*/
|
|
46
|
-
export declare const isOdd: (input: number) => boolean;
|
|
47
|
-
/**
|
|
48
|
-
* * Checks if a number is a multiple of another number.
|
|
49
|
-
*
|
|
50
|
-
* @param input - The number to check.
|
|
51
|
-
* @param multipleOf - The number to check against.
|
|
52
|
-
* @returns `true` if `input` is a multiple of `multipleOf`, otherwise `false`.
|
|
53
|
-
*/
|
|
54
|
-
export declare const isMultiple: (input: number, multipleOf: number) => boolean;
|
|
55
|
-
/**
|
|
56
|
-
* * Checks if a number is a perfect square.
|
|
57
|
-
*
|
|
58
|
-
* @param num The number to check.
|
|
59
|
-
* @returns `true` if the number is a perfect square, otherwise `false`.
|
|
60
|
-
*/
|
|
61
|
-
export declare function isPerfectSquare(num: number): boolean;
|
|
62
|
-
/**
|
|
63
|
-
* * Checks if a number is part of the Fibonacci sequence.
|
|
64
|
-
*
|
|
65
|
-
* @param num The number to check.
|
|
66
|
-
* @returns `true` if the number is a Fibonacci number, otherwise `false`.
|
|
67
|
-
*/
|
|
68
|
-
export declare function isFibonacci(num: number): boolean;
|
|
69
34
|
/**
|
|
70
35
|
* * Generates the first `n` Fibonacci numbers.
|
|
71
36
|
*
|
|
@@ -79,12 +44,19 @@ export declare function getFibonacciSeries(n: number): number[];
|
|
|
79
44
|
* @param num The input number.
|
|
80
45
|
* @returns The sum of its digits.
|
|
81
46
|
*/
|
|
82
|
-
export declare function sumDigits(num:
|
|
47
|
+
export declare function sumDigits(num: Numeric): number;
|
|
48
|
+
/**
|
|
49
|
+
* * Sums up numbers.
|
|
50
|
+
*
|
|
51
|
+
* @param numbers The input numbers.
|
|
52
|
+
* @returns The sum of the numbers.
|
|
53
|
+
*/
|
|
54
|
+
export declare function sumNumbers(...numbers: Numeric[]): number;
|
|
83
55
|
/**
|
|
84
56
|
* * Reverses a number (e.g., `123` → `321`).
|
|
85
57
|
*
|
|
86
58
|
* @param num The number to reverse.
|
|
87
59
|
* @returns The reversed number.
|
|
88
60
|
*/
|
|
89
|
-
export declare function reverseNumber(num:
|
|
61
|
+
export declare function reverseNumber(num: Numeric): number;
|
|
90
62
|
//# sourceMappingURL=basics.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"basics.d.ts","sourceRoot":"","sources":["../../src/number/basics.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"basics.d.ts","sourceRoot":"","sources":["../../src/number/basics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAExC,OAAO,KAAK,EACX,gBAAgB,EAChB,cAAc,EACd,mBAAmB,EACnB,MAAM,SAAS,CAAC;AAEjB;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,aAAc,mBAAmB,KAAG,MA+C/D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,OAAO,GAAG,SAAS,iBACtD,OAAO,YACJ,cAAc,CAAC,CAAC,CAAC,KACzB,gBAAgB,CAAC,CAAC,CAQpB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,eAAgB,MAAM,EAAE,KAAG,MAQnD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,eAAgB,MAAM,EAAE,KAAG,MAQnD,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAQtD;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAK9C;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,OAAO,EAAE,OAAO,EAAE,GAAG,MAAM,CAIxD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAOlD"}
|
package/dist/number/basics.js
CHANGED
|
@@ -80,52 +80,6 @@ export const calculateLCM = (...numbers) => {
|
|
|
80
80
|
}
|
|
81
81
|
return lcm;
|
|
82
82
|
};
|
|
83
|
-
/**
|
|
84
|
-
* * Check if a number is even or not.
|
|
85
|
-
*
|
|
86
|
-
* @param input The number to check.
|
|
87
|
-
* @returns Boolean: `true` if even and `false` if not even.
|
|
88
|
-
*/
|
|
89
|
-
export const isEven = (input) => {
|
|
90
|
-
return input % 2 === 0;
|
|
91
|
-
};
|
|
92
|
-
/**
|
|
93
|
-
* * Checks if a number is odd or not.
|
|
94
|
-
*
|
|
95
|
-
* @param input The number to check.
|
|
96
|
-
* @returns Boolean: `true` if odd and `false` if not odd.
|
|
97
|
-
*/
|
|
98
|
-
export const isOdd = (input) => {
|
|
99
|
-
return input % 2 !== 0;
|
|
100
|
-
};
|
|
101
|
-
/**
|
|
102
|
-
* * Checks if a number is a multiple of another number.
|
|
103
|
-
*
|
|
104
|
-
* @param input - The number to check.
|
|
105
|
-
* @param multipleOf - The number to check against.
|
|
106
|
-
* @returns `true` if `input` is a multiple of `multipleOf`, otherwise `false`.
|
|
107
|
-
*/
|
|
108
|
-
export const isMultiple = (input, multipleOf) => {
|
|
109
|
-
return input % multipleOf === 0;
|
|
110
|
-
};
|
|
111
|
-
/**
|
|
112
|
-
* * Checks if a number is a perfect square.
|
|
113
|
-
*
|
|
114
|
-
* @param num The number to check.
|
|
115
|
-
* @returns `true` if the number is a perfect square, otherwise `false`.
|
|
116
|
-
*/
|
|
117
|
-
export function isPerfectSquare(num) {
|
|
118
|
-
return Number.isInteger(Math.sqrt(num));
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* * Checks if a number is part of the Fibonacci sequence.
|
|
122
|
-
*
|
|
123
|
-
* @param num The number to check.
|
|
124
|
-
* @returns `true` if the number is a Fibonacci number, otherwise `false`.
|
|
125
|
-
*/
|
|
126
|
-
export function isFibonacci(num) {
|
|
127
|
-
return (isPerfectSquare(5 * num * num + 4) || isPerfectSquare(5 * num * num - 4));
|
|
128
|
-
}
|
|
129
83
|
/**
|
|
130
84
|
* * Generates the first `n` Fibonacci numbers.
|
|
131
85
|
*
|
|
@@ -146,11 +100,22 @@ export function getFibonacciSeries(n) {
|
|
|
146
100
|
* @returns The sum of its digits.
|
|
147
101
|
*/
|
|
148
102
|
export function sumDigits(num) {
|
|
149
|
-
return Math.abs(num)
|
|
103
|
+
return Math.abs(Number(num))
|
|
150
104
|
.toString()
|
|
151
105
|
.split('')
|
|
152
106
|
.reduce((sum, digit) => sum + Number(digit), 0);
|
|
153
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* * Sums up numbers.
|
|
110
|
+
*
|
|
111
|
+
* @param numbers The input numbers.
|
|
112
|
+
* @returns The sum of the numbers.
|
|
113
|
+
*/
|
|
114
|
+
export function sumNumbers(...numbers) {
|
|
115
|
+
return numbers
|
|
116
|
+
.map((num) => Number(num))
|
|
117
|
+
.reduce((sum, number) => sum + number, 0);
|
|
118
|
+
}
|
|
154
119
|
/**
|
|
155
120
|
* * Reverses a number (e.g., `123` → `321`).
|
|
156
121
|
*
|
|
@@ -158,6 +123,6 @@ export function sumDigits(num) {
|
|
|
158
123
|
* @returns The reversed number.
|
|
159
124
|
*/
|
|
160
125
|
export function reverseNumber(num) {
|
|
161
|
-
const reversed = parseInt(Math.abs(num).toString().split('').reverse().join(''), 10);
|
|
162
|
-
return num < 0 ? -reversed : reversed;
|
|
126
|
+
const reversed = parseInt(Math.abs(Number(num)).toString().split('').reverse().join(''), 10);
|
|
127
|
+
return Number(num) < 0 ? -reversed : reversed;
|
|
163
128
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* * Check if a number is even or not.
|
|
3
|
+
*
|
|
4
|
+
* @param input The number to check.
|
|
5
|
+
* @returns Boolean: `true` if even and `false` if not even.
|
|
6
|
+
*/
|
|
7
|
+
export declare const isEven: (input: number) => boolean;
|
|
8
|
+
/**
|
|
9
|
+
* * Checks if a number is odd or not.
|
|
10
|
+
*
|
|
11
|
+
* @param input The number to check.
|
|
12
|
+
* @returns Boolean: `true` if odd and `false` if not odd.
|
|
13
|
+
*/
|
|
14
|
+
export declare const isOdd: (input: number) => boolean;
|
|
15
|
+
/**
|
|
16
|
+
* * Checks if a number is a multiple of another number.
|
|
17
|
+
*
|
|
18
|
+
* @param input - The number to check.
|
|
19
|
+
* @param multipleOf - The number to check against.
|
|
20
|
+
* @returns `true` if `input` is a multiple of `multipleOf`, otherwise `false`.
|
|
21
|
+
*/
|
|
22
|
+
export declare const isMultiple: (input: number, multipleOf: number) => boolean;
|
|
23
|
+
/**
|
|
24
|
+
* * Checks if a number is a perfect square.
|
|
25
|
+
*
|
|
26
|
+
* @param num The number to check.
|
|
27
|
+
* @returns `true` if the number is a perfect square, otherwise `false`.
|
|
28
|
+
*/
|
|
29
|
+
export declare function isPerfectSquare(num: number): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* * Checks if a number is part of the Fibonacci sequence.
|
|
32
|
+
*
|
|
33
|
+
* @param num The number to check.
|
|
34
|
+
* @returns `true` if the number is a Fibonacci number, otherwise `false`.
|
|
35
|
+
*/
|
|
36
|
+
export declare function isFibonacci(num: number): boolean;
|
|
37
|
+
//# sourceMappingURL=guards.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../../src/number/guards.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,MAAM,UAAW,MAAM,KAAG,OAEtC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,KAAK,UAAW,MAAM,KAAG,OAErC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,UAAW,MAAM,cAAc,MAAM,KAAG,OAE9D,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAIhD"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* * Check if a number is even or not.
|
|
3
|
+
*
|
|
4
|
+
* @param input The number to check.
|
|
5
|
+
* @returns Boolean: `true` if even and `false` if not even.
|
|
6
|
+
*/
|
|
7
|
+
export const isEven = (input) => {
|
|
8
|
+
return input % 2 === 0;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* * Checks if a number is odd or not.
|
|
12
|
+
*
|
|
13
|
+
* @param input The number to check.
|
|
14
|
+
* @returns Boolean: `true` if odd and `false` if not odd.
|
|
15
|
+
*/
|
|
16
|
+
export const isOdd = (input) => {
|
|
17
|
+
return input % 2 !== 0;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* * Checks if a number is a multiple of another number.
|
|
21
|
+
*
|
|
22
|
+
* @param input - The number to check.
|
|
23
|
+
* @param multipleOf - The number to check against.
|
|
24
|
+
* @returns `true` if `input` is a multiple of `multipleOf`, otherwise `false`.
|
|
25
|
+
*/
|
|
26
|
+
export const isMultiple = (input, multipleOf) => {
|
|
27
|
+
return input % multipleOf === 0;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* * Checks if a number is a perfect square.
|
|
31
|
+
*
|
|
32
|
+
* @param num The number to check.
|
|
33
|
+
* @returns `true` if the number is a perfect square, otherwise `false`.
|
|
34
|
+
*/
|
|
35
|
+
export function isPerfectSquare(num) {
|
|
36
|
+
return Number.isInteger(Math.sqrt(num));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* * Checks if a number is part of the Fibonacci sequence.
|
|
40
|
+
*
|
|
41
|
+
* @param num The number to check.
|
|
42
|
+
* @returns `true` if the number is a Fibonacci number, otherwise `false`.
|
|
43
|
+
*/
|
|
44
|
+
export function isFibonacci(num) {
|
|
45
|
+
return (isPerfectSquare(5 * num * num + 4) || isPerfectSquare(5 * num * num - 4));
|
|
46
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"range.d.ts","sourceRoot":"","sources":["../../src/number/range.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"range.d.ts","sourceRoot":"","sources":["../../src/number/range.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE9E;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,KAAK,EAChD,IAAI,GAAE,UAAkB,EACxB,OAAO,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,GACvB,aAAa,CAAC,CAAC,CAAC,CA2FlB"}
|
package/dist/number/range.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { shuffleArray } from '../array/basics';
|
|
2
2
|
import { convertArrayToString } from '../utils';
|
|
3
|
-
import { getRandomNumber
|
|
3
|
+
import { getRandomNumber } from './basics';
|
|
4
|
+
import { isEven, isOdd } from './guards';
|
|
4
5
|
import { _applyMultiples } from './helpers';
|
|
5
6
|
import { isPrime } from './prime';
|
|
6
7
|
/**
|
package/dist/types/index.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ export type FlattenPartial<T> = Partial<{
|
|
|
11
11
|
[K in keyof T]: T[K];
|
|
12
12
|
}>;
|
|
13
13
|
/** Utility type to flatten Partial type */
|
|
14
|
+
/** Union of `number` and numeric string */
|
|
15
|
+
export type Numeric = number | `${number}`;
|
|
14
16
|
/** Union of Primitive Types */
|
|
15
17
|
export type Primitive = string | number | boolean | null | undefined;
|
|
16
18
|
/** Extract primitive key(s) from an object */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,MAAM,MAAM,eAAe,GAAG,GAAG,CAAC;AAElC,OAA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