fix(core): update
This commit is contained in:
parent
14ba4465d9
commit
1fc95fcf0e
10
package.json
10
package.json
@ -26,11 +26,11 @@
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/smartstring#readme",
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.66",
|
||||
"@gitzone/tsrun": "^1.2.42",
|
||||
"@gitzone/tstest": "^1.0.74",
|
||||
"@push.rocks/tapbundle": "^5.0.8",
|
||||
"@types/node": "^20.3.1"
|
||||
"@git.zone/tsbuild": "^2.1.66",
|
||||
"@git.zone/tsrun": "^1.2.42",
|
||||
"@git.zone/tstest": "^1.0.74",
|
||||
"@push.rocks/tapbundle": "^5.0.15",
|
||||
"@types/node": "^20.5.7"
|
||||
},
|
||||
"dependencies": {
|
||||
"@push.rocks/isounique": "^1.0.5",
|
||||
|
2149
pnpm-lock.yaml
generated
2149
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -9,8 +9,7 @@ tap.test('should normalize a string', async () => {
|
||||
`;
|
||||
const normalizedString = smartstring.normalize.standard(testString);
|
||||
expect(normalizedString).toEqual(
|
||||
`
|
||||
myawesome string;
|
||||
`myawesome string;
|
||||
is indented with two spaces
|
||||
`
|
||||
);
|
||||
|
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartstring',
|
||||
version: '4.0.8',
|
||||
version: '4.0.9',
|
||||
description: 'handle strings in smart ways. TypeScript ready.'
|
||||
}
|
||||
|
@ -10,13 +10,42 @@ export const replaceAll = (stringArg: string, searchPattern: string, replacement
|
||||
return stringArg.replace(new RegExp(searchPattern, 'g'), replacementString);
|
||||
};
|
||||
|
||||
export interface INormalizeOptions {
|
||||
stripLeadingTrailingEmptyLines?: boolean;
|
||||
stripAllEmptyLines?: boolean;
|
||||
stripIndent?: boolean;
|
||||
normalizeNewline?: boolean;
|
||||
replaceTabs?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* normalizes a string
|
||||
* Normalizes a string
|
||||
* @param stringArg
|
||||
* @param options
|
||||
*/
|
||||
export const standard = (stringArg: string): string => {
|
||||
let fix1 = plugins.stripIndent(stringArg); // fix indention
|
||||
let fix2 = plugins.normalizeNewline(fix1); // fix newlines
|
||||
let fix3 = replaceAll(fix2, '\t/', ' '); // fix tabs
|
||||
return fix3;
|
||||
export const standard = (stringArg: string, options?: INormalizeOptions): string => {
|
||||
let result = stringArg;
|
||||
|
||||
if (!options || options.stripIndent) {
|
||||
result = plugins.stripIndent(result); // fix indention
|
||||
}
|
||||
|
||||
if (!options || options.normalizeNewline) {
|
||||
result = plugins.normalizeNewline(result); // fix newlines
|
||||
}
|
||||
|
||||
if (!options || options.replaceTabs) {
|
||||
result = replaceAll(result, '\t/', ' '); // fix tabs
|
||||
}
|
||||
|
||||
if (!options || options.stripLeadingTrailingEmptyLines) {
|
||||
result = result.replace(/^\s*[\r\n]/gm, '').replace(/\s*[\r\n]$/gm, '');
|
||||
}
|
||||
|
||||
if (!options || options.stripAllEmptyLines) {
|
||||
result = result.replace(/^\s*[\r\n]/gm, '');
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user