CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes45downloads
index.js25 linesDownload Raw Back to strip-indent
1export default function stripIndent(string) {2	const match = string.match(/^[ \t]*(?=\S)/gm);3 4	if (!match) {5		return string;6	}7 8	let minIndent = Number.POSITIVE_INFINITY;9	for (const indent of match) {10		minIndent = Math.min(minIndent, indent.length);11	}12 13	if (minIndent === 0 || minIndent === Number.POSITIVE_INFINITY) {14		return string;15	}16 17	return string.replace(new RegExp(`^[ \\t]{${minIndent}}`, 'gm'), '');18}19 20export function dedent(string) {21	// Remove all leading and trailing whitespace-only lines22	const trimmed = string.replace(/^(?:[ \t]*\r?\n)+|(?:\r?\n[ \t]*)+$/g, '');23	return stripIndent(trimmed);24}25 
basant307/AI_Governance_Project · CoolFace