Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 28716c7b5a | |||
| d530f6abdf |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ztimson/utils",
|
"name": "@ztimson/utils",
|
||||||
"version": "0.29.2",
|
"version": "0.29.4",
|
||||||
"description": "Utility library",
|
"description": "Utility library",
|
||||||
"author": "Zak Timson",
|
"author": "Zak Timson",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|||||||
@@ -241,7 +241,6 @@ export function snakeCase(str?: string): string {
|
|||||||
return wordSegments(str).map(w => w.toLowerCase()).join("_");
|
return wordSegments(str).map(w => w.toLowerCase()).join("_");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Splice a string together (Similar to Array.splice)
|
* Splice a string together (Similar to Array.splice)
|
||||||
*
|
*
|
||||||
@@ -257,6 +256,20 @@ export function strSplice(str: string, start: number, deleteCount: number, inser
|
|||||||
return before + insert + after;
|
return before + insert + after;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function titleCase(str: string) {
|
||||||
|
// Normalize separators: replace underscores and hyphens with spaces
|
||||||
|
let normalizedStr = str.replace(/(_|-)/g, ' ');
|
||||||
|
// Handle CamelCase/PascalCase boundaries: insert a space before capital letters
|
||||||
|
normalizedStr = normalizedStr.replace(/([a-z])([A-Z])/g, '$1 $2');
|
||||||
|
// Lowercase the whole string, split by any whitespace, and capitalize each word
|
||||||
|
let words = normalizedStr.toLowerCase().split(/\s+/).filter(Boolean);
|
||||||
|
const titledWords = words.map(word => {
|
||||||
|
if (word.length === 0) return '';
|
||||||
|
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
||||||
|
});
|
||||||
|
return titledWords.join(' ');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find all substrings that match a given pattern.
|
* Find all substrings that match a given pattern.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ export function formatDate(format: string = 'YYYY-MM-DD H:mm', date: Date | numb
|
|||||||
});
|
});
|
||||||
|
|
||||||
const monthValue = parseInt(partsMap.month) - 1;
|
const monthValue = parseInt(partsMap.month) - 1;
|
||||||
const dayOfWeekValue = new Date(`${partsMap.year}-${partsMap.month}-${partsMap.day}`).getDay();
|
const dayOfWeekValue = new Date(Date.UTC(parseInt(partsMap.year), parseInt(partsMap.month) - 1, parseInt(partsMap.day))).getUTCDay();
|
||||||
const hourValue = parseInt(partsMap.hour);
|
const hourValue = parseInt(partsMap.hour);
|
||||||
|
|
||||||
get = (fn: 'FullYear' | 'Month' | 'Date' | 'Day' | 'Hours' | 'Minutes' | 'Seconds' | 'Milliseconds'): number => {
|
get = (fn: 'FullYear' | 'Month' | 'Date' | 'Day' | 'Hours' | 'Minutes' | 'Seconds' | 'Milliseconds'): number => {
|
||||||
|
|||||||
Reference in New Issue
Block a user