swc/bundler/tests/.cache/deno/31e518114bda56f682a9c2d68b6b1bba43b9bd2f.ts
강동윤 1178686a4c
fix(bundler): Fix bundler (#1576)
swc_bundler:
 - Fix remapping of exports. (denoland/deno#9350)
2021-04-16 18:09:38 +00:00

37 lines
1.2 KiB
TypeScript

// Loaded from https://deno.land/x/cliffy@v0.12.1/packages/x/normalCase.ts
import camelCaseRegexp from 'https://deno.land/x/case/vendor/camelCaseRegexp.ts';
import camelCaseUpperRegexp from 'https://deno.land/x/case/vendor/camelCaseUpperRegexp.ts';
import nonWordRegexp from 'https://deno.land/x/case/vendor/nonWordRegexp.ts';
import lowerCase from './lowerCase.ts';
export default function normalCase( str: string, locale?: string, replacement?: string ): string {
if ( str == null ) {
return '';
}
replacement = typeof replacement !== 'string' ? ' ' : replacement;
function replace( match: string, index: number, value: string ): string {
if ( index === 0 || index === value.length - match.length ) {
return '';
}
return replacement || '';
}
str = String( str )
// Support camel case ("camelCase" -> "camel Case").
.replace( camelCaseRegexp, '$1 $2' )
// Support odd camel case ("CAMELCase" -> "CAMEL Case").
.replace( camelCaseUpperRegexp, '$1 $2' )
// Remove all non-word characters and replace with a single space.
.replace( nonWordRegexp, replace );
// Lower case the entire string.
return lowerCase( str, locale );
}