dedent
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -7,6 +7,3 @@ "use strict"; | ||
exports.default = dedent; | ||
// @flow | ||
function dedent(strings /*: string | Array<string>*/, ...values /*: Array<string>*/) { | ||
// $FlowFixMe: Flow doesn't undestand .raw | ||
function dedent(strings, ...values) { | ||
const raw = typeof strings === "string" ? [strings] : strings.raw; | ||
@@ -29,7 +26,7 @@ | ||
const lines = result.split("\n"); | ||
let mindent /*: number | null*/ = null; | ||
lines.forEach(l => { | ||
let m = l.match(/^(\s+)\S+/); | ||
let mindent = null; | ||
for (const l of lines) { | ||
const m = l.match(/^(\s+)\S+/); | ||
if (m) { | ||
let indent = m[1].length; | ||
const indent = m[1].length; | ||
if (!mindent) { | ||
@@ -42,6 +39,9 @@ // this is the first indented line | ||
} | ||
}); | ||
} | ||
if (mindent !== null) { | ||
const m = mindent; // appease Flow | ||
result = lines.map(l => l[0] === " " || l[0] === "\t" ? l.slice(m) : l).join("\n"); | ||
const m = mindent; // appease TypeScript | ||
result = lines | ||
// https://github.com/typescript-eslint/typescript-eslint/issues/7140 | ||
// eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with | ||
.map(l => l[0] === " " || l[0] === "\t" ? l.slice(m) : l).join("\n"); | ||
} | ||
@@ -48,0 +48,0 @@ return result |
{ | ||
"name": "dedent", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "An ES6 string tag that strips indentation from multi-line strings", | ||
"main": "dist/dedent.js", | ||
"types": "./dist/dedent.d.ts", | ||
"module": "./dist/dedent.mjs", | ||
"files": [ | ||
"dist/dedent.d.ts", | ||
"dist/dedent.js", | ||
@@ -42,20 +44,26 @@ "dist/dedent.mjs", | ||
"@babel/core": "^7.21.8", | ||
"@babel/plugin-transform-flow-comments": "^7.22.5", | ||
"@babel/preset-env": "^7.21.5", | ||
"@babel/preset-typescript": "^7.22.5", | ||
"@types/babel-plugin-macros": "^3.1.0", | ||
"@types/jest": "^29.5.3", | ||
"@typescript-eslint/eslint-plugin": "^6.0.0", | ||
"@typescript-eslint/parser": "^6.0.0", | ||
"babel-plugin-add-module-exports": "^1.0.4", | ||
"babel-plugin-tester": "^11.0.4", | ||
"eslint": "^8.41.0", | ||
"eslint-plugin-ft-flow": "^2.0.3", | ||
"flow-bin": "^0.206.0", | ||
"hermes-eslint": "^0.11.1", | ||
"jest": "^29.5.0" | ||
"jest": "^29.5.0", | ||
"tsup": "^7.1.0", | ||
"typescript": "^5.1.6" | ||
}, | ||
"scripts": { | ||
"build": "yarn build:legacy && yarn build:modern", | ||
"build:legacy": "BABEL_ENV=legacy babel dedent.js --out-file dist/dedent.js", | ||
"build:modern": "BABEL_ENV=modern babel dedent.js --out-file dist/dedent.mjs", | ||
"lint": "eslint dedent.js __tests__", | ||
"build": "yarn build:legacy && yarn build:modern && yarn build:types", | ||
"build:legacy": "BABEL_ENV=legacy babel dedent.ts --out-file dist/dedent.js", | ||
"build:modern": "BABEL_ENV=modern babel dedent.ts --out-file dist/dedent.mjs", | ||
"build:types": "tsup dedent.ts --dts-only", | ||
"lint": "eslint .", | ||
"prepack": "yarn build", | ||
"test": "jest" | ||
"test": "jest", | ||
"tsc": "tsc" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
8578
124
15