@waiting/shared-core
Advanced tools
Comparing version 20.13.0 to 21.0.0
@@ -15,9 +15,5 @@ import { CamelKeys, CamelToSnake, SnakeKeys, SnakeToCamel, SnakeToPascal } from '@waiting/shared-types'; | ||
*/ | ||
export declare function snakeToCamel<T extends string, D extends string = '_', TrimStart extends boolean = false, TrimEnd extends boolean = false>(input: T, | ||
export declare function snakeToCamel<T extends string, D extends string = '_'>(input: T, | ||
/** @default _ */ | ||
delimiter?: D, | ||
/** @defalut false */ | ||
trimStartFlag?: TrimStart, | ||
/** @defalut false */ | ||
trimEndFlag?: TrimEnd): SnakeToCamel<T, D, TrimStart, TrimEnd>; | ||
delimiter?: D): SnakeToCamel<T, D>; | ||
export declare function trimStart(input: string, delimiter: string): string; | ||
@@ -40,9 +36,5 @@ export declare function trimEnd(input: string, delimiter: string): string; | ||
*/ | ||
export declare function snakeToPascal<T extends string, D extends string = '_', TrimStart extends boolean = false, TrimEnd extends boolean = false>(input: T, | ||
export declare function snakeToPascal<T extends string, D extends string = '_'>(input: T, | ||
/** @default _ */ | ||
delimiter?: D, | ||
/** @defalut false */ | ||
trimStartFlag?: TrimStart, | ||
/** @defalut false */ | ||
trimEndFlag?: TrimEnd): SnakeToPascal<T, D, TrimStart, TrimEnd>; | ||
delimiter?: D): SnakeToPascal<T, D>; | ||
/** | ||
@@ -49,0 +41,0 @@ * Convert camelcase to snakecase |
import assert from 'node:assert'; | ||
const startDelimiterRegExpMap = new Map(); | ||
const endDelimiterRegExpMap = new Map(); | ||
const delimiterAndNumberRegExpMap = new Map(); | ||
const regExpMap = new Map(); | ||
@@ -21,28 +22,31 @@ const startDelimiterRegExpMapPascal = new Map(); | ||
/** @default _ */ | ||
delimiter, | ||
/** @defalut false */ | ||
trimStartFlag, | ||
/** @defalut false */ | ||
trimEndFlag) { | ||
delimiter) { | ||
const dem = delimiter ?? '_'; | ||
const ts = trimStartFlag ?? false; | ||
const te = trimEndFlag ?? false; | ||
let reg = regExpMap.get(dem); | ||
if (!reg) { | ||
reg = new RegExp(`${dem}+[^${dem}]+|[^${dem}]+|${dem}+$`, 'ug'); | ||
regExpMap.set(dem, reg); | ||
if (regExpMap.size > 10000) { | ||
regExpMap.clear(); | ||
} | ||
reg = new RegExp(`${dem}+[^${dem}]+|[^${dem}]+|${dem}+$`, 'ug'); | ||
regExpMap.set(dem, reg); | ||
} | ||
if (!delimiterAndNumberRegExpMap.get(dem)) { | ||
if (delimiterAndNumberRegExpMap.size > 10000) { | ||
delimiterAndNumberRegExpMap.clear(); | ||
} | ||
const reg2 = new RegExp(`${dem}+[0-9]+?[^${dem}]*$`, 'u'); // !no flag g | ||
delimiterAndNumberRegExpMap.set(dem, reg2); | ||
} | ||
const matches = input.match(reg); | ||
reg.lastIndex = 0; | ||
const len = matches?.length; | ||
if (!len) { | ||
return ''; | ||
// return '' | ||
return input; | ||
} | ||
const arr = matches.map((str, idx) => _snakeToCamel(len, idx, str, dem, ts, te)); | ||
const arr = matches.map((str, idx) => _snakeToCamel(len, idx, str, dem)); | ||
const ret = arr.join(''); | ||
return ret; | ||
} | ||
function _snakeToCamel(len, idx, input, delimiter, trimStartFlag, trimEndFlag) { | ||
function _snakeToCamel(len, idx, input, delimiter, trimStartFlag = false, trimEndFlag = false) { | ||
if (!input) { | ||
@@ -52,2 +56,6 @@ return ''; | ||
let ret = input; | ||
const reg2 = delimiterAndNumberRegExpMap.get(delimiter); | ||
if (reg2?.test(input)) { | ||
return ret; | ||
} | ||
if (idx === 0) { | ||
@@ -116,9 +124,5 @@ if (trimStartFlag === true) { | ||
/** @default _ */ | ||
delimiter, | ||
/** @defalut false */ | ||
trimStartFlag, | ||
/** @defalut false */ | ||
trimEndFlag) { | ||
delimiter) { | ||
const dem = delimiter ?? '_'; | ||
const line = snakeToCamel(input, dem, trimStartFlag, trimEndFlag); | ||
const line = snakeToCamel(input, dem); | ||
let reg = startDelimiterRegExpMapPascal.get(dem); | ||
@@ -133,2 +137,3 @@ if (!reg) { | ||
const line2 = line.replace(reg, match => match.toUpperCase()); | ||
reg.lastIndex = 0; | ||
const ret = capitalize(line2); | ||
@@ -155,4 +160,4 @@ return ret; | ||
line = line.replace(/[A-Z]/ug, match => `${dem}${match.toLowerCase()}`); | ||
const ret = line.replace(/(?<=\w)\d+/ug, match => `${dem}${match}`); | ||
return ret; | ||
// line = line.replace(/(?<=\w)\d+/ug, match => `${dem}${match}`) // 'tb6_user_id' => 'tb_6_user_id' | ||
return line; | ||
} | ||
@@ -159,0 +164,0 @@ export function camelKeys(input, |
{ | ||
"name": "@waiting/shared-core", | ||
"author": "waiting", | ||
"version": "20.13.0", | ||
"version": "21.0.0", | ||
"description": "node core function re export with Promise or Observable", | ||
@@ -31,3 +31,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@waiting/shared-types": "^20.13.0", | ||
"@waiting/shared-types": "^21.0.0", | ||
"rxjs": "^7.8.0", | ||
@@ -58,3 +58,3 @@ "source-map-support": "^0.5.21" | ||
"scripts": { | ||
"build": "npm run tsc && npm run rp", | ||
"build": "npm run tsc && tsc-alias && npm run rp", | ||
"clean": "npm run clean:lock & npm run clean:cache & rm -rf dist/* -rf", | ||
@@ -70,6 +70,5 @@ "clean:cache": "rm -rf .eslintcache .vscode/.tsbuildinfo .vscode/.tsbuildinfo.*", | ||
"test:local": "cross-env TS_NODE_PROJECT=test/tsconfig.json ../../node_modules/.bin/mocha --loader=ts-node/esm --parallel=false", | ||
"tsc": "tsc -b ", | ||
"tsc:w": "tsc -p tsconfig.json -w" | ||
"tsc": "tsc -b " | ||
}, | ||
"gitHead": "88133dc03b3df986fa8ae4944cd7abcee857ec8e" | ||
"gitHead": "f5b91437b1088473eedd52b16cf9561f5129d39d" | ||
} |
@@ -14,2 +14,3 @@ import assert from 'node:assert' | ||
const endDelimiterRegExpMap = new Map<string, RegExp>() | ||
const delimiterAndNumberRegExpMap = new Map<string, RegExp>() | ||
const regExpMap = new Map<string, RegExp>() | ||
@@ -34,4 +35,2 @@ const startDelimiterRegExpMapPascal = new Map<string, RegExp>() | ||
D extends string = '_', | ||
TrimStart extends boolean = false, | ||
TrimEnd extends boolean = false, | ||
>( | ||
@@ -41,29 +40,33 @@ input: T, | ||
delimiter?: D, | ||
/** @defalut false */ | ||
trimStartFlag?: TrimStart, | ||
/** @defalut false */ | ||
trimEndFlag?: TrimEnd, | ||
): SnakeToCamel<T, D, TrimStart, TrimEnd> { | ||
): SnakeToCamel<T, D> { | ||
const dem = delimiter ?? '_' | ||
const ts = trimStartFlag ?? false | ||
const te = trimEndFlag ?? false | ||
let reg = regExpMap.get(dem) | ||
if (! reg) { | ||
reg = new RegExp(`${dem}+[^${dem}]+|[^${dem}]+|${dem}+$`, 'ug') | ||
regExpMap.set(dem, reg) | ||
if (regExpMap.size > 10000) { | ||
regExpMap.clear() | ||
} | ||
reg = new RegExp(`${dem}+[^${dem}]+|[^${dem}]+|${dem}+$`, 'ug') | ||
regExpMap.set(dem, reg) | ||
} | ||
if (! delimiterAndNumberRegExpMap.get(dem)) { | ||
if (delimiterAndNumberRegExpMap.size > 10000) { | ||
delimiterAndNumberRegExpMap.clear() | ||
} | ||
const reg2 = new RegExp(`${dem}+[0-9]+?[^${dem}]*$`, 'u') // !no flag g | ||
delimiterAndNumberRegExpMap.set(dem, reg2) | ||
} | ||
const matches = input.match(reg) | ||
reg.lastIndex = 0 | ||
const len = matches?.length | ||
if (! len) { | ||
return '' as SnakeToCamel<T, D, TrimStart, TrimEnd> | ||
// return '' | ||
return input as SnakeToCamel<T, D> | ||
} | ||
const arr = matches.map((str, idx) => _snakeToCamel(len, idx, str, dem, ts, te)) | ||
const ret = arr.join('') as SnakeToCamel<T, D, TrimStart, TrimEnd> | ||
const arr = matches.map((str, idx) => _snakeToCamel(len, idx, str, dem)) | ||
const ret = arr.join('') as SnakeToCamel<T, D> | ||
return ret | ||
@@ -77,4 +80,4 @@ } | ||
delimiter: string, | ||
trimStartFlag: boolean, | ||
trimEndFlag: boolean, | ||
trimStartFlag = false, | ||
trimEndFlag = false, | ||
): string { | ||
@@ -86,2 +89,7 @@ | ||
const reg2 = delimiterAndNumberRegExpMap.get(delimiter) | ||
if (reg2?.test(input)) { | ||
return ret | ||
} | ||
if (idx === 0) { | ||
@@ -159,4 +167,2 @@ if (trimStartFlag === true) { | ||
D extends string = '_', | ||
TrimStart extends boolean = false, | ||
TrimEnd extends boolean = false, | ||
>( | ||
@@ -166,10 +172,6 @@ input: T, | ||
delimiter?: D, | ||
/** @defalut false */ | ||
trimStartFlag?: TrimStart, | ||
/** @defalut false */ | ||
trimEndFlag?: TrimEnd, | ||
): SnakeToPascal<T, D, TrimStart, TrimEnd> { | ||
): SnakeToPascal<T, D> { | ||
const dem = delimiter ?? '_' | ||
const line = snakeToCamel(input, dem, trimStartFlag, trimEndFlag) | ||
const line = snakeToCamel(input, dem) | ||
@@ -186,3 +188,4 @@ let reg = startDelimiterRegExpMapPascal.get(dem) | ||
const line2 = line.replace(reg, match => match.toUpperCase()) | ||
const ret = capitalize(line2) as SnakeToPascal<T, D, TrimStart, TrimEnd> | ||
reg.lastIndex = 0 | ||
const ret = capitalize(line2) as SnakeToPascal<T, D> | ||
return ret | ||
@@ -214,4 +217,4 @@ } | ||
line = line.replace(/[A-Z]/ug, match => `${dem}${match.toLowerCase()}`) | ||
const ret = line.replace(/(?<=\w)\d+/ug, match => `${dem}${match}`) | ||
return ret as CamelToSnake<T, D> | ||
// line = line.replace(/(?<=\w)\d+/ug, match => `${dem}${match}`) // 'tb6_user_id' => 'tb_6_user_id' | ||
return line as CamelToSnake<T, D> | ||
} | ||
@@ -218,0 +221,0 @@ |
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
188881
3481
+ Added@waiting/shared-types@21.6.1(transitive)
+ Addedtypescript@5.7.2(transitive)
- Removed@waiting/shared-types@20.13.0(transitive)
- Removedtypescript@5.6.3(transitive)