feat(core): Introduce native implementations for Base64, random generation and normalization; remove runtime plugin dependencies; update tests, docs and package metadata

This commit is contained in:
2025-09-12 18:57:31 +00:00
parent 6a7570de7b
commit 1f3e170a88
17 changed files with 7585 additions and 4795 deletions

View File

@@ -1,5 +1,3 @@
import * as plugins from './smartstring.plugins.js';
/**
* replaces all occurences of something in a string
* @param stringArg
@@ -10,6 +8,38 @@ export const replaceAll = (stringArg: string, searchPattern: string, replacement
return stringArg.replace(new RegExp(searchPattern, 'g'), replacementString);
};
/**
* Custom implementation of strip-indent
* Removes the minimum indentation from all lines
*/
const stripIndent = (str: string): string => {
const lines = str.split('\n');
// Find the minimum indentation (ignoring empty lines)
let minIndent = Infinity;
for (const line of lines) {
if (line.trim().length > 0) {
const match = line.match(/^(\s*)/);
if (match) {
minIndent = Math.min(minIndent, match[1].length);
}
}
}
// If no indentation found, return original string
if (minIndent === Infinity || minIndent === 0) {
return str;
}
// Remove the minimum indentation from all lines
return lines.map(line => {
if (line.length >= minIndent) {
return line.slice(minIndent);
}
return line;
}).join('\n');
};
export interface INormalizeOptions {
stripLeadingTrailingEmptyLines?: boolean;
stripAllEmptyLines?: boolean;
@@ -27,7 +57,7 @@ export const standard = (stringArg: string, options?: INormalizeOptions): string
let result = stringArg;
if (!options || options.stripIndent) {
result = plugins.stripIndent(result); // fix indention
result = stripIndent(result); // fix indention
}
if (!options || options.normalizeNewline) {