@stacksjs/strings 0.75.514 → 0.75.518

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/case.js CHANGED
@@ -1 +1 @@
1
- export function capitalize(str){return str[0]?str[0].toUpperCase()+str.slice(1).toLowerCase():""}export function lowercase(str){return str.toLowerCase()}const SPLIT_LOWER_UPPER_RE=/([\p{Ll}\d])(\p{Lu})/gu,SPLIT_UPPER_UPPER_RE=/(\p{Lu})(\p{Lu}\p{Ll})/gu,SPLIT_SEPARATE_NUMBER_RE=/(\d)\p{Ll}|(\p{L})\d/u,DEFAULT_STRIP_REGEXP=/[^\p{L}\p{M}\p{N}]+/giu,SPLIT_REPLACE_VALUE="$1\x00$2",DEFAULT_PREFIX_SUFFIX_CHARACTERS="";export function split(value){let result=value.trim();result=result.replace(SPLIT_LOWER_UPPER_RE,SPLIT_REPLACE_VALUE).replace(SPLIT_UPPER_UPPER_RE,SPLIT_REPLACE_VALUE);result=result.replace(DEFAULT_STRIP_REGEXP,"\x00");let start=0,end=result.length;while(result.charAt(start)==="\x00")start++;if(start===end)return[];while(result.charAt(end-1)==="\x00")end--;return result.slice(start,end).split(/\0/g)}export function splitSeparateNumbers(value){const words=split(value);for(let i=0;i<words.length;i++){const word=words[i];if(word===void 0)continue;const match=SPLIT_SEPARATE_NUMBER_RE.exec(word);if(match){const offset=match.index+(match[1]??match[2]??"").length;words.splice(i,1,word.slice(0,offset),word.slice(offset))}}return words}export function noCase(input,options){const[prefix,words,suffix]=splitPrefixSuffix(input,options);return prefix+words.map(lowerFactory(options?.locale)).join(options?.delimiter??" ")+suffix}export function camelCase(input,options){const[prefix,words,suffix]=splitPrefixSuffix(input,options),lower=lowerFactory(options?.locale),upper=upperFactory(options?.locale),transform=options?.mergeAmbiguousCharacters?capitalCaseTransformFactory(lower,upper):pascalCaseTransformFactory(lower,upper);return prefix+words.map((word,index)=>{if(index===0)return lower(word);return transform(word,index)}).join(options?.delimiter??"")+suffix}export function pascalCase(input,options){const[prefix,words,suffix]=splitPrefixSuffix(input,options),lower=lowerFactory(options?.locale),upper=upperFactory(options?.locale),transform=options?.mergeAmbiguousCharacters?capitalCaseTransformFactory(lower,upper):pascalCaseTransformFactory(lower,upper);return prefix+words.map(transform).join(options?.delimiter??"")+suffix}export function pascalSnakeCase(input,options){return capitalCase(input,{delimiter:"_",...options})}export function capitalCase(input,options){const[prefix,words,suffix]=splitPrefixSuffix(input,options),lower=lowerFactory(options?.locale),upper=upperFactory(options?.locale);return prefix+words.map(capitalCaseTransformFactory(lower,upper)).join(options?.delimiter??" ")+suffix}export function constantCase(input,options){const[prefix,words,suffix]=splitPrefixSuffix(input,options);return prefix+words.map(upperFactory(options?.locale)).join(options?.delimiter??"_")+suffix}export function dotCase(input,options){return noCase(input,{delimiter:".",...options})}export function kebabCase(input,options){return noCase(input,{delimiter:"-",...options})}export function pathCase(input,options){return noCase(input,{delimiter:"/",...options})}export function sentenceCase(input,options){const[prefix,words,suffix]=splitPrefixSuffix(input,options),lower=lowerFactory(options?.locale),upper=upperFactory(options?.locale),transform=capitalCaseTransformFactory(lower,upper);return prefix+words.map((word,index)=>{if(index===0)return transform(word);return lower(word)}).join(options?.delimiter??" ")+suffix}export function snakeCase(input,options){return noCase(input,{delimiter:"_",...options})}export function trainCase(input,options){return capitalCase(input,{delimiter:"-",...options})}export function paramCase(input,options){return kebabCase(input,options)}function lowerFactory(locale){return locale===!1?(input)=>input.toLowerCase():(input)=>input.toLocaleLowerCase(locale)}function upperFactory(locale){return locale===!1?(input)=>input.toUpperCase():(input)=>input.toLocaleUpperCase(locale)}function capitalCaseTransformFactory(lower,upper){return(word)=>{if(!word)return word;return`${upper(word[0]??"")}${lower(word.slice(1))}`}}function pascalCaseTransformFactory(lower,upper){return(word,index)=>{if(!word)return word;const char0=word[0]??"";return(index>0&&char0>="0"&&char0<="9"?`_${char0}`:upper(char0))+lower(word.slice(1))}}function splitPrefixSuffix(input,options={}){const splitFn=options.split??split,prefixCharacters=options.prefixCharacters??DEFAULT_PREFIX_SUFFIX_CHARACTERS,suffixCharacters=options.suffixCharacters??DEFAULT_PREFIX_SUFFIX_CHARACTERS;let prefixIndex=0,suffixIndex=input.length;while(prefixIndex<input.length){const char=input.charAt(prefixIndex);if(!prefixCharacters.includes(char))break;prefixIndex++}while(suffixIndex>prefixIndex){const index=suffixIndex-1,char=input.charAt(index);if(!suffixCharacters.includes(char))break;suffixIndex=index}return[input.slice(0,prefixIndex),splitFn(input.slice(prefixIndex,suffixIndex)),input.slice(suffixIndex)]}export*from"./sponge-case";export*from"./swap-case";export*from"./title-case";
1
+ export function capitalize(str){return str[0]?str[0].toUpperCase()+str.slice(1).toLowerCase():""}export function lowercase(str){return str.toLowerCase()}const SPLIT_LOWER_UPPER_RE=/([\p{Ll}\d])(\p{Lu})/gu;const SPLIT_UPPER_UPPER_RE=/(\p{Lu})(\p{Lu}\p{Ll})/gu;const SPLIT_SEPARATE_NUMBER_RE=/(\d)\p{Ll}|(\p{L})\d/u;const DEFAULT_STRIP_REGEXP=/[^\p{L}\p{M}\p{N}]+/giu;const SPLIT_REPLACE_VALUE="$1\x00$2";const DEFAULT_PREFIX_SUFFIX_CHARACTERS="";export function split(value){let result=value.trim();result=result.replace(SPLIT_LOWER_UPPER_RE,SPLIT_REPLACE_VALUE).replace(SPLIT_UPPER_UPPER_RE,SPLIT_REPLACE_VALUE);result=result.replace(DEFAULT_STRIP_REGEXP,"\x00");let start=0;let end=result.length;while(result.charAt(start)==="\x00")start++;if(start===end)return[];while(result.charAt(end-1)==="\x00")end--;return result.slice(start,end).split(/\0/g)}export function splitSeparateNumbers(value){const words=split(value);for(let i=0;i<words.length;i++){const word=words[i];if(word===undefined)continue;const match=SPLIT_SEPARATE_NUMBER_RE.exec(word);if(match){const offset=match.index+(match[1]??match[2]??"").length;words.splice(i,1,word.slice(0,offset),word.slice(offset))}}return words}export function noCase(input,options){const[prefix,words,suffix]=splitPrefixSuffix(input,options);return prefix+words.map(lowerFactory(options?.locale)).join(options?.delimiter??" ")+suffix}export function camelCase(input,options){const[prefix,words,suffix]=splitPrefixSuffix(input,options);const lower=lowerFactory(options?.locale);const upper=upperFactory(options?.locale);const transform=options?.mergeAmbiguousCharacters?capitalCaseTransformFactory(lower,upper):pascalCaseTransformFactory(lower,upper);return prefix+words.map((word,index)=>{if(index===0)return lower(word);return transform(word,index)}).join(options?.delimiter??"")+suffix}export function pascalCase(input,options){const[prefix,words,suffix]=splitPrefixSuffix(input,options);const lower=lowerFactory(options?.locale);const upper=upperFactory(options?.locale);const transform=options?.mergeAmbiguousCharacters?capitalCaseTransformFactory(lower,upper):pascalCaseTransformFactory(lower,upper);return prefix+words.map(transform).join(options?.delimiter??"")+suffix}export function pascalSnakeCase(input,options){return capitalCase(input,{delimiter:"_",...options})}export function capitalCase(input,options){const[prefix,words,suffix]=splitPrefixSuffix(input,options);const lower=lowerFactory(options?.locale);const upper=upperFactory(options?.locale);return prefix+words.map(capitalCaseTransformFactory(lower,upper)).join(options?.delimiter??" ")+suffix}export function constantCase(input,options){const[prefix,words,suffix]=splitPrefixSuffix(input,options);return prefix+words.map(upperFactory(options?.locale)).join(options?.delimiter??"_")+suffix}export function dotCase(input,options){return noCase(input,{delimiter:".",...options})}export function kebabCase(input,options){return noCase(input,{delimiter:"-",...options})}export function pathCase(input,options){return noCase(input,{delimiter:"/",...options})}export function sentenceCase(input,options){const[prefix,words,suffix]=splitPrefixSuffix(input,options);const lower=lowerFactory(options?.locale);const upper=upperFactory(options?.locale);const transform=capitalCaseTransformFactory(lower,upper);return prefix+words.map((word,index)=>{if(index===0)return transform(word);return lower(word)}).join(options?.delimiter??" ")+suffix}export function snakeCase(input,options){return noCase(input,{delimiter:"_",...options})}export function trainCase(input,options){return capitalCase(input,{delimiter:"-",...options})}export function paramCase(input,options){return kebabCase(input,options)}function lowerFactory(locale){return locale===false?(input)=>input.toLowerCase():(input)=>input.toLocaleLowerCase(locale)}function upperFactory(locale){return locale===false?(input)=>input.toUpperCase():(input)=>input.toLocaleUpperCase(locale)}function capitalCaseTransformFactory(lower,upper){return(word)=>{if(!word)return word;return`${upper(word[0]??"")}${lower(word.slice(1))}`}}function pascalCaseTransformFactory(lower,upper){return(word,index)=>{if(!word)return word;const char0=word[0]??"";const initial=index>0&&char0>="0"&&char0<="9"?`_${char0}`:upper(char0);return initial+lower(word.slice(1))}}function splitPrefixSuffix(input,options={}){const splitFn=options.split??split;const prefixCharacters=options.prefixCharacters??DEFAULT_PREFIX_SUFFIX_CHARACTERS;const suffixCharacters=options.suffixCharacters??DEFAULT_PREFIX_SUFFIX_CHARACTERS;let prefixIndex=0;let suffixIndex=input.length;while(prefixIndex<input.length){const char=input.charAt(prefixIndex);if(!prefixCharacters.includes(char))break;prefixIndex++}while(suffixIndex>prefixIndex){const index=suffixIndex-1;const char=input.charAt(index);if(!suffixCharacters.includes(char))break;suffixIndex=index}return[input.slice(0,prefixIndex),splitFn(input.slice(prefixIndex,suffixIndex)),input.slice(suffixIndex)]}export*from"./sponge-case";export*from"./swap-case";export*from"./title-case";
package/dist/csv.js CHANGED
@@ -1,2 +1,2 @@
1
- export function csvCell(value,options={}){if(value===null||value===void 0)return"";let text=String(value);if(options.spreadsheetSafe!==!1&&typeof value==="string"&&/^[\s\u0000-\u001F]*[=+@-]/.test(text))text=`'${text}`;return/[",\r\n]/.test(text)?`"${text.replace(/"/g,'""')}"`:text}export function toCsv(header,rows,options={}){return(options.bom?"\uFEFF":"")+[header,...rows].map((row)=>row.map((cell)=>csvCell(cell,options)).join(",")).join(`\r
1
+ export function csvCell(value,options={}){if(value===null||value===undefined)return"";let text=String(value);if(options.spreadsheetSafe!==false&&typeof value==="string"&&/^[\s\u0000-\u001F]*[=+@-]/.test(text))text=`'${text}`;return/[",\r\n]/.test(text)?`"${text.replace(/"/g,'""')}"`:text}export function toCsv(header,rows,options={}){return(options.bom?"\uFEFF":"")+[header,...rows].map((row)=>row.map((cell)=>csvCell(cell,options)).join(",")).join(`\r
2
2
  `)}
@@ -1 +1 @@
1
- const INDENT_REGEX=/^(?:( )+|\t+)/,INDENT_TYPE_SPACE="space",INDENT_TYPE_TAB="tab";function makeIndentsMap(string,ignoreSingleSpaces=!0){const indents=new Map;let previousSize=0,previousIndentType,key="";for(const line of string.split(/\n/g)){if(!line)continue;let indent,indentType,use,weight,entry;const matches=line.match(INDENT_REGEX);if(matches===null){previousSize=0;previousIndentType=""}else{indent=matches[0].length;indentType=matches[1]?INDENT_TYPE_SPACE:INDENT_TYPE_TAB;if(ignoreSingleSpaces&&indentType===INDENT_TYPE_SPACE&&indent===1)continue;if(indentType!==previousIndentType)previousSize=0;previousIndentType=indentType;use=1;weight=0;const indentDifference=indent-previousSize;previousSize=indent;if(indentDifference===0){use=0;weight=1}else{const absoluteIndentDifference=indentDifference>0?indentDifference:-indentDifference;key=encodeIndentsKey(indentType,absoluteIndentDifference)}entry=indents.get(key);entry=entry===void 0?[1,0]:[entry[0]+use,entry[1]+weight];indents.set(key,entry)}}return indents}function encodeIndentsKey(indentType,indentAmount){return(indentType===INDENT_TYPE_SPACE?"s":"t")+String(indentAmount)}function decodeIndentsKey(indentsKey){const type=indentsKey[0]==="s"?INDENT_TYPE_SPACE:INDENT_TYPE_TAB,amount=Number(indentsKey.slice(1));return{type,amount}}function getMostUsedKey(indents){let result,maxUsed=0,maxWeight=0;for(const[key,[usedCount,weight]]of indents)if(usedCount>maxUsed||usedCount===maxUsed&&weight>maxWeight){maxUsed=usedCount;maxWeight=weight;result=key}return result}function makeIndentString(type,amount){return(type===INDENT_TYPE_SPACE?" ":"\t").repeat(amount)}export function detectIndent(string){if(typeof string!=="string")throw TypeError("Expected a string");let indents=makeIndentsMap(string,!0);if(indents.size===0)indents=makeIndentsMap(string,!1);const keyOfMostUsedIndent=getMostUsedKey(indents),decoded=keyOfMostUsedIndent!==void 0?decodeIndentsKey(keyOfMostUsedIndent):void 0,type=decoded?.type,amount=decoded?.amount??0,indent=decoded?makeIndentString(type,amount):"";return{amount,type,indent}}export default detectIndent;
1
+ const INDENT_REGEX=/^(?:( )+|\t+)/;const INDENT_TYPE_SPACE="space";const INDENT_TYPE_TAB="tab";function makeIndentsMap(string,ignoreSingleSpaces=true){const indents=new Map;let previousSize=0;let previousIndentType;let key="";for(const line of string.split(/\n/g)){if(!line){continue}let indent;let indentType;let use;let weight;let entry;const matches=line.match(INDENT_REGEX);if(matches===null){previousSize=0;previousIndentType=""}else{indent=matches[0].length;indentType=matches[1]?INDENT_TYPE_SPACE:INDENT_TYPE_TAB;if(ignoreSingleSpaces&&indentType===INDENT_TYPE_SPACE&&indent===1){continue}if(indentType!==previousIndentType){previousSize=0}previousIndentType=indentType;use=1;weight=0;const indentDifference=indent-previousSize;previousSize=indent;if(indentDifference===0){use=0;weight=1}else{const absoluteIndentDifference=indentDifference>0?indentDifference:-indentDifference;key=encodeIndentsKey(indentType,absoluteIndentDifference)}entry=indents.get(key);entry=entry===undefined?[1,0]:[entry[0]+use,entry[1]+weight];indents.set(key,entry)}}return indents}function encodeIndentsKey(indentType,indentAmount){const typeCharacter=indentType===INDENT_TYPE_SPACE?"s":"t";return typeCharacter+String(indentAmount)}function decodeIndentsKey(indentsKey){const keyHasTypeSpace=indentsKey[0]==="s";const type=keyHasTypeSpace?INDENT_TYPE_SPACE:INDENT_TYPE_TAB;const amount=Number(indentsKey.slice(1));return{type,amount}}function getMostUsedKey(indents){let result;let maxUsed=0;let maxWeight=0;for(const[key,[usedCount,weight]]of indents){if(usedCount>maxUsed||usedCount===maxUsed&&weight>maxWeight){maxUsed=usedCount;maxWeight=weight;result=key}}return result}function makeIndentString(type,amount){const indentCharacter=type===INDENT_TYPE_SPACE?" ":"\t";return indentCharacter.repeat(amount)}export function detectIndent(string){if(typeof string!=="string"){throw new TypeError("Expected a string")}let indents=makeIndentsMap(string,true);if(indents.size===0){indents=makeIndentsMap(string,false)}const keyOfMostUsedIndent=getMostUsedKey(indents);const decoded=keyOfMostUsedIndent!==undefined?decodeIndentsKey(keyOfMostUsedIndent):undefined;const type=decoded?.type;const amount=decoded?.amount??0;const indent=decoded?makeIndentString(type,amount):"";return{amount,type,indent}}export default detectIndent;
@@ -1,5 +1,5 @@
1
- export function detectNewline(string){if(typeof string!=="string")throw TypeError("Expected a string");const newlines=string.match(/\r?\n/g)||[];if(newlines.length===0)return;const crlf=newlines.filter((newline)=>newline===`\r
2
- `).length,lf=newlines.length-crlf;return crlf>lf?`\r
1
+ export function detectNewline(string){if(typeof string!=="string"){throw new TypeError("Expected a string")}const newlines=string.match(/\r?\n/g)||[];if(newlines.length===0){return}const crlf=newlines.filter((newline)=>newline===`\r
2
+ `).length;const lf=newlines.length-crlf;return crlf>lf?`\r
3
3
  `:`
4
4
  `}export function detectNewlineGraceful(string){return typeof string==="string"&&detectNewline(string)||`
5
5
  `}
package/dist/helpers.js CHANGED
@@ -1 +1 @@
1
- export function toString(v){return Object.prototype.toString.call(v)}export function mask(value,character,index,length){if(!Number.isSafeInteger(index)||length!==void 0&&!Number.isSafeInteger(length))throw RangeError("Mask coordinates must be safe integers");if(character==="")return value;const chars=Array.from(value),len=chars.length,start=index<0?Math.max(0,len+index):index;if(start>=len)return value;const maskLen=length===void 0?len-start:Math.max(0,length);if(maskLen===0)return value;const end=Math.min(len,start+maskLen),fill=(Array.from(character)[0]??"").repeat(end-start);return chars.slice(0,start).join("")+fill+chars.slice(end).join("")}
1
+ export function toString(v){return Object.prototype.toString.call(v)}export function mask(value,character,index,length){if(!Number.isSafeInteger(index)||length!==undefined&&!Number.isSafeInteger(length))throw new RangeError("Mask coordinates must be safe integers");if(character==="")return value;const chars=Array.from(value);const len=chars.length;const start=index<0?Math.max(0,len+index):index;if(start>=len)return value;const maskLen=length===undefined?len-start:Math.max(0,length);if(maskLen===0)return value;const end=Math.min(len,start+maskLen);const fill=(Array.from(character)[0]??"").repeat(end-start);return chars.slice(0,start).join("")+fill+chars.slice(end).join("")}
package/dist/macro.js CHANGED
@@ -1 +1 @@
1
- import*as c from"./case";import p from"./pluralize";import*as u from"./utils";export const Str={slash(str){return u.slash(str)},ensurePrefix(prefix,str){return u.ensurePrefix(prefix,str)},ensureSuffix(suffix,str){return u.ensureSuffix(suffix,str)},template(str,...args){return u.template(str,...args)},truncate(str,length,end="..."){return u.truncate(str,length,end)},random(length=16,dict){return u.random(length,dict)},capitalize(str){return c.capitalize(str)},slug(str){return u.slug(str)},detectIndent(str){return u.detectIndent(str)},detectNewline(str){return u.detectNewline(str)},camelCase(str){return c.camelCase(str)},capitalCase(str){return c.capitalCase(str)},constantCase(str){return c.constantCase(str)},dotCase(str){return c.dotCase(str)},noCase(str){return c.noCase(str)},paramCase(str){return c.paramCase(str)},pascalCase(str){return c.pascalCase(str)},pathCase(str){return c.pathCase(str)},sentenceCase(str){return c.sentenceCase(str)},snakeCase(str){return c.snakeCase(str)},titleCase(str){return c.titleCase(str)},kebabCase(str){return c.kebabCase(str)},plural(str){return p.plural(str)},singular(str){return p.singular(str)},isPlural(str){return p.isPlural(str)},isSingular(str){return p.isSingular(str)},addPluralRule(rule,repl){p.addPluralRule(rule,repl)},addSingularRule(rule,repl){p.addSingularRule(rule,repl)},addIrregularRule(single,plural){p.addIrregularRule(single,plural)},addUncountableRule(word){p.addUncountableRule(word)}},str=Str;
1
+ import*as c from"./case";import p from"./pluralize";import*as u from"./utils";export const Str={slash(str){return u.slash(str)},ensurePrefix(prefix,str){return u.ensurePrefix(prefix,str)},ensureSuffix(suffix,str){return u.ensureSuffix(suffix,str)},template(str,...args){return u.template(str,...args)},truncate(str,length,end="..."){return u.truncate(str,length,end)},random(length=16,dict){return u.random(length,dict)},capitalize(str){return c.capitalize(str)},slug(str){return u.slug(str)},detectIndent(str){return u.detectIndent(str)},detectNewline(str){return u.detectNewline(str)},camelCase(str){return c.camelCase(str)},capitalCase(str){return c.capitalCase(str)},constantCase(str){return c.constantCase(str)},dotCase(str){return c.dotCase(str)},noCase(str){return c.noCase(str)},paramCase(str){return c.paramCase(str)},pascalCase(str){return c.pascalCase(str)},pathCase(str){return c.pathCase(str)},sentenceCase(str){return c.sentenceCase(str)},snakeCase(str){return c.snakeCase(str)},titleCase(str){return c.titleCase(str)},kebabCase(str){return c.kebabCase(str)},plural(str){return p.plural(str)},singular(str){return p.singular(str)},isPlural(str){return p.isPlural(str)},isSingular(str){return p.isSingular(str)},addPluralRule(rule,repl){p.addPluralRule(rule,repl)},addSingularRule(rule,repl){p.addSingularRule(rule,repl)},addIrregularRule(single,plural){p.addIrregularRule(single,plural)},addUncountableRule(word){p.addUncountableRule(word)}};export const str=Str;
package/dist/pluralize.js CHANGED
@@ -1 +1 @@
1
- const pluralRules=[],singularRules=[],uncountables={},irregularPlurals={},irregularSingles={};function sanitizeRule(rule){return typeof rule==="string"?new RegExp(`^${rule}$`,"i"):rule}function restoreCase(word,token){if(word===token)return token;if(word===word.toLowerCase())return token.toLowerCase();if(word===word.toUpperCase())return token.toUpperCase();const firstChar=word[0];if(firstChar!==void 0&&firstChar===firstChar.toUpperCase())return token.charAt(0).toUpperCase()+token.slice(1).toLowerCase();return token.toLowerCase()}function interpolate(str,...args){return str.replace(/\$(\d{1,2})/g,(_match,index)=>args[Number(index)]||"")}function replace(word,rule){return word.replace(rule[0],(...matchArgs)=>{const result=interpolate(rule[1],...matchArgs);if(matchArgs[0]==="")return restoreCase(word[matchArgs[matchArgs.length-2]-1]??"",result);return restoreCase(matchArgs[0],result)})}function sanitizeWord(token,word,rules){if(!token.length||uncountables[token])return word;for(let i=rules.length-1;i>=0;i--){const rule=rules[i];if(rule&&rule[0].test(word))return replace(word,rule)}return word}function replaceWord(replaceMap,keepMap,rules){return(word)=>{const token=word.toLowerCase();if(keepMap[token])return restoreCase(word,token);if(replaceMap[token])return restoreCase(word,replaceMap[token]);return sanitizeWord(token,word,rules)}}function checkWord(replaceMap,keepMap,rules){return(word)=>{const token=word.toLowerCase();if(keepMap[token])return!0;if(replaceMap[token])return!1;return sanitizeWord(token,token,rules)===token}}export const pluralize=(word,options={})=>{const{count=2,inclusive=!1}=options;if(typeof word!=="string")throw TypeError("Word must be a string");const pluralized=count===1?pluralize.singular(word):pluralize.plural(word);return inclusive?`${count} ${pluralized}`:pluralized},singular=(word)=>{return pluralize.singular(word)},plural=(word,count=2)=>{return pluralize(word,{count})};pluralize.plural=replaceWord(irregularSingles,irregularPlurals,pluralRules);pluralize.isPlural=checkWord(irregularSingles,irregularPlurals,pluralRules);pluralize.singular=replaceWord(irregularPlurals,irregularSingles,singularRules);pluralize.isSingular=checkWord(irregularPlurals,irregularSingles,singularRules);pluralize.addPluralRule=(rule,replacement)=>{pluralRules.push([sanitizeRule(rule),replacement])};pluralize.addSingularRule=(rule,replacement)=>{singularRules.push([sanitizeRule(rule),replacement])};pluralize.addUncountableRule=(word)=>{if(typeof word==="string"){uncountables[word.toLowerCase()]=!0;return}pluralize.addPluralRule(word,"$0");pluralize.addSingularRule(word,"$0")};pluralize.addIrregularRule=(single,plural)=>{const lowerPlural=plural.toLowerCase(),lowerSingle=single.toLowerCase();irregularSingles[lowerSingle]=lowerPlural;irregularPlurals[lowerPlural]=lowerSingle};[["I","we"],["me","us"],["he","they"],["she","they"],["them","them"],["myself","ourselves"],["yourself","yourselves"],["itself","themselves"],["herself","themselves"],["himself","themselves"],["themself","themselves"],["is","are"],["was","were"],["has","have"],["this","these"],["that","those"],["my","our"],["its","their"],["his","their"],["her","their"],["echo","echoes"],["dingo","dingoes"],["volcano","volcanoes"],["tornado","tornadoes"],["torpedo","torpedoes"],["genus","genera"],["viscus","viscera"],["stigma","stigmata"],["stoma","stomata"],["dogma","dogmata"],["lemma","lemmata"],["schema","schemata"],["anathema","anathemata"],["ox","oxen"],["axe","axes"],["die","dice"],["yes","yeses"],["foot","feet"],["eave","eaves"],["goose","geese"],["tooth","teeth"],["quiz","quizzes"],["human","humans"],["proof","proofs"],["carve","carves"],["valve","valves"],["looey","looies"],["thief","thieves"],["groove","grooves"],["pickaxe","pickaxes"],["passerby","passersby"],["canvas","canvases"]].forEach(([single,plural])=>pluralize.addIrregularRule(single??"",plural??""));[[/s?$/i,"s"],[/[^\x20-\x7F]$/,"$0"],[/([^aeiou]ese)$/i,"$1"],[/(ax|test)is$/i,"$1es"],[/(alias|[^aou]us|t[lm]as|gas|ris)$/i,"$1es"],[/(e[mn]u)s?$/i,"$1s"],[/([^l]ias|[aeiou]las|[ejzr]as|[iu]am)$/i,"$1"],[/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i,"$1i"],[/(alumn|alg|vertebr)(?:a|ae)$/i,"$1ae"],[/(seraph|cherub)(?:im)?$/i,"$1im"],[/(her|at|gr)o$/i,"$1oes"],[/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|automat|quor)(?:a|um)$/i,"$1a"],[/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)(?:a|on)$/i,"$1a"],[/sis$/i,"ses"],[/(?:(kni|wi|li)fe|(ar|l|ea|eo|oa|hoo)f)$/i,"$1$2ves"],[/([^aeiouy]|qu)y$/i,"$1ies"],[/([^ch][ieo][ln])ey$/i,"$1ies"],[/(x|ch|ss|sh|zz)$/i,"$1es"],[/(matr|cod|mur|sil|vert|ind|append)(?:ix|ex)$/i,"$1ices"],[/\b((?:tit)?m|l)(?:ice|ouse)$/i,"$1ice"],[/(pe)(?:rson|ople)$/i,"$1ople"],[/(child)(?:ren)?$/i,"$1ren"],[/eaux$/i,"$0"],[/m[ae]n$/i,"men"],["thou","you"]].forEach(([rule,replacement])=>{if(rule===void 0)return;pluralize.addPluralRule(rule,replacement)});[[/s$/i,""],[/(ss)$/i,"$1"],[/(wi|kni|(?:after|half|high|low|mid|non|night|\W|^)li)ves$/i,"$1fe"],[/(ar|(?:wo|[ae])l|[eo][ao])ves$/i,"$1f"],[/ies$/i,"y"],[/(dg|ss|ois|lk|ok|wn|mb|th|ch|ec|oal|is|ck|ix|sser|ts|wb)ies$/i,"$1ie"],[/\b(l|(?:neck|cross|hog|aun)?t|coll|faer|food|gen|goon|group|hipp|junk|vegg|(?:pork)?p|charl|calor|cut)ies$/i,"$1ie"],[/\b(mon|smil)ies$/i,"$1ey"],[/\b((?:tit)?m|l)ice$/i,"$1ouse"],[/(seraph|cherub)im$/i,"$1"],[/(x|ch|ss|sh|zz|tto|go|cho|alias|[^aou]us|t[lm]as|gas|(?:her|at|gr)o|[aeiou]ris)(?:es)?$/i,"$1"],[/(analy|diagno|parenthe|progno|synop|the|empha|cri|ne)(?:sis|ses)$/i,"$1sis"],[/(movie|twelve|abuse|e[mn]u)s$/i,"$1"],[/(test)(?:is|es)$/i,"$1is"],[/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i,"$1us"],[/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|quor)a$/i,"$1um"],[/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)a$/i,"$1on"],[/(alumn|alg|vertebr)ae$/i,"$1a"],[/(cod|mur|sil|vert|ind)ices$/i,"$1ex"],[/(matr|append)ices$/i,"$1ix"],[/(pe)(rson|ople)$/i,"$1rson"],[/(child)ren$/i,"$1"],[/(eau)x?$/i,"$1"],[/men$/i,"man"]].forEach(([rule,replacement])=>{if(rule===void 0)return;pluralize.addSingularRule(rule,replacement)});["adulthood","advice","agenda","aid","aircraft","alcohol","ammo","analytics","anime","athletics","audio","bison","blood","bream","buffalo","butter","carp","cash","chassis","chess","clothing","cod","commerce","cooperation","corps","debris","diabetes","digestion","elk","energy","equipment","excretion","expertise","firmware","flounder","fun","gallows","garbage","graffiti","hardware","headquarters","health","herpes","highjinks","homework","housework","information","jeans","justice","kudos","labour","literature","machinery","mackerel","mail","media","mews","moose","music","mud","manga","news","only","personnel","pike","plankton","pliers","police","pollution","premises","rain","research","rice","salmon","scissors","series","sewage","shambles","shrimp","software","staff","swine","tennis","traffic","transportation","trout","tuna","wealth","welfare","whiting","wildebeest","wildlife","you",/pok[e\u00E9]mon$/i,/[^aeiou]ese$/i,/deer$/i,/fish$/i,/measles$/i,/o[iu]s$/i,/pox$/i,/sheep$/i].forEach(pluralize.addUncountableRule);export default pluralize;
1
+ const pluralRules=[];const singularRules=[];const uncountables={};const irregularPlurals={};const irregularSingles={};function sanitizeRule(rule){return typeof rule==="string"?new RegExp(`^${rule}$`,"i"):rule}function restoreCase(word,token){if(word===token)return token;if(word===word.toLowerCase())return token.toLowerCase();if(word===word.toUpperCase())return token.toUpperCase();const firstChar=word[0];if(firstChar!==undefined&&firstChar===firstChar.toUpperCase()){return token.charAt(0).toUpperCase()+token.slice(1).toLowerCase()}return token.toLowerCase()}function interpolate(str,...args){return str.replace(/\$(\d{1,2})/g,(_match,index)=>args[Number(index)]||"")}function replace(word,rule){return word.replace(rule[0],(...matchArgs)=>{const result=interpolate(rule[1],...matchArgs);if(matchArgs[0]===""){return restoreCase(word[matchArgs[matchArgs.length-2]-1]??"",result)}return restoreCase(matchArgs[0],result)})}function sanitizeWord(token,word,rules){if(!token.length||uncountables[token]){return word}for(let i=rules.length-1;i>=0;i--){const rule=rules[i];if(rule&&rule[0].test(word))return replace(word,rule)}return word}function replaceWord(replaceMap,keepMap,rules){return(word)=>{const token=word.toLowerCase();if(keepMap[token])return restoreCase(word,token);if(replaceMap[token])return restoreCase(word,replaceMap[token]);return sanitizeWord(token,word,rules)}}function checkWord(replaceMap,keepMap,rules){return(word)=>{const token=word.toLowerCase();if(keepMap[token])return true;if(replaceMap[token])return false;return sanitizeWord(token,token,rules)===token}}export const pluralize=(word,options={})=>{const{count=2,inclusive=false}=options;if(typeof word!=="string"){throw new TypeError("Word must be a string")}const pluralized=count===1?pluralize.singular(word):pluralize.plural(word);return inclusive?`${count} ${pluralized}`:pluralized};export const singular=(word)=>{return pluralize.singular(word)};export const plural=(word,count=2)=>{return pluralize(word,{count})};pluralize.plural=replaceWord(irregularSingles,irregularPlurals,pluralRules);pluralize.isPlural=checkWord(irregularSingles,irregularPlurals,pluralRules);pluralize.singular=replaceWord(irregularPlurals,irregularSingles,singularRules);pluralize.isSingular=checkWord(irregularPlurals,irregularSingles,singularRules);pluralize.addPluralRule=(rule,replacement)=>{pluralRules.push([sanitizeRule(rule),replacement])};pluralize.addSingularRule=(rule,replacement)=>{singularRules.push([sanitizeRule(rule),replacement])};pluralize.addUncountableRule=(word)=>{if(typeof word==="string"){uncountables[word.toLowerCase()]=true;return}pluralize.addPluralRule(word,"$0");pluralize.addSingularRule(word,"$0")};pluralize.addIrregularRule=(single,plural)=>{const lowerPlural=plural.toLowerCase();const lowerSingle=single.toLowerCase();irregularSingles[lowerSingle]=lowerPlural;irregularPlurals[lowerPlural]=lowerSingle};[["I","we"],["me","us"],["he","they"],["she","they"],["them","them"],["myself","ourselves"],["yourself","yourselves"],["itself","themselves"],["herself","themselves"],["himself","themselves"],["themself","themselves"],["is","are"],["was","were"],["has","have"],["this","these"],["that","those"],["my","our"],["its","their"],["his","their"],["her","their"],["echo","echoes"],["dingo","dingoes"],["volcano","volcanoes"],["tornado","tornadoes"],["torpedo","torpedoes"],["genus","genera"],["viscus","viscera"],["stigma","stigmata"],["stoma","stomata"],["dogma","dogmata"],["lemma","lemmata"],["schema","schemata"],["anathema","anathemata"],["ox","oxen"],["axe","axes"],["die","dice"],["yes","yeses"],["foot","feet"],["eave","eaves"],["goose","geese"],["tooth","teeth"],["quiz","quizzes"],["human","humans"],["proof","proofs"],["carve","carves"],["valve","valves"],["looey","looies"],["thief","thieves"],["groove","grooves"],["pickaxe","pickaxes"],["passerby","passersby"],["canvas","canvases"]].forEach(([single,plural])=>pluralize.addIrregularRule(single??"",plural??""));[[/s?$/i,"s"],[/[^\x20-\x7F]$/,"$0"],[/([^aeiou]ese)$/i,"$1"],[/(ax|test)is$/i,"$1es"],[/(alias|[^aou]us|t[lm]as|gas|ris)$/i,"$1es"],[/(e[mn]u)s?$/i,"$1s"],[/([^l]ias|[aeiou]las|[ejzr]as|[iu]am)$/i,"$1"],[/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i,"$1i"],[/(alumn|alg|vertebr)(?:a|ae)$/i,"$1ae"],[/(seraph|cherub)(?:im)?$/i,"$1im"],[/(her|at|gr)o$/i,"$1oes"],[/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|automat|quor)(?:a|um)$/i,"$1a"],[/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)(?:a|on)$/i,"$1a"],[/sis$/i,"ses"],[/(?:(kni|wi|li)fe|(ar|l|ea|eo|oa|hoo)f)$/i,"$1$2ves"],[/([^aeiouy]|qu)y$/i,"$1ies"],[/([^ch][ieo][ln])ey$/i,"$1ies"],[/(x|ch|ss|sh|zz)$/i,"$1es"],[/(matr|cod|mur|sil|vert|ind|append)(?:ix|ex)$/i,"$1ices"],[/\b((?:tit)?m|l)(?:ice|ouse)$/i,"$1ice"],[/(pe)(?:rson|ople)$/i,"$1ople"],[/(child)(?:ren)?$/i,"$1ren"],[/eaux$/i,"$0"],[/m[ae]n$/i,"men"],["thou","you"]].forEach(([rule,replacement])=>{if(rule===undefined)return;pluralize.addPluralRule(rule,replacement)});[[/s$/i,""],[/(ss)$/i,"$1"],[/(wi|kni|(?:after|half|high|low|mid|non|night|\W|^)li)ves$/i,"$1fe"],[/(ar|(?:wo|[ae])l|[eo][ao])ves$/i,"$1f"],[/ies$/i,"y"],[/(dg|ss|ois|lk|ok|wn|mb|th|ch|ec|oal|is|ck|ix|sser|ts|wb)ies$/i,"$1ie"],[/\b(l|(?:neck|cross|hog|aun)?t|coll|faer|food|gen|goon|group|hipp|junk|vegg|(?:pork)?p|charl|calor|cut)ies$/i,"$1ie"],[/\b(mon|smil)ies$/i,"$1ey"],[/\b((?:tit)?m|l)ice$/i,"$1ouse"],[/(seraph|cherub)im$/i,"$1"],[/(x|ch|ss|sh|zz|tto|go|cho|alias|[^aou]us|t[lm]as|gas|(?:her|at|gr)o|[aeiou]ris)(?:es)?$/i,"$1"],[/(analy|diagno|parenthe|progno|synop|the|empha|cri|ne)(?:sis|ses)$/i,"$1sis"],[/(movie|twelve|abuse|e[mn]u)s$/i,"$1"],[/(test)(?:is|es)$/i,"$1is"],[/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i,"$1us"],[/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|quor)a$/i,"$1um"],[/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)a$/i,"$1on"],[/(alumn|alg|vertebr)ae$/i,"$1a"],[/(cod|mur|sil|vert|ind)ices$/i,"$1ex"],[/(matr|append)ices$/i,"$1ix"],[/(pe)(rson|ople)$/i,"$1rson"],[/(child)ren$/i,"$1"],[/(eau)x?$/i,"$1"],[/men$/i,"man"]].forEach(([rule,replacement])=>{if(rule===undefined)return;pluralize.addSingularRule(rule,replacement)});["adulthood","advice","agenda","aid","aircraft","alcohol","ammo","analytics","anime","athletics","audio","bison","blood","bream","buffalo","butter","carp","cash","chassis","chess","clothing","cod","commerce","cooperation","corps","debris","diabetes","digestion","elk","energy","equipment","excretion","expertise","firmware","flounder","fun","gallows","garbage","graffiti","hardware","headquarters","health","herpes","highjinks","homework","housework","information","jeans","justice","kudos","labour","literature","machinery","mackerel","mail","media","mews","moose","music","mud","manga","news","only","personnel","pike","plankton","pliers","police","pollution","premises","rain","research","rice","salmon","scissors","series","sewage","shambles","shrimp","software","staff","swine","tennis","traffic","transportation","trout","tuna","wealth","welfare","whiting","wildebeest","wildlife","you",/pok[eé]mon$/i,/[^aeiou]ese$/i,/deer$/i,/fish$/i,/measles$/i,/o[iu]s$/i,/pox$/i,/sheep$/i].forEach(pluralize.addUncountableRule);export default pluralize;
package/dist/slug.js CHANGED
@@ -1 +1 @@
1
- const DASH=/^\p{Pd}$/u,charMap=JSON.parse('{"$":"dollar","%":"percent","&":"and","<":"less",">":"greater","|":"or","\xA2":"cent","\xA3":"pound","\xA4":"currency","\xA5":"yen","\xA9":"(c)","\xAA":"a","\xAE":"(r)","\xBA":"o","\xC0":"A","\xC1":"A","\xC2":"A","\xC3":"A","\xC4":"A","\xC5":"A","\xC6":"AE","\xC7":"C","\xC8":"E","\xC9":"E","\xCA":"E","\xCB":"E","\xCC":"I","\xCD":"I","\xCE":"I","\xCF":"I","\xD0":"D","\xD1":"N","\xD2":"O","\xD3":"O","\xD4":"O","\xD5":"O","\xD6":"O","\xD8":"O","\xD9":"U","\xDA":"U","\xDB":"U","\xDC":"U","\xDD":"Y","\xDE":"TH","\xDF":"ss","\xE0":"a","\xE1":"a","\xE2":"a","\xE3":"a","\xE4":"a","\xE5":"a","\xE6":"ae","\xE7":"c","\xE8":"e","\xE9":"e","\xEA":"e","\xEB":"e","\xEC":"i","\xED":"i","\xEE":"i","\xEF":"i","\xF0":"d","\xF1":"n","\xF2":"o","\xF3":"o","\xF4":"o","\xF5":"o","\xF6":"o","\xF8":"o","\xF9":"u","\xFA":"u","\xFB":"u","\xFC":"u","\xFD":"y","\xFE":"th","\xFF":"y","\u0100":"A","\u0101":"a","\u0102":"A","\u0103":"a","\u0104":"A","\u0105":"a","\u0106":"C","\u0107":"c","\u010C":"C","\u010D":"c","\u010E":"D","\u010F":"d","\u0110":"DJ","\u0111":"dj","\u0112":"E","\u0113":"e","\u0116":"E","\u0117":"e","\u0118":"e","\u0119":"e","\u011A":"E","\u011B":"e","\u011E":"G","\u011F":"g","\u0122":"G","\u0123":"g","\u0128":"I","\u0129":"i","\u012A":"i","\u012B":"i","\u012E":"I","\u012F":"i","\u0130":"I","\u0131":"i","\u0136":"k","\u0137":"k","\u013B":"L","\u013C":"l","\u013D":"L","\u013E":"l","\u0141":"L","\u0142":"l","\u0143":"N","\u0144":"n","\u0145":"N","\u0146":"n","\u0147":"N","\u0148":"n","\u014C":"O","\u014D":"o","\u0150":"O","\u0151":"o","\u0152":"OE","\u0153":"oe","\u0154":"R","\u0155":"r","\u0158":"R","\u0159":"r","\u015A":"S","\u015B":"s","\u015E":"S","\u015F":"s","\u0160":"S","\u0161":"s","\u0162":"T","\u0163":"t","\u0164":"T","\u0165":"t","\u0168":"U","\u0169":"u","\u016A":"u","\u016B":"u","\u016E":"U","\u016F":"u","\u0170":"U","\u0171":"u","\u0172":"U","\u0173":"u","\u0174":"W","\u0175":"w","\u0176":"Y","\u0177":"y","\u0178":"Y","\u0179":"Z","\u017A":"z","\u017B":"Z","\u017C":"z","\u017D":"Z","\u017E":"z","\u018F":"E","\u0192":"f","\u01A0":"O","\u01A1":"o","\u01AF":"U","\u01B0":"u","\u01C8":"LJ","\u01C9":"lj","\u01CB":"NJ","\u01CC":"nj","\u0218":"S","\u0219":"s","\u021A":"T","\u021B":"t","\u0259":"e","\u02DA":"o","\u0386":"A","\u0388":"E","\u0389":"H","\u038A":"I","\u038C":"O","\u038E":"Y","\u038F":"W","\u0390":"i","\u0391":"A","\u0392":"B","\u0393":"G","\u0394":"D","\u0395":"E","\u0396":"Z","\u0397":"H","\u0398":"8","\u0399":"I","\u039A":"K","\u039B":"L","\u039C":"M","\u039D":"N","\u039E":"3","\u039F":"O","\u03A0":"P","\u03A1":"R","\u03A3":"S","\u03A4":"T","\u03A5":"Y","\u03A6":"F","\u03A7":"X","\u03A8":"PS","\u03A9":"W","\u03AA":"I","\u03AB":"Y","\u03AC":"a","\u03AD":"e","\u03AE":"h","\u03AF":"i","\u03B0":"y","\u03B1":"a","\u03B2":"b","\u03B3":"g","\u03B4":"d","\u03B5":"e","\u03B6":"z","\u03B7":"h","\u03B8":"8","\u03B9":"i","\u03BA":"k","\u03BB":"l","\u03BC":"m","\u03BD":"n","\u03BE":"3","\u03BF":"o","\u03C0":"p","\u03C1":"r","\u03C2":"s","\u03C3":"s","\u03C4":"t","\u03C5":"y","\u03C6":"f","\u03C7":"x","\u03C8":"ps","\u03C9":"w","\u03CA":"i","\u03CB":"y","\u03CC":"o","\u03CD":"y","\u03CE":"w","\u0401":"Yo","\u0402":"DJ","\u0404":"Ye","\u0406":"I","\u0407":"Yi","\u0408":"J","\u0409":"LJ","\u040A":"NJ","\u040B":"C","\u040F":"DZ","\u0410":"A","\u0411":"B","\u0412":"V","\u0413":"G","\u0414":"D","\u0415":"E","\u0416":"Zh","\u0417":"Z","\u0418":"I","\u0419":"J","\u041A":"K","\u041B":"L","\u041C":"M","\u041D":"N","\u041E":"O","\u041F":"P","\u0420":"R","\u0421":"S","\u0422":"T","\u0423":"U","\u0424":"F","\u0425":"H","\u0426":"C","\u0427":"Ch","\u0428":"Sh","\u0429":"Sh","\u042A":"U","\u042B":"Y","\u042C":"","\u042D":"E","\u042E":"Yu","\u042F":"Ya","\u0430":"a","\u0431":"b","\u0432":"v","\u0433":"g","\u0434":"d","\u0435":"e","\u0436":"zh","\u0437":"z","\u0438":"i","\u0439":"j","\u043A":"k","\u043B":"l","\u043C":"m","\u043D":"n","\u043E":"o","\u043F":"p","\u0440":"r","\u0441":"s","\u0442":"t","\u0443":"u","\u0444":"f","\u0445":"h","\u0446":"c","\u0447":"ch","\u0448":"sh","\u0449":"sh","\u044A":"u","\u044B":"y","\u044C":"","\u044D":"e","\u044E":"yu","\u044F":"ya","\u0451":"yo","\u0452":"dj","\u0454":"ye","\u0456":"i","\u0457":"yi","\u0458":"j","\u0459":"lj","\u045A":"nj","\u045B":"c","\u045D":"u","\u045F":"dz","\u0490":"G","\u0491":"g","\u0492":"GH","\u0493":"gh","\u049A":"KH","\u049B":"kh","\u04A2":"NG","\u04A3":"ng","\u04AE":"UE","\u04AF":"ue","\u04B0":"U","\u04B1":"u","\u04BA":"H","\u04BB":"h","\u04D8":"AE","\u04D9":"ae","\u04E8":"OE","\u04E9":"oe","\u0531":"A","\u0532":"B","\u0533":"G","\u0534":"D","\u0535":"E","\u0536":"Z","\u0537":"E\'","\u0538":"Y\'","\u0539":"T\'","\u053A":"JH","\u053B":"I","\u053C":"L","\u053D":"X","\u053E":"C\'","\u053F":"K","\u0540":"H","\u0541":"D\'","\u0542":"GH","\u0543":"TW","\u0544":"M","\u0545":"Y","\u0546":"N","\u0547":"SH","\u0549":"CH","\u054A":"P","\u054B":"J","\u054C":"R\'","\u054D":"S","\u054E":"V","\u054F":"T","\u0550":"R","\u0551":"C","\u0553":"P\'","\u0554":"Q\'","\u0555":"O\'\'","\u0556":"F","\u0587":"EV","\u0621":"a","\u0622":"aa","\u0623":"a","\u0624":"u","\u0625":"i","\u0626":"e","\u0627":"a","\u0628":"b","\u0629":"h","\u062A":"t","\u062B":"th","\u062C":"j","\u062D":"h","\u062E":"kh","\u062F":"d","\u0630":"th","\u0631":"r","\u0632":"z","\u0633":"s","\u0634":"sh","\u0635":"s","\u0636":"dh","\u0637":"t","\u0638":"z","\u0639":"a","\u063A":"gh","\u0641":"f","\u0642":"q","\u0643":"k","\u0644":"l","\u0645":"m","\u0646":"n","\u0647":"h","\u0648":"w","\u0649":"a","\u064A":"y","\u064B":"an","\u064C":"on","\u064D":"en","\u064E":"a","\u064F":"u","\u0650":"e","\u0652":"","\u0660":"0","\u0661":"1","\u0662":"2","\u0663":"3","\u0664":"4","\u0665":"5","\u0666":"6","\u0667":"7","\u0668":"8","\u0669":"9","\u067E":"p","\u0686":"ch","\u0698":"zh","\u06A9":"k","\u06AF":"g","\u06CC":"y","\u06F0":"0","\u06F1":"1","\u06F2":"2","\u06F3":"3","\u06F4":"4","\u06F5":"5","\u06F6":"6","\u06F7":"7","\u06F8":"8","\u06F9":"9","\u0E3F":"baht","\u10D0":"a","\u10D1":"b","\u10D2":"g","\u10D3":"d","\u10D4":"e","\u10D5":"v","\u10D6":"z","\u10D7":"t","\u10D8":"i","\u10D9":"k","\u10DA":"l","\u10DB":"m","\u10DC":"n","\u10DD":"o","\u10DE":"p","\u10DF":"zh","\u10E0":"r","\u10E1":"s","\u10E2":"t","\u10E3":"u","\u10E4":"f","\u10E5":"k","\u10E6":"gh","\u10E7":"q","\u10E8":"sh","\u10E9":"ch","\u10EA":"ts","\u10EB":"dz","\u10EC":"ts","\u10ED":"ch","\u10EE":"kh","\u10EF":"j","\u10F0":"h","\u1E62":"S","\u1E63":"s","\u1E80":"W","\u1E81":"w","\u1E82":"W","\u1E83":"w","\u1E84":"W","\u1E85":"w","\u1E9E":"SS","\u1EA0":"A","\u1EA1":"a","\u1EA2":"A","\u1EA3":"a","\u1EA4":"A","\u1EA5":"a","\u1EA6":"A","\u1EA7":"a","\u1EA8":"A","\u1EA9":"a","\u1EAA":"A","\u1EAB":"a","\u1EAC":"A","\u1EAD":"a","\u1EAE":"A","\u1EAF":"a","\u1EB0":"A","\u1EB1":"a","\u1EB2":"A","\u1EB3":"a","\u1EB4":"A","\u1EB5":"a","\u1EB6":"A","\u1EB7":"a","\u1EB8":"E","\u1EB9":"e","\u1EBA":"E","\u1EBB":"e","\u1EBC":"E","\u1EBD":"e","\u1EBE":"E","\u1EBF":"e","\u1EC0":"E","\u1EC1":"e","\u1EC2":"E","\u1EC3":"e","\u1EC4":"E","\u1EC5":"e","\u1EC6":"E","\u1EC7":"e","\u1EC8":"I","\u1EC9":"i","\u1ECA":"I","\u1ECB":"i","\u1ECC":"O","\u1ECD":"o","\u1ECE":"O","\u1ECF":"o","\u1ED0":"O","\u1ED1":"o","\u1ED2":"O","\u1ED3":"o","\u1ED4":"O","\u1ED5":"o","\u1ED6":"O","\u1ED7":"o","\u1ED8":"O","\u1ED9":"o","\u1EDA":"O","\u1EDB":"o","\u1EDC":"O","\u1EDD":"o","\u1EDE":"O","\u1EDF":"o","\u1EE0":"O","\u1EE1":"o","\u1EE2":"O","\u1EE3":"o","\u1EE4":"U","\u1EE5":"u","\u1EE6":"U","\u1EE7":"u","\u1EE8":"U","\u1EE9":"u","\u1EEA":"U","\u1EEB":"u","\u1EEC":"U","\u1EED":"u","\u1EEE":"U","\u1EEF":"u","\u1EF0":"U","\u1EF1":"u","\u1EF2":"Y","\u1EF3":"y","\u1EF4":"Y","\u1EF5":"y","\u1EF6":"Y","\u1EF7":"y","\u1EF8":"Y","\u1EF9":"y","\u2018":"\'","\u2019":"\'","\u201C":"\\"","\u201D":"\\"","\u201E":"\\"","\u2020":"+","\u2022":"*","\u2026":"...","\u20A0":"ecu","\u20A2":"cruzeiro","\u20A3":"french franc","\u20A4":"lira","\u20A5":"mill","\u20A6":"naira","\u20A7":"peseta","\u20A8":"rupee","\u20A9":"won","\u20AA":"new shequel","\u20AB":"dong","\u20AC":"euro","\u20AD":"kip","\u20AE":"tugrik","\u20AF":"drachma","\u20B0":"penny","\u20B1":"peso","\u20B2":"guarani","\u20B3":"austral","\u20B4":"hryvnia","\u20B5":"cedi","\u20B8":"kazakhstani tenge","\u20B9":"indian rupee","\u20BA":"turkish lira","\u20BD":"russian ruble","\u20BF":"bitcoin","\u2120":"sm","\u2122":"tm","\u2202":"d","\u2206":"delta","\u2211":"sum","\u221E":"infinity","\u2665":"love","\u5143":"yuan","\u5186":"yen","\uFDFC":"rial","\uFEF5":"laa","\uFEF7":"laa","\uFEF9":"lai","\uFEFB":"la"}'),locales=JSON.parse('{"bg":{"\u0419":"Y","\u0426":"Ts","\u0429":"Sht","\u042A":"A","\u042C":"Y","\u0439":"y","\u0446":"ts","\u0449":"sht","\u044A":"a","\u044C":"y"},"de":{"\xC4":"AE","\xE4":"ae","\xD6":"OE","\xF6":"oe","\xDC":"UE","\xFC":"ue","\xDF":"ss","%":"prozent","&":"und","|":"oder","\u2211":"summe","\u221E":"unendlich","\u2665":"liebe"},"es":{"%":"por ciento","&":"y","<":"menor que",">":"mayor que","|":"o","\xA2":"centavos","\xA3":"libras","\xA4":"moneda","\u20A3":"francos","\u2211":"suma","\u221E":"infinito","\u2665":"amor"},"fr":{"%":"pourcent","&":"et","<":"plus petit",">":"plus grand","|":"ou","\xA2":"centime","\xA3":"livre","\xA4":"devise","\u20A3":"franc","\u2211":"somme","\u221E":"infini","\u2665":"amour"},"pt":{"%":"porcento","&":"e","<":"menor",">":"maior","|":"ou","\xA2":"centavo","\u2211":"soma","\xA3":"libra","\u221E":"infinito","\u2665":"amor"},"uk":{"\u0418":"Y","\u0438":"y","\u0419":"Y","\u0439":"y","\u0426":"Ts","\u0446":"ts","\u0425":"Kh","\u0445":"kh","\u0429":"Shch","\u0449":"shch","\u0413":"H","\u0433":"h"},"vi":{"\u0110":"D","\u0111":"d"},"da":{"\xD8":"OE","\xF8":"oe","\xC5":"AA","\xE5":"aa","%":"procent","&":"og","|":"eller","$":"dollar","<":"mindre end",">":"st\xF8rre end"},"nb":{"&":"og","\xC5":"AA","\xC6":"AE","\xD8":"OE","\xE5":"aa","\xE6":"ae","\xF8":"oe"},"it":{"&":"e"},"nl":{"&":"en"},"sv":{"&":"och","\xC5":"AA","\xC4":"AE","\xD6":"OE","\xE5":"aa","\xE4":"ae","\xF6":"oe"}}');export function slugify(string,options={}){if(typeof string!=="string")throw TypeError("slugify: string argument expected");const{replacement="-",remove=/[^\w\s$*+~.()'"!\-:@]+/g,lower=!1,strict=!1,locale,trim=!0}=options,localeMap=locale?locales[locale]||{}:{},slug=string.normalize().split("").reduce((result,ch)=>{let appendChar=localeMap[ch]??charMap[ch]??ch;appendChar=appendChar===replacement||DASH.test(ch)?" ":appendChar;return result+appendChar},"").replace(remove,""),strictSlug=strict?slug.replace(/[^A-Z0-9\s]/gi,""):slug,finalSlug=(trim?strictSlug.trim():strictSlug).replace(/\s+/g,replacement);return lower?finalSlug.toLowerCase():finalSlug}export function extendCharMap(customMap){Object.assign(charMap,customMap)}
1
+ const DASH=/^\p{Pd}$/u;const charMap=JSON.parse('{"$":"dollar","%":"percent","&":"and","<":"less",">":"greater","|":"or","¢":"cent","£":"pound","¤":"currency","¥":"yen","©":"(c)","ª":"a","®":"(r)","º":"o","À":"A","Á":"A","Â":"A","Ã":"A","Ä":"A","Å":"A","Æ":"AE","Ç":"C","È":"E","É":"E","Ê":"E","Ë":"E","Ì":"I","Í":"I","Î":"I","Ï":"I","Ð":"D","Ñ":"N","Ò":"O","Ó":"O","Ô":"O","Õ":"O","Ö":"O","Ø":"O","Ù":"U","Ú":"U","Û":"U","Ü":"U","Ý":"Y","Þ":"TH","ß":"ss","à":"a","á":"a","â":"a","ã":"a","ä":"a","å":"a","æ":"ae","ç":"c","è":"e","é":"e","ê":"e","ë":"e","ì":"i","í":"i","î":"i","ï":"i","ð":"d","ñ":"n","ò":"o","ó":"o","ô":"o","õ":"o","ö":"o","ø":"o","ù":"u","ú":"u","û":"u","ü":"u","ý":"y","þ":"th","ÿ":"y","Ā":"A","ā":"a","Ă":"A","ă":"a","Ą":"A","ą":"a","Ć":"C","ć":"c","Č":"C","č":"c","Ď":"D","ď":"d","Đ":"DJ","đ":"dj","Ē":"E","ē":"e","Ė":"E","ė":"e","Ę":"e","ę":"e","Ě":"E","ě":"e","Ğ":"G","ğ":"g","Ģ":"G","ģ":"g","Ĩ":"I","ĩ":"i","Ī":"i","ī":"i","Į":"I","į":"i","İ":"I","ı":"i","Ķ":"k","ķ":"k","Ļ":"L","ļ":"l","Ľ":"L","ľ":"l","Ł":"L","ł":"l","Ń":"N","ń":"n","Ņ":"N","ņ":"n","Ň":"N","ň":"n","Ō":"O","ō":"o","Ő":"O","ő":"o","Œ":"OE","œ":"oe","Ŕ":"R","ŕ":"r","Ř":"R","ř":"r","Ś":"S","ś":"s","Ş":"S","ş":"s","Š":"S","š":"s","Ţ":"T","ţ":"t","Ť":"T","ť":"t","Ũ":"U","ũ":"u","Ū":"u","ū":"u","Ů":"U","ů":"u","Ű":"U","ű":"u","Ų":"U","ų":"u","Ŵ":"W","ŵ":"w","Ŷ":"Y","ŷ":"y","Ÿ":"Y","Ź":"Z","ź":"z","Ż":"Z","ż":"z","Ž":"Z","ž":"z","Ə":"E","ƒ":"f","Ơ":"O","ơ":"o","Ư":"U","ư":"u","Lj":"LJ","lj":"lj","Nj":"NJ","nj":"nj","Ș":"S","ș":"s","Ț":"T","ț":"t","ə":"e","˚":"o","Ά":"A","Έ":"E","Ή":"H","Ί":"I","Ό":"O","Ύ":"Y","Ώ":"W","ΐ":"i","Α":"A","Β":"B","Γ":"G","Δ":"D","Ε":"E","Ζ":"Z","Η":"H","Θ":"8","Ι":"I","Κ":"K","Λ":"L","Μ":"M","Ν":"N","Ξ":"3","Ο":"O","Π":"P","Ρ":"R","Σ":"S","Τ":"T","Υ":"Y","Φ":"F","Χ":"X","Ψ":"PS","Ω":"W","Ϊ":"I","Ϋ":"Y","ά":"a","έ":"e","ή":"h","ί":"i","ΰ":"y","α":"a","β":"b","γ":"g","δ":"d","ε":"e","ζ":"z","η":"h","θ":"8","ι":"i","κ":"k","λ":"l","μ":"m","ν":"n","ξ":"3","ο":"o","π":"p","ρ":"r","ς":"s","σ":"s","τ":"t","υ":"y","φ":"f","χ":"x","ψ":"ps","ω":"w","ϊ":"i","ϋ":"y","ό":"o","ύ":"y","ώ":"w","Ё":"Yo","Ђ":"DJ","Є":"Ye","І":"I","Ї":"Yi","Ј":"J","Љ":"LJ","Њ":"NJ","Ћ":"C","Џ":"DZ","А":"A","Б":"B","В":"V","Г":"G","Д":"D","Е":"E","Ж":"Zh","З":"Z","И":"I","Й":"J","К":"K","Л":"L","М":"M","Н":"N","О":"O","П":"P","Р":"R","С":"S","Т":"T","У":"U","Ф":"F","Х":"H","Ц":"C","Ч":"Ch","Ш":"Sh","Щ":"Sh","Ъ":"U","Ы":"Y","Ь":"","Э":"E","Ю":"Yu","Я":"Ya","а":"a","б":"b","в":"v","г":"g","д":"d","е":"e","ж":"zh","з":"z","и":"i","й":"j","к":"k","л":"l","м":"m","н":"n","о":"o","п":"p","р":"r","с":"s","т":"t","у":"u","ф":"f","х":"h","ц":"c","ч":"ch","ш":"sh","щ":"sh","ъ":"u","ы":"y","ь":"","э":"e","ю":"yu","я":"ya","ё":"yo","ђ":"dj","є":"ye","і":"i","ї":"yi","ј":"j","љ":"lj","њ":"nj","ћ":"c","ѝ":"u","џ":"dz","Ґ":"G","ґ":"g","Ғ":"GH","ғ":"gh","Қ":"KH","қ":"kh","Ң":"NG","ң":"ng","Ү":"UE","ү":"ue","Ұ":"U","ұ":"u","Һ":"H","һ":"h","Ә":"AE","ә":"ae","Ө":"OE","ө":"oe","Ա":"A","Բ":"B","Գ":"G","Դ":"D","Ե":"E","Զ":"Z","Է":"E\'","Ը":"Y\'","Թ":"T\'","Ժ":"JH","Ի":"I","Լ":"L","Խ":"X","Ծ":"C\'","Կ":"K","Հ":"H","Ձ":"D\'","Ղ":"GH","Ճ":"TW","Մ":"M","Յ":"Y","Ն":"N","Շ":"SH","Չ":"CH","Պ":"P","Ջ":"J","Ռ":"R\'","Ս":"S","Վ":"V","Տ":"T","Ր":"R","Ց":"C","Փ":"P\'","Ք":"Q\'","Օ":"O\'\'","Ֆ":"F","և":"EV","ء":"a","آ":"aa","أ":"a","ؤ":"u","إ":"i","ئ":"e","ا":"a","ب":"b","ة":"h","ت":"t","ث":"th","ج":"j","ح":"h","خ":"kh","د":"d","ذ":"th","ر":"r","ز":"z","س":"s","ش":"sh","ص":"s","ض":"dh","ط":"t","ظ":"z","ع":"a","غ":"gh","ف":"f","ق":"q","ك":"k","ل":"l","م":"m","ن":"n","ه":"h","و":"w","ى":"a","ي":"y","ً":"an","ٌ":"on","ٍ":"en","َ":"a","ُ":"u","ِ":"e","ْ":"","٠":"0","١":"1","٢":"2","٣":"3","٤":"4","٥":"5","٦":"6","٧":"7","٨":"8","٩":"9","پ":"p","چ":"ch","ژ":"zh","ک":"k","گ":"g","ی":"y","۰":"0","۱":"1","۲":"2","۳":"3","۴":"4","۵":"5","۶":"6","۷":"7","۸":"8","۹":"9","฿":"baht","ა":"a","ბ":"b","გ":"g","დ":"d","ე":"e","ვ":"v","ზ":"z","თ":"t","ი":"i","კ":"k","ლ":"l","მ":"m","ნ":"n","ო":"o","პ":"p","ჟ":"zh","რ":"r","ს":"s","ტ":"t","უ":"u","ფ":"f","ქ":"k","ღ":"gh","ყ":"q","შ":"sh","ჩ":"ch","ც":"ts","ძ":"dz","წ":"ts","ჭ":"ch","ხ":"kh","ჯ":"j","ჰ":"h","Ṣ":"S","ṣ":"s","Ẁ":"W","ẁ":"w","Ẃ":"W","ẃ":"w","Ẅ":"W","ẅ":"w","ẞ":"SS","Ạ":"A","ạ":"a","Ả":"A","ả":"a","Ấ":"A","ấ":"a","Ầ":"A","ầ":"a","Ẩ":"A","ẩ":"a","Ẫ":"A","ẫ":"a","Ậ":"A","ậ":"a","Ắ":"A","ắ":"a","Ằ":"A","ằ":"a","Ẳ":"A","ẳ":"a","Ẵ":"A","ẵ":"a","Ặ":"A","ặ":"a","Ẹ":"E","ẹ":"e","Ẻ":"E","ẻ":"e","Ẽ":"E","ẽ":"e","Ế":"E","ế":"e","Ề":"E","ề":"e","Ể":"E","ể":"e","Ễ":"E","ễ":"e","Ệ":"E","ệ":"e","Ỉ":"I","ỉ":"i","Ị":"I","ị":"i","Ọ":"O","ọ":"o","Ỏ":"O","ỏ":"o","Ố":"O","ố":"o","Ồ":"O","ồ":"o","Ổ":"O","ổ":"o","Ỗ":"O","ỗ":"o","Ộ":"O","ộ":"o","Ớ":"O","ớ":"o","Ờ":"O","ờ":"o","Ở":"O","ở":"o","Ỡ":"O","ỡ":"o","Ợ":"O","ợ":"o","Ụ":"U","ụ":"u","Ủ":"U","ủ":"u","Ứ":"U","ứ":"u","Ừ":"U","ừ":"u","Ử":"U","ử":"u","Ữ":"U","ữ":"u","Ự":"U","ự":"u","Ỳ":"Y","ỳ":"y","Ỵ":"Y","ỵ":"y","Ỷ":"Y","ỷ":"y","Ỹ":"Y","ỹ":"y","‘":"\'","’":"\'","“":"\\"","”":"\\"","„":"\\"","†":"+","•":"*","…":"...","₠":"ecu","₢":"cruzeiro","₣":"french franc","₤":"lira","₥":"mill","₦":"naira","₧":"peseta","₨":"rupee","₩":"won","₪":"new shequel","₫":"dong","€":"euro","₭":"kip","₮":"tugrik","₯":"drachma","₰":"penny","₱":"peso","₲":"guarani","₳":"austral","₴":"hryvnia","₵":"cedi","₸":"kazakhstani tenge","₹":"indian rupee","₺":"turkish lira","₽":"russian ruble","₿":"bitcoin","℠":"sm","™":"tm","∂":"d","∆":"delta","∑":"sum","∞":"infinity","♥":"love","元":"yuan","円":"yen","﷼":"rial","ﻵ":"laa","ﻷ":"laa","ﻹ":"lai","ﻻ":"la"}');const locales=JSON.parse('{"bg":{"Й":"Y","Ц":"Ts","Щ":"Sht","Ъ":"A","Ь":"Y","й":"y","ц":"ts","щ":"sht","ъ":"a","ь":"y"},"de":{"Ä":"AE","ä":"ae","Ö":"OE","ö":"oe","Ü":"UE","ü":"ue","ß":"ss","%":"prozent","&":"und","|":"oder","∑":"summe","∞":"unendlich","♥":"liebe"},"es":{"%":"por ciento","&":"y","<":"menor que",">":"mayor que","|":"o","¢":"centavos","£":"libras","¤":"moneda","₣":"francos","∑":"suma","∞":"infinito","♥":"amor"},"fr":{"%":"pourcent","&":"et","<":"plus petit",">":"plus grand","|":"ou","¢":"centime","£":"livre","¤":"devise","₣":"franc","∑":"somme","∞":"infini","♥":"amour"},"pt":{"%":"porcento","&":"e","<":"menor",">":"maior","|":"ou","¢":"centavo","∑":"soma","£":"libra","∞":"infinito","♥":"amor"},"uk":{"И":"Y","и":"y","Й":"Y","й":"y","Ц":"Ts","ц":"ts","Х":"Kh","х":"kh","Щ":"Shch","щ":"shch","Г":"H","г":"h"},"vi":{"Đ":"D","đ":"d"},"da":{"Ø":"OE","ø":"oe","Å":"AA","å":"aa","%":"procent","&":"og","|":"eller","$":"dollar","<":"mindre end",">":"større end"},"nb":{"&":"og","Å":"AA","Æ":"AE","Ø":"OE","å":"aa","æ":"ae","ø":"oe"},"it":{"&":"e"},"nl":{"&":"en"},"sv":{"&":"och","Å":"AA","Ä":"AE","Ö":"OE","å":"aa","ä":"ae","ö":"oe"}}');export function slugify(string,options={}){if(typeof string!=="string"){throw new TypeError("slugify: string argument expected")}const{replacement="-",remove=/[^\w\s$*+~.()'"!\-:@]+/g,lower=false,strict=false,locale,trim=true}=options;const localeMap=locale?locales[locale]||{}:{};const slug=string.normalize().split("").reduce((result,ch)=>{let appendChar=localeMap[ch]??charMap[ch]??ch;appendChar=appendChar===replacement||DASH.test(ch)?" ":appendChar;return result+appendChar},"").replace(remove,"");const strictSlug=strict?slug.replace(/[^A-Z0-9\s]/gi,""):slug;const trimmedSlug=trim?strictSlug.trim():strictSlug;const finalSlug=trimmedSlug.replace(/\s+/g,replacement);return lower?finalSlug.toLowerCase():finalSlug}export function extendCharMap(customMap){Object.assign(charMap,customMap)}
@@ -1 +1 @@
1
- export function spongeCase(input,locale){let result="";for(const char of input)result+=Math.random()>0.5?char.toLocaleUpperCase(locale):char.toLocaleLowerCase(locale);return result}
1
+ export function spongeCase(input,locale){let result="";for(const char of input){result+=Math.random()>0.5?char.toLocaleUpperCase(locale):char.toLocaleLowerCase(locale)}return result}
@@ -1 +1 @@
1
- const TOKENS=/(\S+)|(.)/g,IS_SPECIAL_CASE=/[.#][\p{L}\p{N}]/u,IS_MANUAL_CASE=/\p{Ll}(?=\p{Lu})/u,ALPHANUMERIC_PATTERN=/[\p{L}\p{N}]+/gu,IS_ACRONYM=/^(\P{L})*(?:\p{L}\.){2,}(\P{L})*$/u;export const WORD_SEPARATORS=new Set(["\u2014","\u2013","-","\u2015","/"]),SENTENCE_TERMINATORS=new Set([".","!","?"]),TITLE_TERMINATORS=new Set([...SENTENCE_TERMINATORS,":",'"',"'","\u201D"]),SMALL_WORDS=new Set(["a","an","and","as","at","because","but","by","en","for","if","in","neither","nor","of","on","only","or","over","per","so","some","than","that","the","to","up","upon","v","versus","via","vs","when","with","without","yet"]);export function titleCase(input,options={}){const{locale=void 0,sentenceCase=!1,sentenceTerminators=SENTENCE_TERMINATORS,titleTerminators=TITLE_TERMINATORS,smallWords=SMALL_WORDS,wordSeparators=WORD_SEPARATORS}=typeof options==="string"||Array.isArray(options)?{locale:options}:options,terminators=sentenceCase?sentenceTerminators:titleTerminators;let result="",isNewSentence=!0;for(const m of input.matchAll(TOKENS)){const{1:token,2:whiteSpace,index=0}=m;if(whiteSpace){result+=whiteSpace;continue}if(token===void 0)continue;if(IS_SPECIAL_CASE.test(token)){const acronym=token.match(IS_ACRONYM);if(acronym){const[_,prefix="",suffix=""]=acronym;result+=sentenceCase&&!isNewSentence?token:upperAt(token,prefix.length,locale);isNewSentence=terminators.has(suffix.charAt(0));continue}result+=token;isNewSentence=terminators.has(token.charAt(token.length-1))}else{const matches=Array.from(token.matchAll(ALPHANUMERIC_PATTERN));let value=token,isSentenceEnd=!1;for(let i=0;i<matches.length;i++){const match=matches[i];if(!match)continue;const{0:word,index:wordIndex=0}=match,nextChar=token.charAt(wordIndex+word.length);isSentenceEnd=terminators.has(nextChar);if(isNewSentence)isNewSentence=!1;else if(sentenceCase||IS_MANUAL_CASE.test(word))continue;else if(matches.length===1){if(smallWords.has(word)){if(index+token.length!==input.length&&!isSentenceEnd)continue}}else if(i>0){if(!wordSeparators.has(token.charAt(wordIndex-1)))continue;if(smallWords.has(word)&&wordSeparators.has(nextChar))continue}value=upperAt(value,wordIndex,locale)}result+=value;isNewSentence=isSentenceEnd||terminators.has(token.charAt(token.length-1))}}return result}function upperAt(input,index,locale){return input.slice(0,index)+input.charAt(index).toLocaleUpperCase(locale)+input.slice(index+1)}
1
+ const TOKENS=/(\S+)|(.)/g;const IS_SPECIAL_CASE=/[.#][\p{L}\p{N}]/u;const IS_MANUAL_CASE=/\p{Ll}(?=\p{Lu})/u;const ALPHANUMERIC_PATTERN=/[\p{L}\p{N}]+/gu;const IS_ACRONYM=/^(\P{L})*(?:\p{L}\.){2,}(\P{L})*$/u;export const WORD_SEPARATORS=new Set(["—","–","-","―","/"]);export const SENTENCE_TERMINATORS=new Set([".","!","?"]);export const TITLE_TERMINATORS=new Set([...SENTENCE_TERMINATORS,":",'"',"'","”"]);export const SMALL_WORDS=new Set(["a","an","and","as","at","because","but","by","en","for","if","in","neither","nor","of","on","only","or","over","per","so","some","than","that","the","to","up","upon","v","versus","via","vs","when","with","without","yet"]);export function titleCase(input,options={}){const{locale=undefined,sentenceCase=false,sentenceTerminators=SENTENCE_TERMINATORS,titleTerminators=TITLE_TERMINATORS,smallWords=SMALL_WORDS,wordSeparators=WORD_SEPARATORS}=typeof options==="string"||Array.isArray(options)?{locale:options}:options;const terminators=sentenceCase?sentenceTerminators:titleTerminators;let result="";let isNewSentence=true;for(const m of input.matchAll(TOKENS)){const{1:token,2:whiteSpace,index=0}=m;if(whiteSpace){result+=whiteSpace;continue}if(token===undefined)continue;if(IS_SPECIAL_CASE.test(token)){const acronym=token.match(IS_ACRONYM);if(acronym){const[_,prefix="",suffix=""]=acronym;result+=sentenceCase&&!isNewSentence?token:upperAt(token,prefix.length,locale);isNewSentence=terminators.has(suffix.charAt(0));continue}result+=token;isNewSentence=terminators.has(token.charAt(token.length-1))}else{const matches=Array.from(token.matchAll(ALPHANUMERIC_PATTERN));let value=token;let isSentenceEnd=false;for(let i=0;i<matches.length;i++){const match=matches[i];if(!match)continue;const{0:word,index:wordIndex=0}=match;const nextChar=token.charAt(wordIndex+word.length);isSentenceEnd=terminators.has(nextChar);if(isNewSentence){isNewSentence=false}else if(sentenceCase||IS_MANUAL_CASE.test(word)){continue}else if(matches.length===1){if(smallWords.has(word)){const isFinalToken=index+token.length===input.length;if(!isFinalToken&&!isSentenceEnd){continue}}}else if(i>0){if(!wordSeparators.has(token.charAt(wordIndex-1))){continue}if(smallWords.has(word)&&wordSeparators.has(nextChar)){continue}}value=upperAt(value,wordIndex,locale)}result+=value;isNewSentence=isSentenceEnd||terminators.has(token.charAt(token.length-1))}}return result}function upperAt(input,index,locale){return input.slice(0,index)+input.charAt(index).toLocaleUpperCase(locale)+input.slice(index+1)}
package/dist/utils.js CHANGED
@@ -1 +1 @@
1
- import{slugify}from"./slug";export const urlAlphabet="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";export function slash(str){return str.replace(/\\/g,"/")}export function ensurePrefix(prefix,str){if(!str.startsWith(prefix))return prefix+str;return str}export function ensureSuffix(suffix,str){return str.endsWith(suffix)?str:str+suffix}export function template(str,...args){return str.replace(/\{(\d+)\}/g,(match,key)=>{const index=Number(key);return Number.isNaN(index)||args[index]===void 0?match:String(args[index])})}export function truncate(str,length,end="..."){const chars=Array.from(str),limit=Math.max(0,Math.floor(length));if(chars.length<=limit)return str;const marker=Array.from(end).slice(0,limit);return chars.slice(0,limit-marker.length).join("")+marker.join("")}export function random(size=16,dict=urlAlphabet){const len=dict.length,g=globalThis;if(!g.crypto?.getRandomValues)throw Error("[strings.random] crypto.getRandomValues is not available; cannot generate secure random string.");const bytes=new Uint8Array(size);g.crypto.getRandomValues(bytes);let id="";for(let i=0;i<size;i++)id+=dict[(bytes[i]??0)%len];return id}export function slug(str,options){if(options)return slugify(str,options);return slugify(str,{lower:!0,strict:!0})}export*from"./detect-indent";export*from"./detect-newline";
1
+ import{slugify}from"./slug";export const urlAlphabet="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";export function slash(str){return str.replace(/\\/g,"/")}export function ensurePrefix(prefix,str){if(!str.startsWith(prefix))return prefix+str;return str}export function ensureSuffix(suffix,str){return str.endsWith(suffix)?str:str+suffix}export function template(str,...args){return str.replace(/\{(\d+)\}/g,(match,key)=>{const index=Number(key);return Number.isNaN(index)||args[index]===undefined?match:String(args[index])})}export function truncate(str,length,end="..."){const chars=Array.from(str);const limit=Math.max(0,Math.floor(length));if(chars.length<=limit)return str;const marker=Array.from(end).slice(0,limit);return chars.slice(0,limit-marker.length).join("")+marker.join("")}export function random(size=16,dict=urlAlphabet){const len=dict.length;const g=globalThis;if(!g.crypto?.getRandomValues)throw new Error("[strings.random] crypto.getRandomValues is not available; cannot generate secure random string.");const bytes=new Uint8Array(size);g.crypto.getRandomValues(bytes);let id="";for(let i=0;i<size;i++)id+=dict[(bytes[i]??0)%len];return id}export function slug(str,options){if(options)return slugify(str,options);return slugify(str,{lower:true,strict:true})}export*from"./detect-indent";export*from"./detect-newline";
@@ -1 +1 @@
1
- export function isEmail(email){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)}export function isStrongPassword(password){if(password.length<8)return!1;const hasUpperCase=/\p{Lu}/u.test(password),hasLowerCase=/\p{Ll}/u.test(password),hasNumber=/\p{N}/u.test(password),hasSymbol=/[^\p{L}\p{N}]/u.test(password);return hasUpperCase&&hasLowerCase&&hasNumber&&hasSymbol}export function isAlphanumeric(str){return/^[a-zA-Z0-9]+$/.test(str)}export function isURL(url){try{const parsed=new URL(url);return parsed.protocol==="http:"||parsed.protocol==="https:"}catch{return!1}}export function isMobilePhone(phoneNumber){const phoneRegex=/^\+?[1-9]\d{6,14}$/,cleaned=phoneNumber.replace(/[\s()-]/g,"");return phoneRegex.test(cleaned)}export function isAlpha(str){return/^[a-zA-Z]+$/.test(str)}export function isPostalCode(zipCode){const usZip=/^\d{5}(?:-\d{4})?$/,ukPostcode=/^[A-Z]{1,2}\d{1,2}[A-Z]?\s?\d[A-Z]{2}$/i,canadaPostcode=/^[A-Z]\d[A-Z]\s?\d[A-Z]\d$/i,generic=/^[a-zA-Z0-9]{3,10}$/;return usZip.test(zipCode)||ukPostcode.test(zipCode)||canadaPostcode.test(zipCode)||generic.test(zipCode)}export function isNumeric(str){return/^\d+$/.test(str)}export function isHexColor(color){return/^#(?:[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(color)}export function isHexadecimal(hex){return/^[A-Fa-f0-9]+$/.test(hex)}export function isBase64(base64){try{return btoa(atob(base64))===base64}catch{return!1}}export function isUUID(uuid){return/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|0{8}-0{4}-0{4}-0{4}-0{12}|f{8}-f{4}-f{4}-f{4}-f{12})$/i.test(uuid)}export function isJSON(json){try{JSON.parse(json);return!0}catch{return!1}}export function isCreditCard(creditCard){const cleaned=creditCard.replace(/[\s-]/g,"");if(!/^\d{13,19}$/.test(cleaned))return!1;let sum=0,isEven=!1;for(let i=cleaned.length-1;i>=0;i--){let digit=parseInt(cleaned.charAt(i),10);if(isEven){digit*=2;if(digit>9)digit-=9}sum+=digit;isEven=!isEven}return sum%10===0}export function isISBN(isbn){const cleaned=isbn.replace(/[\s-]/g,"");if(cleaned.length===10){let sum=0;for(let i=0;i<9;i++){const digit=parseInt(cleaned.charAt(i),10);if(isNaN(digit))return!1;sum+=digit*(10-i)}const checkChar=cleaned.charAt(9),checkDigit=checkChar==="X"?10:parseInt(checkChar,10);if(isNaN(checkDigit)&&checkChar!=="X")return!1;sum+=checkDigit;return sum%11===0}if(cleaned.length===13){let sum=0;for(let i=0;i<12;i++){const digit=parseInt(cleaned.charAt(i),10);if(isNaN(digit))return!1;sum+=digit*(i%2===0?1:3)}const checkDigit=parseInt(cleaned.charAt(12),10);if(isNaN(checkDigit))return!1;return(10-sum%10)%10===checkDigit}return!1}export function isIP(ip){if(/^(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ip))return!0;return/^(?:(?:[0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,7}:|(?:[0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,5}(?::[0-9a-fA-F]{1,4}){1,2}|(?:[0-9a-fA-F]{1,4}:){1,4}(?::[0-9a-fA-F]{1,4}){1,3}|(?:[0-9a-fA-F]{1,4}:){1,3}(?::[0-9a-fA-F]{1,4}){1,4}|(?:[0-9a-fA-F]{1,4}:){1,2}(?::[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:(?:(?::[0-9a-fA-F]{1,4}){1,6})|:(?:(?::[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(?::[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(?:ffff(?::0{1,4}){0,1}:){0,1}(?:(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])|(?:[0-9a-fA-F]{1,4}:){1,4}:(?:(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/.test(ip)}export function isIPRange(ip){const parts=ip.split("/");if(parts.length!==2)return!1;const[address,cidr]=parts;if(address===void 0||cidr===void 0)return!1;if(!/^\d{1,3}$/.test(cidr))return!1;const cidrNum=Number(cidr);if(!isIP(address))return!1;if(address.includes(":"))return cidrNum>=0&&cidrNum<=128;else return cidrNum>=0&&cidrNum<=32}export function isMACAddress(macAddress){return/^(?:[0-9A-Fa-f]{2}[:-]){5}(?:[0-9A-Fa-f]{2})$/.test(macAddress)}function isCoordinate(value,limit){const text=value.trim();return/^[+-]?(?:\d+(?:\.\d+)?|\.\d+)$/.test(text)&&Math.abs(Number(text))<=limit}export function isLatLong(latlong){const parts=latlong.split(",");if(parts.length!==2)return!1;return isCoordinate(parts[0]??"",90)&&isCoordinate(parts[1]??"",180)}export function isCurrency(currency){return/^[$\u00A3\u20AC\u00A5]?\d{1,3}(?:,?\d{3})*(?:\.\d{2})?$/.test(currency.trim())}export function isDataURI(dataURI){const match=/^data:([^,]*),(.*)$/is.exec(dataURI);if(!match)return!1;const params=(match[1]??"").split(";"),base64=params.length>1&&params[params.length-1].toLowerCase()==="base64";if(base64)params.pop();const token="[a-z0-9!#$&^_.+-]+",[mediaType="",...attributes]=params;if(mediaType!==""&&!new RegExp(`^${token}/${token}$`,"i").test(mediaType))return!1;if(!attributes.every((attribute)=>new RegExp(`^${token}=[^;,]*$`,"i").test(attribute)))return!1;const data=match[2]??"";return base64?/^[a-z0-9+/]*={0,2}$/i.test(data):/^[\w!$&'()*+,;=\-.~:@/?%\s]*$/.test(data)}export function isMimeType(mimeType){return/^[a-z]+\/[a-z0-9\-+.]+$/i.test(mimeType)}export function isJWT(jwt){const parts=jwt.split(".");if(parts.length!==3)return!1;try{parts.forEach((part)=>{atob(part.replace(/-/g,"+").replace(/_/g,"/"))});return!0}catch{return!1}}export function isAscii(ascii){return/^[\x00-\x7F]*$/.test(ascii)}export function isBase32(base32){return/^[A-Z2-7]+=*$/.test(base32.toUpperCase())}export function isByteLength(str,options){const min=options?.min??0,max=options?.max??1/0,byteLength=new TextEncoder().encode(str).length;return byteLength>=min&&byteLength<=max}export function isFQDN(fqdn){return/^(?=.{1,253}$)(?:(?!-)[A-Za-z0-9-]{1,63}(?<!-)\.)+[A-Za-z]{2,}$/.test(fqdn)}export function isFullWidth(fullWidth){return/^[\uFF00-\uFFEF]+$/.test(fullWidth)}export function isHalfWidth(halfWidth){return/^[\u0020-\u007E\uFF61-\uFF9F]+$/.test(halfWidth)}export function isHash(hash,algorithm){const expectedLength={md5:32,sha1:40,sha256:64,sha384:96,sha512:128}[algorithm];if(!expectedLength)return!1;return hash.length===expectedLength&&/^[a-f0-9]+$/i.test(hash)}export function isHSL(hsl){return/^hsl\(\s*\d+\s*,\s*\d+(?:\.\d+)?%\s*,\s*\d+(?:\.\d+)?%\s*\)$/.test(hsl)}export function isIBAN(iban){const cleaned=iban.replace(/\s/g,"").toUpperCase();if(!/^[A-Z]{2}\d{2}[A-Z0-9]+$/.test(cleaned))return!1;if(cleaned.length<15||cleaned.length>34)return!1;const digits=(cleaned.slice(4)+cleaned.slice(0,4)).split("").map((char)=>{const code=char.charCodeAt(0);return code>=65&&code<=90?(code-55).toString():char}).join("");let remainder=digits.slice(0,2);for(let i=2;i<digits.length;i+=7)remainder=(parseInt(remainder+digits.slice(i,i+7),10)%97).toString();return parseInt(remainder,10)===1}export function isIdentityCard(identityCard){const cleaned=identityCard.replace(/[\s-]/g,"");return/^[A-Z0-9]{5,20}$/i.test(cleaned)}export function isISIN(isin){if(!/^[A-Z]{2}[A-Z0-9]{9}\d$/.test(isin))return!1;const digits=isin.split("").map((char)=>{const code=char.charCodeAt(0);return code>=65&&code<=90?(code-55).toString():char}).join("");let sum=0,isEven=!1;for(let i=digits.length-1;i>=0;i--){let digit=parseInt(digits.charAt(i),10);if(isEven){digit*=2;if(digit>9)digit-=9}sum+=digit;isEven=!isEven}return sum%10===0}export function isISO8601(iso8601){if(!/^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})?)?$/.test(iso8601))return!1;const[year,month,day]=iso8601.slice(0,10).split("-").map(Number);if(month<1||month>12||day<1||day>daysInMonth(year,month))return!1;try{const date=new Date(iso8601);return!isNaN(date.getTime())}catch{return!1}}export function isISRC(isrc){return/^[A-Z]{2}[A-Z0-9]{3}\d{2}\d{5}$/.test(isrc.replace(/-/g,""))}export function isISSN(issn){const cleaned=issn.replace(/[\s-]/g,"");if(!/^\d{7}[\dX]$/.test(cleaned))return!1;let sum=0;for(let i=0;i<7;i++)sum+=parseInt(cleaned.charAt(i),10)*(8-i);const checkChar=cleaned.charAt(7),checkDigit=checkChar==="X"?10:parseInt(checkChar,10);sum+=checkDigit;return sum%11===0}export function isISO31661Alpha2(iso31661Alpha2){return/^[A-Z]{2}$/.test(iso31661Alpha2)}export function isISO31661Alpha3(iso31661Alpha3){return/^[A-Z]{3}$/.test(iso31661Alpha3)}export function validateUsername(username){return isAlphanumeric(username)}export function isLatitude(latitude){return isCoordinate(latitude,90)}export function isLongitude(longitude){return isCoordinate(longitude,180)}function daysInMonth(year,month){if(month===2)return year%4===0&&(year%100!==0||year%400===0)?29:28;return[4,6,9,11].includes(month)?30:31}
1
+ export function isEmail(email){const emailRegex=/^[^\s@]+@[^\s@]+\.[^\s@]+$/;return emailRegex.test(email)}export function isStrongPassword(password){if(password.length<8)return false;const hasUpperCase=/\p{Lu}/u.test(password);const hasLowerCase=/\p{Ll}/u.test(password);const hasNumber=/\p{N}/u.test(password);const hasSymbol=/[^\p{L}\p{N}]/u.test(password);return hasUpperCase&&hasLowerCase&&hasNumber&&hasSymbol}export function isAlphanumeric(str){return/^[a-zA-Z0-9]+$/.test(str)}export function isURL(url){try{const parsed=new URL(url);return parsed.protocol==="http:"||parsed.protocol==="https:"}catch{return false}}export function isMobilePhone(phoneNumber){const phoneRegex=/^\+?[1-9]\d{6,14}$/;const cleaned=phoneNumber.replace(/[\s()-]/g,"");return phoneRegex.test(cleaned)}export function isAlpha(str){return/^[a-zA-Z]+$/.test(str)}export function isPostalCode(zipCode){const usZip=/^\d{5}(?:-\d{4})?$/;const ukPostcode=/^[A-Z]{1,2}\d{1,2}[A-Z]?\s?\d[A-Z]{2}$/i;const canadaPostcode=/^[A-Z]\d[A-Z]\s?\d[A-Z]\d$/i;const generic=/^[a-zA-Z0-9]{3,10}$/;return usZip.test(zipCode)||ukPostcode.test(zipCode)||canadaPostcode.test(zipCode)||generic.test(zipCode)}export function isNumeric(str){return/^\d+$/.test(str)}export function isHexColor(color){return/^#(?:[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(color)}export function isHexadecimal(hex){return/^[A-Fa-f0-9]+$/.test(hex)}export function isBase64(base64){try{return btoa(atob(base64))===base64}catch{return false}}export function isUUID(uuid){const uuidRegex=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|0{8}-0{4}-0{4}-0{4}-0{12}|f{8}-f{4}-f{4}-f{4}-f{12})$/i;return uuidRegex.test(uuid)}export function isJSON(json){try{JSON.parse(json);return true}catch{return false}}export function isCreditCard(creditCard){const cleaned=creditCard.replace(/[\s-]/g,"");if(!/^\d{13,19}$/.test(cleaned))return false;let sum=0;let isEven=false;for(let i=cleaned.length-1;i>=0;i--){let digit=parseInt(cleaned.charAt(i),10);if(isEven){digit*=2;if(digit>9)digit-=9}sum+=digit;isEven=!isEven}return sum%10===0}export function isISBN(isbn){const cleaned=isbn.replace(/[\s-]/g,"");if(cleaned.length===10){let sum=0;for(let i=0;i<9;i++){const digit=parseInt(cleaned.charAt(i),10);if(isNaN(digit))return false;sum+=digit*(10-i)}const checkChar=cleaned.charAt(9);const checkDigit=checkChar==="X"?10:parseInt(checkChar,10);if(isNaN(checkDigit)&&checkChar!=="X")return false;sum+=checkDigit;return sum%11===0}if(cleaned.length===13){let sum=0;for(let i=0;i<12;i++){const digit=parseInt(cleaned.charAt(i),10);if(isNaN(digit))return false;sum+=digit*(i%2===0?1:3)}const checkDigit=parseInt(cleaned.charAt(12),10);if(isNaN(checkDigit))return false;return(10-sum%10)%10===checkDigit}return false}export function isIP(ip){const ipv4Regex=/^(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;if(ipv4Regex.test(ip))return true;const ipv6Regex=/^(?:(?:[0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,7}:|(?:[0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,5}(?::[0-9a-fA-F]{1,4}){1,2}|(?:[0-9a-fA-F]{1,4}:){1,4}(?::[0-9a-fA-F]{1,4}){1,3}|(?:[0-9a-fA-F]{1,4}:){1,3}(?::[0-9a-fA-F]{1,4}){1,4}|(?:[0-9a-fA-F]{1,4}:){1,2}(?::[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:(?:(?::[0-9a-fA-F]{1,4}){1,6})|:(?:(?::[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(?::[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(?:ffff(?::0{1,4}){0,1}:){0,1}(?:(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])|(?:[0-9a-fA-F]{1,4}:){1,4}:(?:(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;return ipv6Regex.test(ip)}export function isIPRange(ip){const parts=ip.split("/");if(parts.length!==2)return false;const[address,cidr]=parts;if(address===undefined||cidr===undefined)return false;if(!/^\d{1,3}$/.test(cidr))return false;const cidrNum=Number(cidr);if(!isIP(address))return false;if(address.includes(":")){return cidrNum>=0&&cidrNum<=128}else{return cidrNum>=0&&cidrNum<=32}}export function isMACAddress(macAddress){const macRegex=/^(?:[0-9A-Fa-f]{2}[:-]){5}(?:[0-9A-Fa-f]{2})$/;return macRegex.test(macAddress)}function isCoordinate(value,limit){const text=value.trim();return/^[+-]?(?:\d+(?:\.\d+)?|\.\d+)$/.test(text)&&Math.abs(Number(text))<=limit}export function isLatLong(latlong){const parts=latlong.split(",");if(parts.length!==2)return false;return isCoordinate(parts[0]??"",90)&&isCoordinate(parts[1]??"",180)}export function isCurrency(currency){const currencyRegex=/^[$£€¥]?\d{1,3}(?:,?\d{3})*(?:\.\d{2})?$/;return currencyRegex.test(currency.trim())}export function isDataURI(dataURI){const match=/^data:([^,]*),(.*)$/is.exec(dataURI);if(!match)return false;const params=(match[1]??"").split(";");const base64=params.length>1&&params[params.length-1].toLowerCase()==="base64";if(base64)params.pop();const token="[a-z0-9!#$&^_.+-]+";const[mediaType="",...attributes]=params;if(mediaType!==""&&!new RegExp(`^${token}/${token}$`,"i").test(mediaType))return false;if(!attributes.every((attribute)=>new RegExp(`^${token}=[^;,]*$`,"i").test(attribute)))return false;const data=match[2]??"";return base64?/^[a-z0-9+/]*={0,2}$/i.test(data):/^[\w!$&'()*+,;=\-.~:@/?%\s]*$/.test(data)}export function isMimeType(mimeType){const mimeTypeRegex=/^[a-z]+\/[a-z0-9\-+.]+$/i;return mimeTypeRegex.test(mimeType)}export function isJWT(jwt){const parts=jwt.split(".");if(parts.length!==3)return false;try{parts.forEach((part)=>{atob(part.replace(/-/g,"+").replace(/_/g,"/"))});return true}catch{return false}}export function isAscii(ascii){return/^[\x00-\x7F]*$/.test(ascii)}export function isBase32(base32){return/^[A-Z2-7]+=*$/.test(base32.toUpperCase())}export function isByteLength(str,options){const min=options?.min??0;const max=options?.max??1/0;const byteLength=new TextEncoder().encode(str).length;return byteLength>=min&&byteLength<=max}export function isFQDN(fqdn){const fqdnRegex=/^(?=.{1,253}$)(?:(?!-)[A-Za-z0-9-]{1,63}(?<!-)\.)+[A-Za-z]{2,}$/;return fqdnRegex.test(fqdn)}export function isFullWidth(fullWidth){return/^[\uFF00-\uFFEF]+$/.test(fullWidth)}export function isHalfWidth(halfWidth){return/^[\u0020-\u007E\uFF61-\uFF9F]+$/.test(halfWidth)}export function isHash(hash,algorithm){const hashLengths={md5:32,sha1:40,sha256:64,sha384:96,sha512:128};const expectedLength=hashLengths[algorithm];if(!expectedLength)return false;return hash.length===expectedLength&&/^[a-f0-9]+$/i.test(hash)}export function isHSL(hsl){const hslRegex=/^hsl\(\s*\d+\s*,\s*\d+(?:\.\d+)?%\s*,\s*\d+(?:\.\d+)?%\s*\)$/;return hslRegex.test(hsl)}export function isIBAN(iban){const cleaned=iban.replace(/\s/g,"").toUpperCase();if(!/^[A-Z]{2}\d{2}[A-Z0-9]+$/.test(cleaned))return false;if(cleaned.length<15||cleaned.length>34)return false;const rearranged=cleaned.slice(4)+cleaned.slice(0,4);const digits=rearranged.split("").map((char)=>{const code=char.charCodeAt(0);return code>=65&&code<=90?(code-55).toString():char}).join("");let remainder=digits.slice(0,2);for(let i=2;i<digits.length;i+=7){remainder=(parseInt(remainder+digits.slice(i,i+7),10)%97).toString()}return parseInt(remainder,10)===1}export function isIdentityCard(identityCard){const cleaned=identityCard.replace(/[\s-]/g,"");return/^[A-Z0-9]{5,20}$/i.test(cleaned)}export function isISIN(isin){if(!/^[A-Z]{2}[A-Z0-9]{9}\d$/.test(isin))return false;const digits=isin.split("").map((char)=>{const code=char.charCodeAt(0);return code>=65&&code<=90?(code-55).toString():char}).join("");let sum=0;let isEven=false;for(let i=digits.length-1;i>=0;i--){let digit=parseInt(digits.charAt(i),10);if(isEven){digit*=2;if(digit>9)digit-=9}sum+=digit;isEven=!isEven}return sum%10===0}export function isISO8601(iso8601){const iso8601Regex=/^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})?)?$/;if(!iso8601Regex.test(iso8601))return false;const[year,month,day]=iso8601.slice(0,10).split("-").map(Number);if(month<1||month>12||day<1||day>daysInMonth(year,month))return false;try{const date=new Date(iso8601);return!isNaN(date.getTime())}catch{return false}}export function isISRC(isrc){return/^[A-Z]{2}[A-Z0-9]{3}\d{2}\d{5}$/.test(isrc.replace(/-/g,""))}export function isISSN(issn){const cleaned=issn.replace(/[\s-]/g,"");if(!/^\d{7}[\dX]$/.test(cleaned))return false;let sum=0;for(let i=0;i<7;i++){sum+=parseInt(cleaned.charAt(i),10)*(8-i)}const checkChar=cleaned.charAt(7);const checkDigit=checkChar==="X"?10:parseInt(checkChar,10);sum+=checkDigit;return sum%11===0}export function isISO31661Alpha2(iso31661Alpha2){return/^[A-Z]{2}$/.test(iso31661Alpha2)}export function isISO31661Alpha3(iso31661Alpha3){return/^[A-Z]{3}$/.test(iso31661Alpha3)}export function validateUsername(username){return isAlphanumeric(username)}export function isLatitude(latitude){return isCoordinate(latitude,90)}export function isLongitude(longitude){return isCoordinate(longitude,180)}function daysInMonth(year,month){if(month===2)return year%4===0&&(year%100!==0||year%400===0)?29:28;return[4,6,9,11].includes(month)?30:31}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/strings",
3
3
  "type": "module",
4
- "version": "0.75.514",
4
+ "version": "0.75.518",
5
5
  "description": "The Stacks string utilities.",
6
6
  "author": "Chris Breuer",
7
7
  "contributors": [
@@ -69,9 +69,9 @@
69
69
  "prepublishOnly": "bun run build"
70
70
  },
71
71
  "devDependencies": {
72
- "@stacksjs/alias": "0.75.514",
72
+ "@stacksjs/alias": "0.75.518",
73
73
  "better-dx": "^0.2.24",
74
- "@stacksjs/types": "0.75.514"
74
+ "@stacksjs/types": "0.75.518"
75
75
  },
76
76
  "sideEffects": false
77
77
  }