Skip to content

Commit da5c75a

Browse files
committed
(@fluent/dedent) Migrate to TypeScript
1 parent 0b3a389 commit da5c75a

13 files changed

+75
-43
lines changed

fluent-dedent/.esdoc.json

Lines changed: 0 additions & 16 deletions
This file was deleted.

fluent-dedent/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
esm/
12
/index.js
23
/compat.js

fluent-dedent/.npmignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
.nyc_output
22
coverage
3-
docs
3+
esm/.compiled
4+
src
45
test
56
makefile
7+
tsconfig.json

fluent-dedent/makefile

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,30 @@ GLOBAL := FluentDedent
33

44
include ../common.mk
55

6-
build: index.js compat.js
6+
lint:
7+
@eslint --config $(ROOT)/eslint_ts.json --max-warnings 0 src/*.ts
8+
@eslint --config $(ROOT)/eslint_test.json --max-warnings 0 test/
9+
@echo -e " $(OK) lint"
10+
11+
.PHONY: compile
12+
compile: esm/.compiled
13+
14+
esm/.compiled: $(SOURCES)
15+
@tsc
16+
@touch $@
17+
@echo -e " $(OK) esm/ compiled"
718

8-
test:
19+
.PHONY: test
20+
test: esm/.compiled
921
@nyc --reporter=text --reporter=html mocha \
1022
--recursive --ui tdd \
1123
--require esm \
1224
test/**/*_test.js
1325

26+
build: index.js compat.js
27+
1428
index.js: $(SOURCES)
15-
@rollup $(CURDIR)/src/index.js \
29+
@rollup $(CURDIR)/esm/index.js \
1630
--config $(ROOT)/bundle_config.js \
1731
--banner "/* $(PACKAGE)@$(VERSION) */" \
1832
--amd.id $(PACKAGE) \
@@ -21,14 +35,26 @@ index.js: $(SOURCES)
2135
@echo -e " $(OK) $@ built"
2236

2337
compat.js: $(SOURCES)
24-
@rollup $(CURDIR)/src/index.js \
38+
@rollup $(CURDIR)/esm/index.js \
2539
--config $(ROOT)/compat_config.js \
2640
--banner "/* $(PACKAGE)@$(VERSION) */" \
2741
--amd.id $(PACKAGE) \
2842
--name $(GLOBAL) \
2943
--output.file $@
3044
@echo -e " $(OK) $@ built"
3145

32-
lint: _lint
33-
html: _html
34-
clean: _clean
46+
html:
47+
@typedoc src \
48+
--out ../html/bundle \
49+
--mode file \
50+
--excludeNotExported \
51+
--excludePrivate \
52+
--logger none \
53+
--hideGenerator
54+
@echo -e " $(OK) html build"
55+
56+
clean:
57+
@rm -f esm/*.js esm/*.d.ts esm/.compiled
58+
@rm -f index.js compat.js
59+
@rm -rf .nyc_output coverage
60+
@echo -e " $(OK) clean"

fluent-dedent/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
"email": "[email protected]"
1212
}
1313
],
14-
"directories": {
15-
"lib": "./src"
16-
},
14+
"type": "commonjs",
1715
"main": "./index.js",
18-
"module": "./src/index.js",
16+
"module": "./esm/index.js",
17+
"types": "./esm/index.d.ts",
1918
"repository": {
2019
"type": "git",
2120
"url": "https://github.com/projectfluent/fluent.js.git"

fluent-dedent/src/index.js renamed to fluent-dedent/src/index.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,28 @@ const RE_BLANK = /^[ \t]*$/;
99
* line and it must end on a line of its own, with the closing delimiter on a
1010
* next line.
1111
*
12-
* @param {Array<string>} strings
13-
* @param {...any} values
14-
* @returns string
12+
* @param strings
13+
* @param values
1514
*/
16-
export default function ftl(strings, ...values) {
15+
export default function ftl(
16+
strings: TemplateStringsArray,
17+
...values: Array<unknown>
18+
): string {
1719
let code = strings.reduce((acc, cur) => acc + values.shift() + cur);
1820
let lines = code.split("\n");
19-
let [first, commonIndent] = [lines.shift(), lines.pop()];
2021

21-
if (!RE_BLANK.test(first)) {
22+
let first = lines.shift();
23+
if (first === undefined || !RE_BLANK.test(first)) {
2224
throw new RangeError("Content must start on a new line.");
2325
}
24-
if (!RE_BLANK.test(commonIndent)) {
26+
27+
let commonIndent = lines.pop();
28+
if (commonIndent === undefined || !RE_BLANK.test(commonIndent)) {
2529
throw new RangeError("Closing delimiter must appear on a new line.");
2630
}
2731

28-
function dedent(line, idx) {
29-
let lineIndent = line.slice(0, commonIndent.length);
32+
function dedent(line: string, idx: number): string {
33+
let lineIndent = line.slice(0, (commonIndent as string).length);
3034
if (lineIndent.length === 0) {
3135
// Empty blank lines are preserved even if technically they are not
3236
// indented at all. This also short-circuits the dedentation logic when

fluent-dedent/test/blank_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict";
22

33
import assert from "assert";
4-
import ftl from "../src/index";
4+
import ftl from "../esm/index";
55

66
suite("blank lines", function() {
77
test("leading", function() {

fluent-dedent/test/content_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict";
22

33
import assert from "assert";
4-
import ftl from "../src/index";
4+
import ftl from "../esm/index";
55

66
suite("content lines", function() {
77
test("no indent", function () {

fluent-dedent/test/eol_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict";
22

33
import assert from "assert";
4-
import ftl from "../src/index";
4+
import ftl from "../esm/index";
55

66
suite("EOL at extremes", function () {
77
test("no EOLs", function () {

fluent-dedent/test/interpolation_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict";
22

33
import assert from "assert";
4-
import ftl from "../src/index";
4+
import ftl from "../esm/index";
55

66
suite("interpolation", function() {
77
test("single", function() {

fluent-dedent/test/mixed_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict";
22

33
import assert from "assert";
4-
import ftl from "../src/index";
4+
import ftl from "../esm/index";
55

66
suite("mixed indent", function() {
77
test("same amount", function() {

fluent-dedent/test/tabs_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict";
22

33
import assert from "assert";
4-
import ftl from "../src/index";
4+
import ftl from "../esm/index";
55

66
suite("tab indent", function() {
77
test("same amount", function() {

fluent-dedent/tsconfig.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2019",
4+
"module": "es2015",
5+
"strict": true,
6+
"allowJs": false,
7+
"esModuleInterop": true,
8+
"moduleResolution": "node",
9+
"noEmitHelpers": true,
10+
"declaration": true,
11+
"outDir": "./esm",
12+
},
13+
"include": [
14+
"./src/**/*.ts"
15+
]
16+
}

0 commit comments

Comments
 (0)