forked from ember-tooling/prettier-plugin-ember-template-tag
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent-tag.ts
More file actions
41 lines (32 loc) · 859 Bytes
/
content-tag.ts
File metadata and controls
41 lines (32 loc) · 859 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* eslint-disable jsdoc/require-jsdoc, unicorn/prefer-export-from */
import {
type Parsed as ContentTag,
Preprocessor,
type PreprocessorOptions,
type Range,
} from 'content-tag';
const BufferMap = new Map<string, Buffer>();
export function getBuffer(string_: string): Buffer {
let buffer = BufferMap.get(string_);
if (!buffer) {
buffer = Buffer.from(string_);
BufferMap.set(string_, buffer);
}
return buffer;
}
export function parse(
file: string,
options?: PreprocessorOptions,
): ContentTag[] {
const preprocessor = new Preprocessor();
return preprocessor.parse(file, options);
}
export function sliceByteRange(
string_: string,
indexStart: number,
indexEnd?: number,
): string {
const buffer = getBuffer(string_);
return buffer.slice(indexStart, indexEnd).toString();
}
export type { ContentTag, Range };