blockly-fluid 1.3.12 → 1.3.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/utils/dedent.js +18 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blockly-fluid",
3
- "version": "1.3.12",
3
+ "version": "1.3.13",
4
4
  "description": "A flexible proxy wrapper for Blockly blocks.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/utils/dedent.js CHANGED
@@ -1,15 +1,24 @@
1
- module.exports = (strings, ...values) => {
2
- let text = String.raw({ raw: strings }, ...values);
1
+ module.exports = (text) => {
2
+ const lines = text.split("\n");
3
3
 
4
- text = text.replace(/^\n/, "").replace(/\n$/, "");
4
+ const firstLine = lines.find((line) => line.trim().length > 0);
5
5
 
6
- const indent = text.match(/^[ \t]*(?=\S)/gm);
6
+ if (!firstLine) return text;
7
7
 
8
- if (indent) {
9
- const minimumIndent = Math.min(...indent.map(i => i.length));
8
+ const indentMatch = firstLine.match(/^[ \t]*/);
9
+ const indentSize = (indentMatch) ? indentMatch[0].length : 0;
10
10
 
11
- text = text.replace(new RegExp(`^[ \\t]{${minimumIndent}}`, "gm"), "");
12
- };
11
+ if (indentSize === 0) return text;
13
12
 
14
- return text;
13
+ return (
14
+ lines
15
+ .map((line) => (
16
+ (line.startsWith(" ".repeat(indentSize)))
17
+ ? line.slice(indentSize)
18
+ : line
19
+ ))
20
+ .join("\n")
21
+ .replace(/^\n/, "")
22
+ .replace(/\n\s*$/, "")
23
+ );
15
24
  };