@dprint/typescript 0.74.0 → 0.76.0
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.
- package/README.md +5 -3
- package/index.d.ts +2 -2
- package/index.js +5 -28
- package/package.json +2 -2
- package/plugin.wasm +0 -0
- package/buffer.generated.js +0 -1
package/README.md
CHANGED
|
@@ -2,15 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
npm distribution of [dprint-plugin-typescript](https://github.com/dprint/dprint-plugin-typescript).
|
|
4
4
|
|
|
5
|
-
Use this with [@dprint/formatter](https://github.com/dprint/js-formatter) or just use @dprint/formatter and download the [dprint-plugin-typescript
|
|
5
|
+
Use this with [@dprint/formatter](https://github.com/dprint/js-formatter) or just use @dprint/formatter and download the [dprint-plugin-typescript Wasm file](https://github.com/dprint/dprint-plugin-typescript/releases).
|
|
6
6
|
|
|
7
7
|
## Example
|
|
8
8
|
|
|
9
9
|
```ts
|
|
10
10
|
import { createFromBuffer } from "@dprint/formatter";
|
|
11
|
-
import {
|
|
11
|
+
import { getPath } from "@dprint/typescript";
|
|
12
|
+
import * as fs from "fs";
|
|
12
13
|
|
|
13
|
-
const
|
|
14
|
+
const buffer = fs.readFileSync(getPath());
|
|
15
|
+
const formatter = createFromBuffer(buffer);
|
|
14
16
|
|
|
15
17
|
console.log(formatter.formatText("test.ts", "const t = 5;"));
|
|
16
18
|
```
|
package/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/** Gets
|
|
2
|
-
export function
|
|
1
|
+
/** Gets an absolute path to the Wasm module. */
|
|
2
|
+
export function getPath(): string;
|
package/index.js
CHANGED
|
@@ -1,34 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Gets
|
|
3
|
-
* @returns {
|
|
2
|
+
* Gets the path to the Wasm module.
|
|
3
|
+
* @returns {string}
|
|
4
4
|
*/
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
return decodeEncodedBuffer(encodedBuffer);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @param {string} encodedBuffer
|
|
12
|
-
* @returns {ArrayBuffer}
|
|
13
|
-
*/
|
|
14
|
-
function decodeEncodedBuffer(encodedBuffer) {
|
|
15
|
-
// https://stackoverflow.com/a/51473757/188246
|
|
16
|
-
const binaryString = toBinaryString();
|
|
17
|
-
const bytes = new Uint8Array(binaryString.length);
|
|
18
|
-
for (let i = 0; i < binaryString.length; i++) {
|
|
19
|
-
bytes[i] = binaryString.charCodeAt(i);
|
|
20
|
-
}
|
|
21
|
-
return bytes.buffer;
|
|
22
|
-
|
|
23
|
-
function toBinaryString() {
|
|
24
|
-
if (typeof atob === "function") {
|
|
25
|
-
return atob(encodedBuffer);
|
|
26
|
-
} else {
|
|
27
|
-
return Buffer.from(encodedBuffer, "base64").toString("binary");
|
|
28
|
-
}
|
|
29
|
-
}
|
|
5
|
+
function getPath() {
|
|
6
|
+
return require("path").join(__dirname, "plugin.wasm");
|
|
30
7
|
}
|
|
31
8
|
|
|
32
9
|
module.exports = {
|
|
33
|
-
|
|
10
|
+
getPath,
|
|
34
11
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dprint/typescript",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Wasm
|
|
3
|
+
"version": "0.76.0",
|
|
4
|
+
"description": "Wasm module for dprint-plugin-typescript.",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"types": "./index.d.ts",
|
|
7
7
|
"repository": {
|
package/plugin.wasm
ADDED
|
Binary file
|