Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,6 @@ jobs:
- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build project
run: pnpm run build

- name: Bump version
id: version
shell: bash
Expand Down Expand Up @@ -153,6 +150,9 @@ jobs:

echo "✅ Version bumped to $NEW_VERSION"

- name: Build project
run: pnpm run build

- name: Run coherency checks
run: pnpm coherency

Expand Down
10 changes: 4 additions & 6 deletions .template/category/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
"types": "./lib/index.d.ts",
"import": "./lib/index.js"
},
"./examples.json": "./examples.json",
"./api.json": "./api.json",
"./licenses.json": "./licenses.json",
"./meta/api.json": "./meta/api.json",
"./meta/examples.json": "./meta/examples.json",
"./meta/licenses.json": "./meta/licenses.json",
"./package.json": "./package.json"
},
"keywords": [
Expand All @@ -31,9 +31,7 @@
"lib/index.js",
"lib/index.d.ts",
"lib/index.js.map",
"examples.json",
"api.json",
"licenses.json",
"meta/",
"LICENSE.md",
"package.json",
"README.md"
Expand Down
1 change: 1 addition & 0 deletions helpers/array/arrayEquals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { isArray, isObject } from "radashi";
* @param arr1 One list
* @param arr2 Another list
* @returns `true` if the list contain the same items, `false` otherwise.
* @since 1.0.0
*/
export function arrayEquals<T>(arr1: T[], arr2: T[]): boolean {
return arr1.length === arr2.length && arr1.every((v1) => arr2.some((v2) => {
Expand Down
1 change: 1 addition & 0 deletions helpers/array/chunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* @param array - The array to chunk
* @param size - The size of each chunk
* @returns Array of chunks
* @since 1.9.0
*/
export function chunk<T>(array: T[], size: number): T[][] {
if (size <= 0) return [];
Expand Down
1 change: 1 addition & 0 deletions helpers/array/deepCompare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @param arrA - First array to compare
* @param arrB - Second array to compare
* @returns `true` if arrays are deeply equal, `false` otherwise
* @since 2.0.0
*/
export function deepCompare<T>(arrA: T[], arrB: T[]): boolean {
// Quick reference equality check
Expand Down
1 change: 1 addition & 0 deletions helpers/array/difference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* @param array1 - First array
* @param array2 - Second array
* @returns Array with items from first array not present in second array
* @since 1.9.0
*/
export function difference<T>(array1: T[], array2: T[]): T[] {
const set2 = new Set(array2);
Expand Down
1 change: 1 addition & 0 deletions helpers/array/intersection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* @param a First array
* @param b Second array
* @returns The intersection of the two arrays
* @since 1.0.0
*/
export function intersection<T>(a: readonly T[], b: readonly T[]): T[] {
return a.filter((v) => b.includes(v));
Expand Down
1 change: 1 addition & 0 deletions helpers/array/oneInCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* @param a One list
* @param b Another list
* @returns `true` if one item is in common, `false` otherwise.
* @since 1.0.0
*/
export function oneInCommon<T>(a: readonly T[], b: readonly T[]): boolean {
return a.some((i) => b.includes(i));
Expand Down
1 change: 1 addition & 0 deletions helpers/array/quickCompare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* @param arrA - First array to compare
* @param arrB - Second array to compare
* @returns `true` if arrays are identical according to JSON.stringify, `false` otherwise
* @since 2.0.0
*/
export function quickCompare<T>(arrA: T[], arrB: T[]): boolean {
try {
Expand Down
9 changes: 9 additions & 0 deletions helpers/array/sort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

/**
* Sort function type for arrays
* @since 1.9.0
*/
export type SortFn<T> = (a: T, b: T) => number;

Expand All @@ -14,6 +15,7 @@ export type SortFn<T> = (a: T, b: T) => number;
* @param a - First number
* @param b - Second number
* @returns Sort order
* @since 1.9.0
*/
export const sortNumberAscFn: SortFn<number> = (a: number, b: number) => a - b;

Expand All @@ -22,6 +24,7 @@ export const sortNumberAscFn: SortFn<number> = (a: number, b: number) => a - b;
* @param a - First number
* @param b - Second number
* @returns Sort order
* @since 1.9.0
*/
export const sortNumberDescFn: SortFn<number> = (a: number, b: number) => b - a;

Expand All @@ -30,6 +33,7 @@ export const sortNumberDescFn: SortFn<number> = (a: number, b: number) => b - a;
* @param a - First string
* @param b - Second string
* @returns Sort order
* @since 1.9.0
*/
export const sortStringAscFn: SortFn<string> = (a: string, b: string) => a.localeCompare(b);

Expand All @@ -38,6 +42,7 @@ export const sortStringAscFn: SortFn<string> = (a: string, b: string) => a.local
* @param a - First string
* @param b - Second string
* @returns Sort order
* @since 1.9.0
*/
export const sortStringDescFn: SortFn<string> = (a: string, b: string) => b.localeCompare(a);

Expand All @@ -46,6 +51,7 @@ export const sortStringDescFn: SortFn<string> = (a: string, b: string) => b.loca
* @param a - First string
* @param b - Second string
* @returns Sort order
* @since 1.9.0
*/
export const sortStringAscInsensitiveFn: SortFn<string> = (a: string, b: string) =>
a.toLowerCase().localeCompare(b.toLowerCase());
Expand All @@ -55,6 +61,7 @@ export const sortStringAscInsensitiveFn: SortFn<string> = (a: string, b: string)
* @param property - The property to sort by (defaults to trying 'value', 'label', 'title', 'description')
* @param caseInsensitive - Whether to ignore case
* @returns Sort function
* @since 1.9.0
*/
export function createSortByStringFn<T extends Record<string, any>>(
property?: keyof T,
Expand Down Expand Up @@ -88,6 +95,7 @@ export function createSortByStringFn<T extends Record<string, any>>(
* Creates a sort function for objects by number property
* @param property - The property to sort by (defaults to 'value')
* @returns Sort function
* @since 1.9.0
*/
export function createSortByNumberFn<T extends Record<string, any>>(
property?: keyof T
Expand All @@ -104,6 +112,7 @@ export function createSortByNumberFn<T extends Record<string, any>>(
* Creates a sort function for objects by date property
* @param property - The property to sort by (defaults to 'date')
* @returns Sort function
* @since 1.9.0
*/
export function createSortByDateFn<T extends Record<string, any>>(
property?: keyof T
Expand Down
1 change: 1 addition & 0 deletions helpers/array/unique.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Removes duplicate values from an array
* @param array - The array to remove duplicates from
* @returns New array with unique values only
* @since 1.9.0
*/
export function unique<T>(array: T[]): T[] {
return Array.from(new Set(array));
Expand Down
2 changes: 2 additions & 0 deletions helpers/date/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

/**
* Options for date comparison
* @since 2.0.0
*/
export interface DateCompareOptions {
/**
Expand All @@ -26,6 +27,7 @@ export interface DateCompareOptions {
* @param dateB - Second date to compare
* @param options - Comparison options
* @returns `true` if dates are identical according to the specified precision, `false` otherwise
* @since 2.0.0
*/
export function compare(dateA: Date, dateB: Date, options: DateCompareOptions = {}): boolean {
const { precision = 'milliseconds' } = options;
Expand Down
1 change: 1 addition & 0 deletions helpers/date/difference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* @param date1 - First date
* @param date2 - Second date
* @returns Number of days difference
* @since 2.0.0
*/
export function daysDifference(date1: Date, date2: Date): number {
const oneDay = 24 * 60 * 60 * 1000;
Expand Down
3 changes: 3 additions & 0 deletions helpers/date/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { safeDate } from './safeDate';
* @example
* toISO8601(new Date('2025-01-19T12:30:00Z')) // '2025-01-19T12:30:00.000Z'
* toISO8601(1737290400000) // '2025-01-19T12:00:00.000Z'
* @since 2.0.0
*/
export function toISO8601(date: Date | number | string): string | null {
const d = safeDate(date);
Expand All @@ -31,6 +32,7 @@ export function toISO8601(date: Date | number | string): string | null {
* @example
* toRFC3339(new Date('2025-01-19T12:30:45.123Z')) // '2025-01-19T12:30:45Z'
* toRFC3339(new Date('2025-01-19T12:30:45.123Z'), true) // '2025-01-19T12:30:45.123Z'
* @since 2.0.0
*/
export function toRFC3339(
date: Date | number | string,
Expand All @@ -55,6 +57,7 @@ export function toRFC3339(
* @returns RFC 2822 formatted string or null if invalid date
* @example
* toRFC2822(new Date('2025-01-19T12:30:00Z')) // 'Sun, 19 Jan 2025 12:30:00 +0000'
* @since 2.0.0
*/
export function toRFC2822(date: Date | number | string): string | null {
const d = safeDate(date);
Expand Down
1 change: 1 addition & 0 deletions helpers/date/is.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* @param date1 - First date
* @param date2 - Second date
* @returns True if same day
* @since 2.0.0
*/
export function isSameDay(date1: Date, date2: Date): boolean {
return (
Expand Down
2 changes: 2 additions & 0 deletions helpers/date/safeDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { normalizeTimestamp } from './timestamp';
* Safely creates a Date object from various input types
* @param input - String, number, or Date input
* @returns Valid Date object or null if invalid
* @since 1.9.0
*/
export function safeDate(input: string | number | Date | null | undefined): Date | null {
if (input === null || input === undefined || input === '' || input === 0) {
Expand Down Expand Up @@ -40,6 +41,7 @@ export function safeDate(input: string | number | Date | null | undefined): Date
* Formats a date to ISO string or returns null
* @param input - Date input
* @returns ISO string or null
* @since 1.9.0
*/
export function dateToISOString(input: string | number | Date | null | undefined): string | null {
const date = safeDate(input);
Expand Down
2 changes: 2 additions & 0 deletions helpers/date/timestamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Checks if a timestamp is likely in seconds (Java/Unix style) vs milliseconds (JavaScript style)
* @param timestamp - The timestamp to check
* @returns True if timestamp appears to be in seconds
* @since 1.9.0
*/
export function isTimestampInSeconds(timestamp: number): boolean {
// Timestamps before year 2001 in milliseconds are less than 10^10
Expand All @@ -18,6 +19,7 @@ export function isTimestampInSeconds(timestamp: number): boolean {
* Converts a timestamp to JavaScript milliseconds format
* @param timestamp - The timestamp (in seconds or milliseconds)
* @returns Timestamp in milliseconds
* @since 1.9.0
*/
export function normalizeTimestamp(timestamp: number): number {
return isTimestampInSeconds(timestamp) ? timestamp * 1000 : timestamp;
Expand Down
1 change: 1 addition & 0 deletions helpers/function/debounce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* @param func - The function to debounce
* @param delay - The number of milliseconds to delay
* @returns The debounced function
* @since 1.9.0
*/
export function debounce<T extends (...args: any[]) => any>(
func: T,
Expand Down
1 change: 1 addition & 0 deletions helpers/function/isDefinedAndNotNull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/**
* Check if a given value of unknown data type is defined and not null
* @param value
* @since 1.0.0
*/
export function isDefinedAndNotNull<T>(value: T | undefined | null): boolean {
return value !== undefined && value !== null;
Expand Down
1 change: 1 addition & 0 deletions helpers/function/memoize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Returns a memoized version of the function that caches results
* @param func - The function to memoize
* @returns The memoized function
* @since 1.9.0
*/
export function memoize<T extends (...args: any[]) => any>(func: T): T {
const cache = new Map<string, ReturnType<T>>();
Expand Down
1 change: 1 addition & 0 deletions helpers/function/returnOrThrowError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { isDefinedAndNotNull } from './isDefinedAndNotNull';
* @param value A possible non-defined value.
* @param error The error message to throw.
* @returns A defined value or an error.
* @since 1.0.0
*/
export function returnOrThrowError<T>(value: T | undefined | null, error: string): T {
if (isDefinedAndNotNull(value)) {
Expand Down
1 change: 1 addition & 0 deletions helpers/function/throttle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* @param func - The function to throttle
* @param wait - The number of milliseconds to throttle invocations to
* @returns The throttled function
* @since 1.9.0
*/
export function throttle<T extends (...args: any[]) => any>(
func: T,
Expand Down
1 change: 1 addition & 0 deletions helpers/number/clamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* @param min - Minimum value
* @param max - Maximum value
* @returns Clamped value
* @since 1.9.0
*/
export function clamp(value: number, min: number, max: number): number {
return Math.min(Math.max(value, min), max);
Expand Down
2 changes: 2 additions & 0 deletions helpers/number/random.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* @param min - Minimum value
* @param max - Maximum value
* @returns Random number between min and max
* @since 1.9.0
*/
export function randomBetween(min: number, max: number): number {
return Math.random() * (max - min) + min;
Expand All @@ -19,6 +20,7 @@ export function randomBetween(min: number, max: number): number {
* @param min - Minimum value
* @param max - Maximum value
* @returns Random integer between min and max
* @since 1.9.0
*/
export function randomIntBetween(min: number, max: number): number {
return Math.floor(Math.random() * (max - min + 1)) + min;
Expand Down
1 change: 1 addition & 0 deletions helpers/number/roundTo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* @param value - The number to round
* @param decimals - Number of decimal places
* @returns Rounded number
* @since 1.9.0
*/
export function roundTo(value: number, decimals: number): number {
const multiplier = Math.pow(10, decimals);
Expand Down
1 change: 1 addition & 0 deletions helpers/object/deepClone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Creates a deep copy of an object or array
* @param obj - The object to clone
* @returns Deep cloned object
* @since 1.9.0
*/
export function deepClone<T>(obj: T): T {
if (obj === null || typeof obj !== "object") {
Expand Down
2 changes: 2 additions & 0 deletions helpers/object/deepCompare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { isSpecialObject } from '../type/isSpecialObject';

/**
* Result type for deep comparison when objects are not identical
* @since 2.0.0
*/
export interface DeepCompareResult {
[key: string]: "onlyA" | "onlyB" | false | DeepCompareResult;
Expand All @@ -21,6 +22,7 @@ export interface DeepCompareResult {
* @param objA - First object to compare (can be object, undefined, or null)
* @param objB - Second object to compare (can be object, undefined, or null)
* @returns `true` if objects are identical, `false` if incompatible types, or a `DeepCompareResult` object detailing differences
* @since 2.0.0
*/
export function deepCompare(objA: object | undefined | null, objB: object | undefined | null): true | false | DeepCompareResult {
// Quick reference equality check
Expand Down
1 change: 1 addition & 0 deletions helpers/object/deepMerge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* @param target - The target object
* @param sources - The source objects to merge
* @returns The merged object
* @since 1.9.0
*/
export function deepMerge<T extends Record<string, any>>(target: T, ...sources: Record<string, any>[]): T {
if (!sources.length) return target;
Expand Down
1 change: 1 addition & 0 deletions helpers/object/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* @param path - The dot-notated path (e.g., 'a.b.c')
* @param defaultValue - Default value if path doesn't exist
* @returns The value at the path or default value
* @since 1.9.0
*/
export function get<T = any>(obj: any, path: string, defaultValue?: T): T | undefined {
const keys = path.split('.');
Expand Down
1 change: 1 addition & 0 deletions helpers/object/quickCompare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* @param objA - First object to compare
* @param objB - Second object to compare
* @returns `true` if objects are identical according to JSON.stringify, `false` otherwise
* @since 2.0.0
*/
export function quickCompare(objA: unknown, objB: unknown): boolean {
// Quick reference equality check
Expand Down
Loading
Loading