Comparing version 1.4.0 to 1.5.0
@@ -16,2 +16,4 @@ export declare namespace arrayUtils { | ||
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[]; | ||
} |
@@ -26,4 +26,41 @@ "use strict"; | ||
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; | ||
} | ||
} | ||
return -1; // Element not found | ||
} | ||
arrayUtils.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]); | ||
} | ||
else { | ||
right.push(arr[i]); | ||
} | ||
} | ||
return [...quickSort(left), pivot, ...quickSort(right)]; | ||
} | ||
arrayUtils.quickSort = quickSort; | ||
// Add more array utility functions here as needed... | ||
})(arrayUtils || (exports.arrayUtils = arrayUtils = {})); | ||
//# sourceMappingURL=arrayUtils.js.map |
@@ -1,25 +0,27 @@ | ||
/** | ||
* 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; | ||
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; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isLeapYear = exports.parseDate = exports.getCurrentDateTime = exports.formatDate = void 0; | ||
/** | ||
* 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); | ||
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); | ||
} | ||
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; | ||
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 = {})); | ||
//# sourceMappingURL=dateUtils.js.map |
@@ -1,45 +0,49 @@ | ||
/** | ||
* 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; | ||
/** | ||
* 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 reverse(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; | ||
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; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.countOccurrences = exports.reverse = exports.endsWith = exports.startsWith = exports.trim = exports.decapitalize = exports.capitalize = void 0; | ||
/** | ||
* 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; | ||
/** | ||
* 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 reverse(str) { | ||
return str.split('').reverse().join(''); | ||
} | ||
exports.reverse = reverse; | ||
/** | ||
* 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; | ||
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 = {})); | ||
//# sourceMappingURL=stringUtils.js.map |
{ | ||
"name": "auxin", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"description": "The Utility Toolkit npm package is a comprehensive collection of utility functions designed to streamline common tasks in Node.js development. Whether you're working on string manipulation, array operations, date/time formatting, or other general-purpose tasks, this toolkit has you covered.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -27,3 +27,3 @@ # Auxin Utility Toolkit | ||
const str = 'Hello, World!'; | ||
const reversedStr = stringUtils.reverseString(str); | ||
const reversedStr = stringUtils.reverseStr(str); | ||
console.log(reversedStr); // Output: '!dlroW ,olleH' | ||
@@ -30,0 +30,0 @@ |
@@ -22,3 +22,43 @@ export module arrayUtils { | ||
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]; | ||
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; | ||
} | ||
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]); | ||
} | ||
} | ||
return [...quickSort(left), pivot, ...quickSort(right)]; | ||
} | ||
// Add more array utility functions here as needed... | ||
} |
@@ -1,53 +0,55 @@ | ||
/** | ||
* 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); | ||
/** | ||
* 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; | ||
} | ||
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; | ||
} | ||
} |
@@ -1,65 +0,75 @@ | ||
/** | ||
* 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); | ||
} | ||
/** | ||
* 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(); | ||
} | ||
export function toLowerCase(str: string): string { | ||
return str.toLowerCase(); | ||
} | ||
/** | ||
* 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); | ||
} | ||
export function toUpperCase(str: string): string { | ||
return str.toUpperCase(); | ||
} | ||
/** | ||
* 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); | ||
} | ||
/** | ||
* 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(); | ||
} | ||
/** | ||
* Reverses a string. | ||
* @param str The input string. | ||
* @returns The reversed string. | ||
*/ | ||
export function reverse(str: string): string { | ||
return str.split('').reverse().join(''); | ||
} | ||
/** | ||
* 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); | ||
} | ||
/** | ||
* 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; | ||
} | ||
/** | ||
* 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(''); | ||
} | ||
/** | ||
* 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; | ||
} | ||
} |
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
28026
544