Comparing version 1.15.9 to 1.16.9
@@ -1,26 +0,24 @@ | ||
export declare namespace arrayUtils { | ||
/** | ||
* Filters an array based on a predicate function. | ||
* @param arr The array to filter. | ||
* @param predicate The predicate function used to filter elements. | ||
* @returns A new array containing only the elements that satisfy the predicate function. | ||
*/ | ||
function filterArray<T>(arr: T[], predicate: (element: T) => boolean): T[]; | ||
/** | ||
* Maps each element of an array to a new value using a transformation function. | ||
* @param arr The array to map. | ||
* @param mapper The transformation function to apply to each element. | ||
* @returns A new array containing the transformed elements. | ||
*/ | ||
function mapArray<T, U>(arr: T[], mapper: (element: T) => U): U[]; | ||
function binarySearch<T>(arr: T[], target: T): number; | ||
function quickSort<T>(arr: T[]): T[]; | ||
function quickSortDescending<T>(arr: T[]): T[]; | ||
function arrPush<T>(arr: T[], target: T): T[]; | ||
function arrUnshift<T>(arr: T[], target: T): T[]; | ||
function arrPop<T>(arr: T[]): T[]; | ||
function arrShift<T>(arr: T[]): T[]; | ||
function arrSlice<T>(arr: T[], start: number, end: number): T[]; | ||
function arrToUpperCase<T>(arr: T[]): T[]; | ||
function arrToLowerCase<T>(arr: T[]): T[]; | ||
} | ||
/** | ||
* Filters an array based on a predicate function. | ||
* @param arr The array to filter. | ||
* @param predicate The predicate function used to filter elements. | ||
* @returns A new array containing only the elements that satisfy the predicate function. | ||
*/ | ||
export declare function filterArray<T>(arr: T[], predicate: (element: T) => boolean): T[]; | ||
/** | ||
* Maps each element of an array to a new value using a transformation function. | ||
* @param arr The array to map. | ||
* @param mapper The transformation function to apply to each element. | ||
* @returns A new array containing the transformed elements. | ||
*/ | ||
export declare function mapArray<T, U>(arr: T[], mapper: (element: T) => U): U[]; | ||
export declare function binarySearch<T>(arr: T[], target: T): number; | ||
export declare function quickSort<T>(arr: T[]): T[]; | ||
export declare function quickSortDescending<T>(arr: T[]): T[]; | ||
export declare function arrPush<T>(arr: T[], target: T): T[]; | ||
export declare function arrUnshift<T>(arr: T[], target: T): T[]; | ||
export declare function arrPop<T>(arr: T[]): T[]; | ||
export declare function arrShift<T>(arr: T[]): T[]; | ||
export declare function arrSlice<T>(arr: T[], start: number, end: number): T[]; | ||
export declare function arrToUpperCase<T>(arr: T[]): T[]; | ||
export declare function arrToLowerCase<T>(arr: T[]): T[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.arrayUtils = void 0; | ||
var arrayUtils; | ||
(function (arrayUtils) { | ||
/** | ||
* Filters an array based on a predicate function. | ||
* @param arr The array to filter. | ||
* @param predicate The predicate function used to filter elements. | ||
* @returns A new array containing only the elements that satisfy the predicate function. | ||
*/ | ||
function filterArray(arr, predicate) { | ||
return arr.filter(predicate); | ||
} | ||
arrayUtils.filterArray = filterArray; | ||
/** | ||
* Maps each element of an array to a new value using a transformation function. | ||
* @param arr The array to map. | ||
* @param mapper The transformation function to apply to each element. | ||
* @returns A new array containing the transformed elements. | ||
*/ | ||
function mapArray(arr, mapper) { | ||
return arr.map(mapper); | ||
} | ||
arrayUtils.mapArray = mapArray; | ||
function binarySearch(arr, target) { | ||
let left = 0; | ||
let right = arr.length - 1; | ||
while (left <= right) { | ||
const mid = Math.floor((left + right) / 2); | ||
const midVal = arr[mid]; | ||
if (midVal === target) { | ||
return mid; | ||
} | ||
else if (midVal < target) { | ||
left = mid + 1; | ||
} | ||
else { | ||
right = mid - 1; | ||
} | ||
exports.arrToLowerCase = exports.arrToUpperCase = exports.arrSlice = exports.arrShift = exports.arrPop = exports.arrUnshift = exports.arrPush = exports.quickSortDescending = exports.quickSort = exports.binarySearch = exports.mapArray = exports.filterArray = void 0; | ||
// export module arrayUtils { | ||
/** | ||
* Filters an array based on a predicate function. | ||
* @param arr The array to filter. | ||
* @param predicate The predicate function used to filter elements. | ||
* @returns A new array containing only the elements that satisfy the predicate function. | ||
*/ | ||
function filterArray(arr, predicate) { | ||
return arr.filter(predicate); | ||
} | ||
exports.filterArray = filterArray; | ||
/** | ||
* Maps each element of an array to a new value using a transformation function. | ||
* @param arr The array to map. | ||
* @param mapper The transformation function to apply to each element. | ||
* @returns A new array containing the transformed elements. | ||
*/ | ||
function mapArray(arr, mapper) { | ||
return arr.map(mapper); | ||
} | ||
exports.mapArray = mapArray; | ||
function binarySearch(arr, target) { | ||
let left = 0; | ||
let right = arr.length - 1; | ||
while (left <= right) { | ||
const mid = Math.floor((left + right) / 2); | ||
const midVal = arr[mid]; | ||
if (midVal === target) { | ||
return mid; | ||
} | ||
return -1; // Element not found | ||
} | ||
arrayUtils.binarySearch = binarySearch; | ||
function quickSort(arr) { | ||
if (arr.length <= 1) { | ||
return arr; | ||
else if (midVal < target) { | ||
left = mid + 1; | ||
} | ||
const pivot = arr[0]; | ||
const left = []; | ||
const right = []; | ||
for (let i = 1; i < arr.length; i++) { | ||
if (arr[i] < pivot) { | ||
left.push(arr[i]); | ||
} | ||
else { | ||
right.push(arr[i]); | ||
} | ||
else { | ||
right = mid - 1; | ||
} | ||
return [...quickSort(left), pivot, ...quickSort(right)]; | ||
} | ||
arrayUtils.quickSort = quickSort; | ||
function quickSortDescending(arr) { | ||
if (arr.length <= 1) { | ||
return arr; | ||
return -1; // Element not found | ||
} | ||
exports.binarySearch = binarySearch; | ||
function quickSort(arr) { | ||
if (arr.length <= 1) { | ||
return arr; | ||
} | ||
const pivot = arr[0]; | ||
const left = []; | ||
const right = []; | ||
for (let i = 1; i < arr.length; i++) { | ||
if (arr[i] < pivot) { | ||
left.push(arr[i]); | ||
} | ||
const pivot = arr[0]; | ||
const left = []; | ||
const right = []; | ||
for (let i = 1; i < arr.length; i++) { | ||
if (arr[i] >= pivot) { // Modified condition for descending order | ||
left.push(arr[i]); | ||
} | ||
else { | ||
right.push(arr[i]); | ||
} | ||
else { | ||
right.push(arr[i]); | ||
} | ||
return [...quickSortDescending(left), pivot, ...quickSortDescending(right)]; // Recursively sort left and right arrays | ||
} | ||
arrayUtils.quickSortDescending = quickSortDescending; | ||
function arrPush(arr, target) { | ||
arr.push(target); | ||
return [...quickSort(left), pivot, ...quickSort(right)]; | ||
} | ||
exports.quickSort = quickSort; | ||
function quickSortDescending(arr) { | ||
if (arr.length <= 1) { | ||
return arr; | ||
} | ||
arrayUtils.arrPush = arrPush; | ||
function arrUnshift(arr, target) { | ||
arr.unshift(target); | ||
return arr; | ||
const pivot = arr[0]; | ||
const left = []; | ||
const right = []; | ||
for (let i = 1; i < arr.length; i++) { | ||
if (arr[i] >= pivot) { // Modified condition for descending order | ||
left.push(arr[i]); | ||
} | ||
else { | ||
right.push(arr[i]); | ||
} | ||
} | ||
arrayUtils.arrUnshift = arrUnshift; | ||
function arrPop(arr) { | ||
arr.pop(); | ||
return arr; | ||
} | ||
arrayUtils.arrPop = arrPop; | ||
function arrShift(arr) { | ||
arr.shift(); | ||
return arr; | ||
} | ||
arrayUtils.arrShift = arrShift; | ||
function arrSlice(arr, start, end) { | ||
arr.slice(start, end); | ||
return arr; | ||
} | ||
arrayUtils.arrSlice = arrSlice; | ||
function arrToUpperCase(arr) { | ||
// Create a new array to store the uppercase elements | ||
const upperCaseArray = []; | ||
// Iterate through the original array and convert each element to uppercase | ||
for (const element of arr) { | ||
// Check if the element is a string | ||
if (typeof element === 'string') { | ||
// If it's a string, convert it to uppercase and push to the new array | ||
upperCaseArray.push(element.toUpperCase()); | ||
} | ||
else { | ||
// If it's not a string, push it to the new array as is | ||
upperCaseArray.push(element); | ||
} | ||
return [...quickSortDescending(left), pivot, ...quickSortDescending(right)]; // Recursively sort left and right arrays | ||
} | ||
exports.quickSortDescending = quickSortDescending; | ||
function arrPush(arr, target) { | ||
arr.push(target); | ||
return arr; | ||
} | ||
exports.arrPush = arrPush; | ||
function arrUnshift(arr, target) { | ||
arr.unshift(target); | ||
return arr; | ||
} | ||
exports.arrUnshift = arrUnshift; | ||
function arrPop(arr) { | ||
arr.pop(); | ||
return arr; | ||
} | ||
exports.arrPop = arrPop; | ||
function arrShift(arr) { | ||
arr.shift(); | ||
return arr; | ||
} | ||
exports.arrShift = arrShift; | ||
function arrSlice(arr, start, end) { | ||
arr.slice(start, end); | ||
return arr; | ||
} | ||
exports.arrSlice = arrSlice; | ||
function arrToUpperCase(arr) { | ||
// Create a new array to store the uppercase elements | ||
const upperCaseArray = []; | ||
// Iterate through the original array and convert each element to uppercase | ||
for (const element of arr) { | ||
// Check if the element is a string | ||
if (typeof element === 'string') { | ||
// If it's a string, convert it to uppercase and push to the new array | ||
upperCaseArray.push(element.toUpperCase()); | ||
} | ||
// Return the array with all elements converted to uppercase | ||
return upperCaseArray; | ||
else { | ||
// If it's not a string, push it to the new array as is | ||
upperCaseArray.push(element); | ||
} | ||
} | ||
arrayUtils.arrToUpperCase = arrToUpperCase; | ||
function arrToLowerCase(arr) { | ||
// Create a new array to store the lowercase elements | ||
const lowerCaseArray = []; | ||
// Iterate through the original array and convert each element to lowercase | ||
for (const element of arr) { | ||
// Check if the element is a string | ||
if (typeof element === 'string') { | ||
// If it's a string, convert it to lowercase and push to the new array | ||
lowerCaseArray.push(element.toLowerCase()); | ||
} | ||
else { | ||
// If it's not a string, push it to the new array as is | ||
lowerCaseArray.push(element); | ||
} | ||
// Return the array with all elements converted to uppercase | ||
return upperCaseArray; | ||
} | ||
exports.arrToUpperCase = arrToUpperCase; | ||
function arrToLowerCase(arr) { | ||
// Create a new array to store the lowercase elements | ||
const lowerCaseArray = []; | ||
// Iterate through the original array and convert each element to lowercase | ||
for (const element of arr) { | ||
// Check if the element is a string | ||
if (typeof element === 'string') { | ||
// If it's a string, convert it to lowercase and push to the new array | ||
lowerCaseArray.push(element.toLowerCase()); | ||
} | ||
// Return the array with all elements converted to lowercase | ||
return lowerCaseArray; | ||
else { | ||
// If it's not a string, push it to the new array as is | ||
lowerCaseArray.push(element); | ||
} | ||
} | ||
arrayUtils.arrToLowerCase = arrToLowerCase; | ||
// Add more array utility functions here as needed... | ||
})(arrayUtils || (exports.arrayUtils = arrayUtils = {})); | ||
// Return the array with all elements converted to lowercase | ||
return lowerCaseArray; | ||
} | ||
exports.arrToLowerCase = arrToLowerCase; | ||
// Add more array utility functions here as needed... | ||
// } | ||
//# sourceMappingURL=arrayUtils.js.map |
@@ -1,27 +0,25 @@ | ||
export declare namespace dateUtils { | ||
/** | ||
* Format a date object as a string in the specified format. | ||
* @param date The date object to format. | ||
* @param format The format string (e.g., 'YYYY-MM-DD HH:mm:ss'). | ||
* @returns The formatted date string. | ||
*/ | ||
function formatDate(date: Date, format: string): string; | ||
/** | ||
* Get the current date and time formatted as a string in the specified format. | ||
* @param format The format string (e.g., 'YYYY-MM-DD HH:mm:ss'). | ||
* @returns The formatted current date and time string. | ||
*/ | ||
function getCurrentDateTime(format: string): string; | ||
/** | ||
* Parse a date string into a Date object. | ||
* @param dateString The date string to parse. | ||
* @returns The parsed Date object, or null if parsing fails. | ||
*/ | ||
function parseDate(dateString: string): Date | null; | ||
/** | ||
* Check if a given year is a leap year. | ||
* @param year The year to check. | ||
* @returns True if the year is a leap year, false otherwise. | ||
*/ | ||
function isLeapYear(year: number): boolean; | ||
} | ||
/** | ||
* Format a date object as a string in the specified format. | ||
* @param date The date object to format. | ||
* @param format The format string (e.g., 'YYYY-MM-DD HH:mm:ss'). | ||
* @returns The formatted date string. | ||
*/ | ||
export declare function formatDate(date: Date, format: string): string; | ||
/** | ||
* Get the current date and time formatted as a string in the specified format. | ||
* @param format The format string (e.g., 'YYYY-MM-DD HH:mm:ss'). | ||
* @returns The formatted current date and time string. | ||
*/ | ||
export declare function getCurrentDateTime(format: string): string; | ||
/** | ||
* Parse a date string into a Date object. | ||
* @param dateString The date string to parse. | ||
* @returns The parsed Date object, or null if parsing fails. | ||
*/ | ||
export declare function parseDate(dateString: string): Date | null; | ||
/** | ||
* Check if a given year is a leap year. | ||
* @param year The year to check. | ||
* @returns True if the year is a leap year, false otherwise. | ||
*/ | ||
export declare function isLeapYear(year: number): boolean; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.dateUtils = void 0; | ||
var dateUtils; | ||
(function (dateUtils) { | ||
/** | ||
* Format a date object as a string in the specified format. | ||
* @param date The date object to format. | ||
* @param format The format string (e.g., 'YYYY-MM-DD HH:mm:ss'). | ||
* @returns The formatted date string. | ||
*/ | ||
function formatDate(date, format) { | ||
const yyyy = date.getFullYear(); | ||
const mm = String(date.getMonth() + 1).padStart(2, '0'); | ||
const dd = String(date.getDate()).padStart(2, '0'); | ||
const hh = String(date.getHours()).padStart(2, '0'); | ||
const min = String(date.getMinutes()).padStart(2, '0'); | ||
const ss = String(date.getSeconds()).padStart(2, '0'); | ||
return format | ||
.replace('YYYY', String(yyyy)) | ||
.replace('MM', mm) | ||
.replace('DD', dd) | ||
.replace('HH', hh) | ||
.replace('mm', min) | ||
.replace('ss', ss); | ||
exports.isLeapYear = exports.parseDate = exports.getCurrentDateTime = exports.formatDate = void 0; | ||
// export module dateUtils { | ||
/** | ||
* Format a date object as a string in the specified format. | ||
* @param date The date object to format. | ||
* @param format The format string (e.g., 'YYYY-MM-DD HH:mm:ss'). | ||
* @returns The formatted date string. | ||
*/ | ||
function formatDate(date, format) { | ||
const yyyy = date.getFullYear(); | ||
const mm = String(date.getMonth() + 1).padStart(2, '0'); | ||
const dd = String(date.getDate()).padStart(2, '0'); | ||
const hh = String(date.getHours()).padStart(2, '0'); | ||
const min = String(date.getMinutes()).padStart(2, '0'); | ||
const ss = String(date.getSeconds()).padStart(2, '0'); | ||
return format | ||
.replace('YYYY', String(yyyy)) | ||
.replace('MM', mm) | ||
.replace('DD', dd) | ||
.replace('HH', hh) | ||
.replace('mm', min) | ||
.replace('ss', ss); | ||
} | ||
exports.formatDate = formatDate; | ||
/** | ||
* Get the current date and time formatted as a string in the specified format. | ||
* @param format The format string (e.g., 'YYYY-MM-DD HH:mm:ss'). | ||
* @returns The formatted current date and time string. | ||
*/ | ||
function getCurrentDateTime(format) { | ||
return formatDate(new Date(), format); | ||
} | ||
exports.getCurrentDateTime = getCurrentDateTime; | ||
/** | ||
* Parse a date string into a Date object. | ||
* @param dateString The date string to parse. | ||
* @returns The parsed Date object, or null if parsing fails. | ||
*/ | ||
function parseDate(dateString) { | ||
const timestamp = Date.parse(dateString); | ||
if (!isNaN(timestamp)) { | ||
return new Date(timestamp); | ||
} | ||
dateUtils.formatDate = formatDate; | ||
/** | ||
* Get the current date and time formatted as a string in the specified format. | ||
* @param format The format string (e.g., 'YYYY-MM-DD HH:mm:ss'). | ||
* @returns The formatted current date and time string. | ||
*/ | ||
function getCurrentDateTime(format) { | ||
return formatDate(new Date(), format); | ||
} | ||
dateUtils.getCurrentDateTime = getCurrentDateTime; | ||
/** | ||
* Parse a date string into a Date object. | ||
* @param dateString The date string to parse. | ||
* @returns The parsed Date object, or null if parsing fails. | ||
*/ | ||
function parseDate(dateString) { | ||
const timestamp = Date.parse(dateString); | ||
if (!isNaN(timestamp)) { | ||
return new Date(timestamp); | ||
} | ||
return null; | ||
} | ||
dateUtils.parseDate = parseDate; | ||
/** | ||
* Check if a given year is a leap year. | ||
* @param year The year to check. | ||
* @returns True if the year is a leap year, false otherwise. | ||
*/ | ||
function isLeapYear(year) { | ||
return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0; | ||
} | ||
dateUtils.isLeapYear = isLeapYear; | ||
})(dateUtils || (exports.dateUtils = dateUtils = {})); | ||
return null; | ||
} | ||
exports.parseDate = parseDate; | ||
/** | ||
* Check if a given year is a leap year. | ||
* @param year The year to check. | ||
* @returns True if the year is a leap year, false otherwise. | ||
*/ | ||
function isLeapYear(year) { | ||
return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0; | ||
} | ||
exports.isLeapYear = isLeapYear; | ||
// } | ||
//# sourceMappingURL=dateUtils.js.map |
@@ -1,49 +0,47 @@ | ||
export declare namespace stringUtils { | ||
/** | ||
* Converts the first character of a string to uppercase. | ||
* @param str The input string. | ||
* @returns The string with the first character in uppercase. | ||
*/ | ||
function capitalize(str: string): string; | ||
/** | ||
* Converts the first character of a string to lowercase. | ||
* @param str The input string. | ||
* @returns The string with the first character in lowercase. | ||
*/ | ||
function decapitalize(str: string): string; | ||
function toLowerCase(str: string): string; | ||
function toUpperCase(str: string): string; | ||
/** | ||
* Removes leading and trailing whitespace from a string. | ||
* @param str The input string. | ||
* @returns The string with leading and trailing whitespace removed. | ||
*/ | ||
function trim(str: string): string; | ||
/** | ||
* Checks if a string starts with the specified prefix. | ||
* @param str The input string. | ||
* @param prefix The prefix to check for. | ||
* @returns True if the string starts with the prefix, false otherwise. | ||
*/ | ||
function startsWith(str: string, prefix: string): boolean; | ||
/** | ||
* Checks if a string ends with the specified suffix. | ||
* @param str The input string. | ||
* @param suffix The suffix to check for. | ||
* @returns True if the string ends with the suffix, false otherwise. | ||
*/ | ||
function endsWith(str: string, suffix: string): boolean; | ||
/** | ||
* Reverses a string. | ||
* @param str The input string. | ||
* @returns The reversed string. | ||
*/ | ||
function reverseStr(str: string): string; | ||
/** | ||
* Counts the occurrences of a substring within a string. | ||
* @param str The input string. | ||
* @param subStr The substring to search for. | ||
* @returns The number of occurrences of the substring in the string. | ||
*/ | ||
function countOccurrences(str: string, subStr: string): number; | ||
} | ||
/** | ||
* Converts the first character of a string to uppercase. | ||
* @param str The input string. | ||
* @returns The string with the first character in uppercase. | ||
*/ | ||
export declare function capitalize(str: string): string; | ||
/** | ||
* Converts the first character of a string to lowercase. | ||
* @param str The input string. | ||
* @returns The string with the first character in lowercase. | ||
*/ | ||
export declare function decapitalize(str: string): string; | ||
export declare function toLowerCase(str: string): string; | ||
export declare function toUpperCase(str: string): string; | ||
/** | ||
* Removes leading and trailing whitespace from a string. | ||
* @param str The input string. | ||
* @returns The string with leading and trailing whitespace removed. | ||
*/ | ||
export declare function trim(str: string): string; | ||
/** | ||
* Checks if a string starts with the specified prefix. | ||
* @param str The input string. | ||
* @param prefix The prefix to check for. | ||
* @returns True if the string starts with the prefix, false otherwise. | ||
*/ | ||
export declare function startsWith(str: string, prefix: string): boolean; | ||
/** | ||
* Checks if a string ends with the specified suffix. | ||
* @param str The input string. | ||
* @param suffix The suffix to check for. | ||
* @returns True if the string ends with the suffix, false otherwise. | ||
*/ | ||
export declare function endsWith(str: string, suffix: string): boolean; | ||
/** | ||
* Reverses a string. | ||
* @param str The input string. | ||
* @returns The reversed string. | ||
*/ | ||
export declare function reverseStr(str: string): string; | ||
/** | ||
* Counts the occurrences of a substring within a string. | ||
* @param str The input string. | ||
* @param subStr The substring to search for. | ||
* @returns The number of occurrences of the substring in the string. | ||
*/ | ||
export declare function countOccurrences(str: string, subStr: string): number; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.stringUtils = void 0; | ||
var stringUtils; | ||
(function (stringUtils) { | ||
/** | ||
* Converts the first character of a string to uppercase. | ||
* @param str The input string. | ||
* @returns The string with the first character in uppercase. | ||
*/ | ||
function capitalize(str) { | ||
return str.charAt(0).toUpperCase() + str.slice(1); | ||
} | ||
stringUtils.capitalize = capitalize; | ||
/** | ||
* Converts the first character of a string to lowercase. | ||
* @param str The input string. | ||
* @returns The string with the first character in lowercase. | ||
*/ | ||
function decapitalize(str) { | ||
return str.charAt(0).toLowerCase() + str.slice(1); | ||
} | ||
stringUtils.decapitalize = decapitalize; | ||
function toLowerCase(str) { | ||
return str.toLowerCase(); | ||
} | ||
stringUtils.toLowerCase = toLowerCase; | ||
function toUpperCase(str) { | ||
return str.toUpperCase(); | ||
} | ||
stringUtils.toUpperCase = toUpperCase; | ||
/** | ||
* Removes leading and trailing whitespace from a string. | ||
* @param str The input string. | ||
* @returns The string with leading and trailing whitespace removed. | ||
*/ | ||
function trim(str) { | ||
return str.trim(); | ||
} | ||
stringUtils.trim = trim; | ||
/** | ||
* Checks if a string starts with the specified prefix. | ||
* @param str The input string. | ||
* @param prefix The prefix to check for. | ||
* @returns True if the string starts with the prefix, false otherwise. | ||
*/ | ||
function startsWith(str, prefix) { | ||
return str.startsWith(prefix); | ||
} | ||
stringUtils.startsWith = startsWith; | ||
/** | ||
* Checks if a string ends with the specified suffix. | ||
* @param str The input string. | ||
* @param suffix The suffix to check for. | ||
* @returns True if the string ends with the suffix, false otherwise. | ||
*/ | ||
function endsWith(str, suffix) { | ||
return str.endsWith(suffix); | ||
} | ||
stringUtils.endsWith = endsWith; | ||
/** | ||
* Reverses a string. | ||
* @param str The input string. | ||
* @returns The reversed string. | ||
*/ | ||
function reverseStr(str) { | ||
return str.split('').reverse().join(''); | ||
} | ||
stringUtils.reverseStr = reverseStr; | ||
/** | ||
* Counts the occurrences of a substring within a string. | ||
* @param str The input string. | ||
* @param subStr The substring to search for. | ||
* @returns The number of occurrences of the substring in the string. | ||
*/ | ||
function countOccurrences(str, subStr) { | ||
return str.split(subStr).length - 1; | ||
} | ||
stringUtils.countOccurrences = countOccurrences; | ||
})(stringUtils || (exports.stringUtils = stringUtils = {})); | ||
exports.countOccurrences = exports.reverseStr = exports.endsWith = exports.startsWith = exports.trim = exports.toUpperCase = exports.toLowerCase = exports.decapitalize = exports.capitalize = void 0; | ||
// export module stringUtils { | ||
/** | ||
* Converts the first character of a string to uppercase. | ||
* @param str The input string. | ||
* @returns The string with the first character in uppercase. | ||
*/ | ||
function capitalize(str) { | ||
return str.charAt(0).toUpperCase() + str.slice(1); | ||
} | ||
exports.capitalize = capitalize; | ||
/** | ||
* Converts the first character of a string to lowercase. | ||
* @param str The input string. | ||
* @returns The string with the first character in lowercase. | ||
*/ | ||
function decapitalize(str) { | ||
return str.charAt(0).toLowerCase() + str.slice(1); | ||
} | ||
exports.decapitalize = decapitalize; | ||
function toLowerCase(str) { | ||
return str.toLowerCase(); | ||
} | ||
exports.toLowerCase = toLowerCase; | ||
function toUpperCase(str) { | ||
return str.toUpperCase(); | ||
} | ||
exports.toUpperCase = toUpperCase; | ||
/** | ||
* Removes leading and trailing whitespace from a string. | ||
* @param str The input string. | ||
* @returns The string with leading and trailing whitespace removed. | ||
*/ | ||
function trim(str) { | ||
return str.trim(); | ||
} | ||
exports.trim = trim; | ||
/** | ||
* Checks if a string starts with the specified prefix. | ||
* @param str The input string. | ||
* @param prefix The prefix to check for. | ||
* @returns True if the string starts with the prefix, false otherwise. | ||
*/ | ||
function startsWith(str, prefix) { | ||
return str.startsWith(prefix); | ||
} | ||
exports.startsWith = startsWith; | ||
/** | ||
* Checks if a string ends with the specified suffix. | ||
* @param str The input string. | ||
* @param suffix The suffix to check for. | ||
* @returns True if the string ends with the suffix, false otherwise. | ||
*/ | ||
function endsWith(str, suffix) { | ||
return str.endsWith(suffix); | ||
} | ||
exports.endsWith = endsWith; | ||
/** | ||
* Reverses a string. | ||
* @param str The input string. | ||
* @returns The reversed string. | ||
*/ | ||
function reverseStr(str) { | ||
return str.split('').reverse().join(''); | ||
} | ||
exports.reverseStr = reverseStr; | ||
/** | ||
* Counts the occurrences of a substring within a string. | ||
* @param str The input string. | ||
* @param subStr The substring to search for. | ||
* @returns The number of occurrences of the substring in the string. | ||
*/ | ||
function countOccurrences(str, subStr) { | ||
return str.split(subStr).length - 1; | ||
} | ||
exports.countOccurrences = countOccurrences; | ||
// } | ||
//# sourceMappingURL=stringUtils.js.map |
{ | ||
"name": "auxin", | ||
"version": "1.15.9", | ||
"version": "1.16.9", | ||
"description": "Auxin is a powerful Node.js utility toolkit that simplifies common tasks, boosting your development productivity.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -1,150 +0,150 @@ | ||
export module arrayUtils { | ||
/** | ||
* Filters an array based on a predicate function. | ||
* @param arr The array to filter. | ||
* @param predicate The predicate function used to filter elements. | ||
* @returns A new array containing only the elements that satisfy the predicate function. | ||
*/ | ||
export function filterArray<T>(arr: T[], predicate: (element: T) => boolean): T[] { | ||
return arr.filter(predicate); | ||
} | ||
// export module arrayUtils { | ||
/** | ||
* Filters an array based on a predicate function. | ||
* @param arr The array to filter. | ||
* @param predicate The predicate function used to filter elements. | ||
* @returns A new array containing only the elements that satisfy the predicate function. | ||
*/ | ||
export function filterArray<T>(arr: T[], predicate: (element: T) => boolean): T[] { | ||
return arr.filter(predicate); | ||
} | ||
/** | ||
* Maps each element of an array to a new value using a transformation function. | ||
* @param arr The array to map. | ||
* @param mapper The transformation function to apply to each element. | ||
* @returns A new array containing the transformed elements. | ||
*/ | ||
export function mapArray<T, U>(arr: T[], mapper: (element: T) => U): U[] { | ||
return arr.map(mapper); | ||
} | ||
/** | ||
* Maps each element of an array to a new value using a transformation function. | ||
* @param arr The array to map. | ||
* @param mapper The transformation function to apply to each element. | ||
* @returns A new array containing the transformed elements. | ||
*/ | ||
export function mapArray<T, U>(arr: T[], mapper: (element: T) => U): U[] { | ||
return arr.map(mapper); | ||
} | ||
export function binarySearch<T>(arr: T[], target: T): number { | ||
let left = 0; | ||
let right = arr.length - 1; | ||
export function binarySearch<T>(arr: T[], target: T): number { | ||
let left = 0; | ||
let right = arr.length - 1; | ||
while (left <= right) { | ||
const mid = Math.floor((left + right) / 2); | ||
const midVal = arr[mid]; | ||
while (left <= right) { | ||
const mid = Math.floor((left + right) / 2); | ||
const midVal = arr[mid]; | ||
if (midVal === target) { | ||
return mid; | ||
} else if (midVal < target) { | ||
left = mid + 1; | ||
} else { | ||
right = mid - 1; | ||
} | ||
if (midVal === target) { | ||
return mid; | ||
} else if (midVal < target) { | ||
left = mid + 1; | ||
} else { | ||
right = mid - 1; | ||
} | ||
return -1; // Element not found | ||
} | ||
export function quickSort<T>(arr: T[]): T[] { | ||
if (arr.length <= 1) { | ||
return arr; | ||
} | ||
return -1; // Element not found | ||
} | ||
const pivot = arr[0]; | ||
const left = []; | ||
const right = []; | ||
export function quickSort<T>(arr: T[]): T[] { | ||
if (arr.length <= 1) { | ||
return arr; | ||
} | ||
for (let i = 1; i < arr.length; i++) { | ||
if (arr[i] < pivot) { | ||
left.push(arr[i]); | ||
} else { | ||
right.push(arr[i]); | ||
} | ||
} | ||
const pivot = arr[0]; | ||
const left = []; | ||
const right = []; | ||
return [...quickSort(left), pivot, ...quickSort(right)]; | ||
} | ||
export function quickSortDescending<T>(arr: T[]): T[] { | ||
if (arr.length <= 1) { | ||
return arr; | ||
for (let i = 1; i < arr.length; i++) { | ||
if (arr[i] < pivot) { | ||
left.push(arr[i]); | ||
} else { | ||
right.push(arr[i]); | ||
} | ||
const pivot = arr[0]; | ||
const left = []; | ||
const right = []; | ||
for (let i = 1; i < arr.length; i++) { | ||
if (arr[i] >= pivot) { // Modified condition for descending order | ||
left.push(arr[i]); | ||
} else { | ||
right.push(arr[i]); | ||
} | ||
} | ||
return [...quickSortDescending(left), pivot, ...quickSortDescending(right)]; // Recursively sort left and right arrays | ||
} | ||
export function arrPush<T>(arr: T[], target: T): T[] { | ||
arr.push(target); | ||
return arr; | ||
} | ||
return [...quickSort(left), pivot, ...quickSort(right)]; | ||
} | ||
export function arrUnshift<T>(arr: T[], target: T): T[] { | ||
arr.unshift(target); | ||
export function quickSortDescending<T>(arr: T[]): T[] { | ||
if (arr.length <= 1) { | ||
return arr; | ||
} | ||
export function arrPop<T>(arr: T[]): T[] { | ||
arr.pop(); | ||
return arr; | ||
} | ||
const pivot = arr[0]; | ||
const left = []; | ||
const right = []; | ||
export function arrShift<T>(arr: T[]): T[] { | ||
arr.shift(); | ||
return arr; | ||
for (let i = 1; i < arr.length; i++) { | ||
if (arr[i] >= pivot) { // Modified condition for descending order | ||
left.push(arr[i]); | ||
} else { | ||
right.push(arr[i]); | ||
} | ||
} | ||
export function arrSlice<T>(arr: T[], start: number, end: number): T[] { | ||
arr.slice(start, end); | ||
return arr; | ||
} | ||
return [...quickSortDescending(left), pivot, ...quickSortDescending(right)]; // Recursively sort left and right arrays | ||
} | ||
export function arrToUpperCase<T>(arr: T[]): T[] { | ||
// Create a new array to store the uppercase elements | ||
const upperCaseArray: T[] = []; | ||
// Iterate through the original array and convert each element to uppercase | ||
for (const element of arr) { | ||
// Check if the element is a string | ||
if (typeof element === 'string') { | ||
// If it's a string, convert it to uppercase and push to the new array | ||
upperCaseArray.push(element.toUpperCase() as unknown as T); | ||
} else { | ||
// If it's not a string, push it to the new array as is | ||
upperCaseArray.push(element); | ||
} | ||
export function arrPush<T>(arr: T[], target: T): T[] { | ||
arr.push(target); | ||
return arr; | ||
} | ||
export function arrUnshift<T>(arr: T[], target: T): T[] { | ||
arr.unshift(target); | ||
return arr; | ||
} | ||
export function arrPop<T>(arr: T[]): T[] { | ||
arr.pop(); | ||
return arr; | ||
} | ||
export function arrShift<T>(arr: T[]): T[] { | ||
arr.shift(); | ||
return arr; | ||
} | ||
export function arrSlice<T>(arr: T[], start: number, end: number): T[] { | ||
arr.slice(start, end); | ||
return arr; | ||
} | ||
export function arrToUpperCase<T>(arr: T[]): T[] { | ||
// Create a new array to store the uppercase elements | ||
const upperCaseArray: T[] = []; | ||
// Iterate through the original array and convert each element to uppercase | ||
for (const element of arr) { | ||
// Check if the element is a string | ||
if (typeof element === 'string') { | ||
// If it's a string, convert it to uppercase and push to the new array | ||
upperCaseArray.push(element.toUpperCase() as unknown as T); | ||
} else { | ||
// If it's not a string, push it to the new array as is | ||
upperCaseArray.push(element); | ||
} | ||
// Return the array with all elements converted to uppercase | ||
return upperCaseArray; | ||
} | ||
// Return the array with all elements converted to uppercase | ||
return upperCaseArray; | ||
} | ||
export function arrToLowerCase<T>(arr: T[]): T[] { | ||
// Create a new array to store the lowercase elements | ||
const lowerCaseArray: T[] = []; | ||
// Iterate through the original array and convert each element to lowercase | ||
for (const element of arr) { | ||
// Check if the element is a string | ||
if (typeof element === 'string') { | ||
// If it's a string, convert it to lowercase and push to the new array | ||
lowerCaseArray.push(element.toLowerCase() as unknown as T); | ||
} else { | ||
// If it's not a string, push it to the new array as is | ||
lowerCaseArray.push(element); | ||
} | ||
export function arrToLowerCase<T>(arr: T[]): T[] { | ||
// Create a new array to store the lowercase elements | ||
const lowerCaseArray: T[] = []; | ||
// Iterate through the original array and convert each element to lowercase | ||
for (const element of arr) { | ||
// Check if the element is a string | ||
if (typeof element === 'string') { | ||
// If it's a string, convert it to lowercase and push to the new array | ||
lowerCaseArray.push(element.toLowerCase() as unknown as T); | ||
} else { | ||
// If it's not a string, push it to the new array as is | ||
lowerCaseArray.push(element); | ||
} | ||
// Return the array with all elements converted to lowercase | ||
return lowerCaseArray; | ||
} | ||
// Add more array utility functions here as needed... | ||
// Return the array with all elements converted to lowercase | ||
return lowerCaseArray; | ||
} | ||
// Add more array utility functions here as needed... | ||
// } |
@@ -1,55 +0,55 @@ | ||
export module dateUtils { | ||
/** | ||
* Format a date object as a string in the specified format. | ||
* @param date The date object to format. | ||
* @param format The format string (e.g., 'YYYY-MM-DD HH:mm:ss'). | ||
* @returns The formatted date string. | ||
*/ | ||
export function formatDate(date: Date, format: string): string { | ||
const yyyy = date.getFullYear(); | ||
const mm = String(date.getMonth() + 1).padStart(2, '0'); | ||
const dd = String(date.getDate()).padStart(2, '0'); | ||
const hh = String(date.getHours()).padStart(2, '0'); | ||
const min = String(date.getMinutes()).padStart(2, '0'); | ||
const ss = String(date.getSeconds()).padStart(2, '0'); | ||
// export module dateUtils { | ||
/** | ||
* Format a date object as a string in the specified format. | ||
* @param date The date object to format. | ||
* @param format The format string (e.g., 'YYYY-MM-DD HH:mm:ss'). | ||
* @returns The formatted date string. | ||
*/ | ||
export function formatDate(date: Date, format: string): string { | ||
const yyyy = date.getFullYear(); | ||
const mm = String(date.getMonth() + 1).padStart(2, '0'); | ||
const dd = String(date.getDate()).padStart(2, '0'); | ||
const hh = String(date.getHours()).padStart(2, '0'); | ||
const min = String(date.getMinutes()).padStart(2, '0'); | ||
const ss = String(date.getSeconds()).padStart(2, '0'); | ||
return format | ||
.replace('YYYY', String(yyyy)) | ||
.replace('MM', mm) | ||
.replace('DD', dd) | ||
.replace('HH', hh) | ||
.replace('mm', min) | ||
.replace('ss', ss); | ||
} | ||
return format | ||
.replace('YYYY', String(yyyy)) | ||
.replace('MM', mm) | ||
.replace('DD', dd) | ||
.replace('HH', hh) | ||
.replace('mm', min) | ||
.replace('ss', ss); | ||
} | ||
/** | ||
* Get the current date and time formatted as a string in the specified format. | ||
* @param format The format string (e.g., 'YYYY-MM-DD HH:mm:ss'). | ||
* @returns The formatted current date and time string. | ||
*/ | ||
export function getCurrentDateTime(format: string): string { | ||
return formatDate(new Date(), format); | ||
} | ||
/** | ||
* Get the current date and time formatted as a string in the specified format. | ||
* @param format The format string (e.g., 'YYYY-MM-DD HH:mm:ss'). | ||
* @returns The formatted current date and time string. | ||
*/ | ||
export function getCurrentDateTime(format: string): string { | ||
return formatDate(new Date(), format); | ||
} | ||
/** | ||
* Parse a date string into a Date object. | ||
* @param dateString The date string to parse. | ||
* @returns The parsed Date object, or null if parsing fails. | ||
*/ | ||
export function parseDate(dateString: string): Date | null { | ||
const timestamp = Date.parse(dateString); | ||
if (!isNaN(timestamp)) { | ||
return new Date(timestamp); | ||
} | ||
return null; | ||
/** | ||
* Parse a date string into a Date object. | ||
* @param dateString The date string to parse. | ||
* @returns The parsed Date object, or null if parsing fails. | ||
*/ | ||
export function parseDate(dateString: string): Date | null { | ||
const timestamp = Date.parse(dateString); | ||
if (!isNaN(timestamp)) { | ||
return new Date(timestamp); | ||
} | ||
return null; | ||
} | ||
/** | ||
* Check if a given year is a leap year. | ||
* @param year The year to check. | ||
* @returns True if the year is a leap year, false otherwise. | ||
*/ | ||
export function isLeapYear(year: number): boolean { | ||
return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0; | ||
} | ||
} | ||
/** | ||
* Check if a given year is a leap year. | ||
* @param year The year to check. | ||
* @returns True if the year is a leap year, false otherwise. | ||
*/ | ||
export function isLeapYear(year: number): boolean { | ||
return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0; | ||
} | ||
// } |
export * from './arrayUtils'; | ||
export * from './stringUtils'; | ||
export * from './dateUtils'; | ||
// Export other utility functions/modules here... | ||
// Export other utility functions/modules here... |
@@ -1,75 +0,75 @@ | ||
export module stringUtils { | ||
/** | ||
* Converts the first character of a string to uppercase. | ||
* @param str The input string. | ||
* @returns The string with the first character in uppercase. | ||
*/ | ||
export function capitalize(str: string): string { | ||
return str.charAt(0).toUpperCase() + str.slice(1); | ||
} | ||
// export module stringUtils { | ||
/** | ||
* Converts the first character of a string to uppercase. | ||
* @param str The input string. | ||
* @returns The string with the first character in uppercase. | ||
*/ | ||
export function capitalize(str: string): string { | ||
return str.charAt(0).toUpperCase() + str.slice(1); | ||
} | ||
/** | ||
* Converts the first character of a string to lowercase. | ||
* @param str The input string. | ||
* @returns The string with the first character in lowercase. | ||
*/ | ||
export function decapitalize(str: string): string { | ||
return str.charAt(0).toLowerCase() + str.slice(1); | ||
} | ||
/** | ||
* Converts the first character of a string to lowercase. | ||
* @param str The input string. | ||
* @returns The string with the first character in lowercase. | ||
*/ | ||
export function decapitalize(str: string): string { | ||
return str.charAt(0).toLowerCase() + str.slice(1); | ||
} | ||
export function toLowerCase(str: string): string { | ||
return str.toLowerCase(); | ||
} | ||
export function toLowerCase(str: string): string { | ||
return str.toLowerCase(); | ||
} | ||
export function toUpperCase(str: string): string { | ||
return str.toUpperCase(); | ||
} | ||
export function toUpperCase(str: string): string { | ||
return str.toUpperCase(); | ||
} | ||
/** | ||
* Removes leading and trailing whitespace from a string. | ||
* @param str The input string. | ||
* @returns The string with leading and trailing whitespace removed. | ||
*/ | ||
export function trim(str: string): string { | ||
return str.trim(); | ||
} | ||
/** | ||
* Removes leading and trailing whitespace from a string. | ||
* @param str The input string. | ||
* @returns The string with leading and trailing whitespace removed. | ||
*/ | ||
export function trim(str: string): string { | ||
return str.trim(); | ||
} | ||
/** | ||
* Checks if a string starts with the specified prefix. | ||
* @param str The input string. | ||
* @param prefix The prefix to check for. | ||
* @returns True if the string starts with the prefix, false otherwise. | ||
*/ | ||
export function startsWith(str: string, prefix: string): boolean { | ||
return str.startsWith(prefix); | ||
} | ||
/** | ||
* Checks if a string starts with the specified prefix. | ||
* @param str The input string. | ||
* @param prefix The prefix to check for. | ||
* @returns True if the string starts with the prefix, false otherwise. | ||
*/ | ||
export function startsWith(str: string, prefix: string): boolean { | ||
return str.startsWith(prefix); | ||
} | ||
/** | ||
* Checks if a string ends with the specified suffix. | ||
* @param str The input string. | ||
* @param suffix The suffix to check for. | ||
* @returns True if the string ends with the suffix, false otherwise. | ||
*/ | ||
export function endsWith(str: string, suffix: string): boolean { | ||
return str.endsWith(suffix); | ||
} | ||
/** | ||
* Checks if a string ends with the specified suffix. | ||
* @param str The input string. | ||
* @param suffix The suffix to check for. | ||
* @returns True if the string ends with the suffix, false otherwise. | ||
*/ | ||
export function endsWith(str: string, suffix: string): boolean { | ||
return str.endsWith(suffix); | ||
} | ||
/** | ||
* Reverses a string. | ||
* @param str The input string. | ||
* @returns The reversed string. | ||
*/ | ||
export function reverseStr(str: string): string { | ||
return str.split('').reverse().join(''); | ||
} | ||
/** | ||
* Reverses a string. | ||
* @param str The input string. | ||
* @returns The reversed string. | ||
*/ | ||
export function reverseStr(str: string): string { | ||
return str.split('').reverse().join(''); | ||
} | ||
/** | ||
* Counts the occurrences of a substring within a string. | ||
* @param str The input string. | ||
* @param subStr The substring to search for. | ||
* @returns The number of occurrences of the substring in the string. | ||
*/ | ||
export function countOccurrences(str: string, subStr: string): number { | ||
return str.split(subStr).length - 1; | ||
} | ||
} | ||
/** | ||
* Counts the occurrences of a substring within a string. | ||
* @param str The input string. | ||
* @param subStr The substring to search for. | ||
* @returns The number of occurrences of the substring in the string. | ||
*/ | ||
export function countOccurrences(str: string, subStr: string): number { | ||
return str.split(subStr).length - 1; | ||
} | ||
// } |
@@ -1,9 +0,9 @@ | ||
const { arrayUtils } = require('../dist/arrayUtils'); // Import the array utility functions to be tested | ||
const { binarySearch, quickSort, quickSortDescending, arrPop, arrPush, arrShift, arrSlice, arrToLowerCase, arrToUpperCase, arrUnshift, filterArray } = require('../dist/arrayUtils'); // Import the array utility functions to be tested | ||
const arr = ['a', 'b', 'c', 'd', 'e']; | ||
const index = arrayUtils.binarySearch(arr, 'c'); | ||
const index = binarySearch(arr, 'c'); | ||
console.log(index); // Output: 2 | ||
const arrr = [3, 1, 4, 1, 5, 9, 2, 6, 5]; | ||
const sortedArr = arrayUtils.quickSort(arrr); | ||
const sortedArr = quickSort(arrr); | ||
console.log(sortedArr); // Output: [1, 1, 2, 3, 4, 5, 5, 6, 9] | ||
@@ -13,3 +13,3 @@ | ||
const decarrr = [3, 1, 4, 1, 5, 9, 2, 6, 5]; | ||
const dec = arrayUtils.quickSortDescending(decarrr); | ||
const dec = quickSortDescending(decarrr); | ||
console.log("dec",dec); // Output: [1, 1, 2, 3, 4, 5, 5, 6, 9] | ||
@@ -22,10 +22,10 @@ | ||
const pushedArray = arrayUtils.arrPush(arr, 3); | ||
const pushedArray = arrPush(arr, 3); | ||
console.log(pushedArray); | ||
const unshiftedArr = arrayUtils.arrUnshift(arrr, 3) | ||
const unshiftedArr = arrUnshift(arrr, 3) | ||
console.log(unshiftedArr); | ||
const arre = [3, 1, 4, 1, 5, 9, 2, 6, 5]; | ||
const poppedArr = arrayUtils.arrPop(arre) | ||
const poppedArr = arrPop(arre) | ||
console.log(poppedArr); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
92648
712