Skip to content

Commit 7911fad

Browse files
committed
Updating docs
1 parent f1318bf commit 7911fad

File tree

1 file changed

+39
-35
lines changed

1 file changed

+39
-35
lines changed

README.md

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,30 @@ npm install content-tag
1414

1515
### Node (CommonJS)
1616

17-
```js
18-
let { Preprocessor } = require('content-tag');
17+
```js
18+
let { Preprocessor } = require("content-tag");
1919
let p = new Preprocessor();
20-
let output = p.process('<template>Hi</template>');
20+
let output = p.process("<template>Hi</template>");
2121

2222
console.log(output);
2323
```
2424

25-
2625
### Node (ESM)
2726

2827
```js
29-
import { Preprocessor } from 'content-tag';
28+
import { Preprocessor } from "content-tag";
3029
let p = new Preprocessor();
31-
let output = p.process('<template>Hi</template>');
30+
let output = p.process("<template>Hi</template>");
3231

3332
console.log(output);
3433
```
3534

3635
### Browser (ESM)
3736

3837
```js
39-
import { Preprocessor } from 'content-tag';
38+
import { Preprocessor } from "content-tag";
4039
let p = new Preprocessor();
41-
let output = p.process('<template>Hi</template>');
40+
let output = p.process("<template>Hi</template>");
4241

4342
console.log(output);
4443
```
@@ -55,9 +54,9 @@ Parses a given source code string using the `content-tag` spec into standard
5554
JavaScript.
5655

5756
```ts
58-
import { Preprocessor } from 'content-tag';
57+
import { Preprocessor } from "content-tag";
5958
let p = new Preprocessor();
60-
let output = p.process('<template>Hi</template>');
59+
let output = p.process("<template>Hi</template>");
6160
```
6261

6362
### `Preprocessor.parse(src: string, options?: PreprocessorOptions): Parsed[];`
@@ -66,29 +65,40 @@ Parses a given source code string using the `content-tag` spec into an array of
6665
`Parsed` content tag objects.
6766

6867
```ts
69-
import { Preprocessor } from 'content-tag';
68+
import { Preprocessor } from "content-tag";
7069
let p = new Preprocessor();
71-
let output = p.parse('<template>Hi</template>');
70+
let output = p.parse("<template>Hi</template>");
7271
```
7372

7473
#### `PreprocessorOptions`
7574

76-
````ts
75+
```ts
7776
interface PreprocessorOptions {
78-
7977
/** Default is `false` */
8078
inline_source_map?: boolean;
8179

8280
filename?: string;
83-
8481
}
85-
````
82+
```
8683

8784
#### `Parsed`
8885

89-
NOTE: All ranges are in bytes, not characters.
90-
9186
````ts
87+
interface Range {
88+
// Range in raw bytes.
89+
startByte: number;
90+
endByte: number;
91+
92+
// Range in unicode characters. If you're trying to slice out parts of the tring, you want this, not the byte.
93+
//
94+
// CAUTION: Javascript String.prototype.slice is not actually safe to use on these values
95+
// because it gets characters beyond UTF16 wrong. You want:
96+
// Array.from(myString).slice(startChar, endChar).join('')
97+
// instead.
98+
startChar: number;
99+
endChar: number;
100+
}
101+
92102
interface Parsed {
93103
/**
94104
* The type for the content tag.
@@ -116,38 +126,32 @@ interface Parsed {
116126
contents: string;
117127

118128
/**
119-
* Byte range of the contents, inclusive of inclusive of the
129+
* Range of the contents, inclusive of the
120130
* `<template></template>` tags.
121131
*/
122-
range: {
123-
start: number;
124-
end: number;
125-
};
132+
range: Range;
126133

127134
/**
128-
* Byte range of the template contents, not inclusive of the
135+
* Range of the template contents, not inclusive of the
129136
* `<template></template>` tags.
130137
*/
131138
contentRange: {
132139
start: number;
133140
end: number;
134141
};
135142

136-
/** Byte range of the opening `<template>` tag. */
137-
startRange: {
138-
end: number;
139-
start: number;
140-
};
143+
/**
144+
* Range of the opening `<template>` tag.
145+
*/
146+
startRange: Range;
141147

142-
/** Byte range of the closing `</template>` tag. */
143-
endRange: {
144-
start: number;
145-
end: number;
146-
};
148+
/**
149+
* Range of the closing `</template>` tag.
150+
*/
151+
endRange: Range;
147152
}
148153
````
149154

150155
## Contributing
151156

152157
See the [CONTRIBUTING.md](./CONTRIBUTING.md) file.
153-

0 commit comments

Comments
 (0)