Skip to content

Commit

Permalink
Add trimChars utility and update dependencies (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
4746 authored Jan 15, 2025
2 parents 31a9baa + 528917b commit 3b48caa
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"author": "Vadim",
"license": "MIT",
"version": "1.2.3",
"version": "1.3.0",
"bugs": "https://github.com/4746/transverto/issues",
"homepage": "https://github.com/4746/transverto",
"repository": "4746/transverto",
Expand Down Expand Up @@ -43,7 +43,7 @@
"@oclif/plugin-help": "^6.0.10",
"chalk": "^5.3.0",
"fs-extra": "^11.2.0",
"got": "14.0.0",
"got": "^14.4.5",
"listr2": "^8.0.1"
},
"devDependencies": {
Expand All @@ -67,7 +67,7 @@
"typescript": "^5.3.3"
},
"engines": {
"node": ">=18.0.0"
"node": ">=20"
},
"files": [
"/bin",
Expand Down
7 changes: 7 additions & 0 deletions src/commands/label/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ import {UTIL} from "../../shared/util.js";
/**
* node --loader ts-node/esm --no-warnings=ExperimentalWarning ./bin/dev label:add hello.world -f="en"
* node --loader ts-node/esm --no-warnings=ExperimentalWarning ./bin/dev label:add hello.world -f="en" -t "Hello World!"
* node --loader ts-node/esm --no-warnings=ExperimentalWarning ./bin/dev label:add "ggggg"
* node --loader ts-node/esm --no-warnings=ExperimentalWarning ./bin/dev label:add "ggggg" -fen
* node --loader ts-node/esm --no-warnings=ExperimentalWarning ./bin/dev label:add "\"ggggg\"" -fen
* node --loader ts-node/esm --no-warnings=ExperimentalWarning ./bin/dev label:add \"ggggg\" -fen
* node --loader ts-node/esm --no-warnings=ExperimentalWarning ./bin/dev label:add '"ggggg"' -fen
* node --loader ts-node/esm --no-warnings=ExperimentalWarning ./bin/dev label:add \"ggggg\" -fen
* "C:\Program Files\nodejs\npm.cmd" run ctv label:add "\"ggggg\"" -fen
*/
export default class LabelAdd extends LabelBaseCommand<typeof LabelAdd> {
static args = {
Expand Down
2 changes: 1 addition & 1 deletion src/shared/label-base.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export abstract class LabelBaseCommand<T extends typeof Command> extends Command
}

return input({
default: UTIL.isString(label) ? label : null,
default: UTIL.isString(label) ? UTIL.trimChars(label.trim(), '.*+?^${}()|[\\]\\\\').trim() : null,
message: `Enter label:`,
validate: (v: string) => {
let isValid: boolean;
Expand Down
13 changes: 13 additions & 0 deletions src/shared/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,18 @@ const mergeDeep = (...sources: NonNullable<object>[]): NonNullable<object> => {
return target;
}

/**
* Removes specified characters from the beginning and end of a given string.
*
* @param {string} str - The input string to trim.
* @param {string} chars - A string containing characters to be trimmed from both ends of the input string.
* @returns {string} - The resulting string after removing the specified characters from the start and end.
*/
export const trimChars = (str: string, chars: string): string => {
const pattern = new RegExp(`^[${chars}]+|[${chars}]+$`, 'g');
return str.replace(pattern, '');
}

export const UTIL = {
deletePropertyPath,
flattenObject,
Expand All @@ -188,4 +200,5 @@ export const UTIL = {
replacePropertyPath,
setNestedValue,
sortObjByKey,
trimChars,
}

0 comments on commit 3b48caa

Please sign in to comment.