• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

streetsidesoftware / cspell / 12457971703

22 Dec 2024 09:54PM UTC coverage: 93.54% (-0.5%) from 94.057%
12457971703

Pull #6702

github

web-flow
Merge 729f6b53a into 3d16857fe
Pull Request #6702: fix: reduce size when bundled

11604 of 13369 branches covered (86.8%)

15147 of 16193 relevant lines covered (93.54%)

30926.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.89
/packages/cspell-io/src/common/CFileReference.ts
1
import type { BufferEncoding } from '../models/BufferEncoding.js';
2
import type { FileReference, FileResourceRequest, UrlOrReference } from '../models/FileResource.js';
3
import { toFileURL } from '../node/file/url.js';
4

5
export class CFileReference implements FileReference {
×
6
    /**
7
     * Use to ensure the nominal type separation between CFileReference and FileReference
8
     * See: https://github.com/microsoft/TypeScript/wiki/FAQ#when-and-why-are-classes-nominal
9
     */
10
    private _?: undefined;
11
    readonly gz: boolean | undefined;
12

13
    constructor(
14
        readonly url: URL,
77✔
15
        readonly encoding: BufferEncoding | undefined,
77✔
16
        readonly baseFilename: string | undefined,
77✔
17
        gz: boolean | undefined,
18
    ) {
19
        this.gz = gz ?? (baseFilename?.endsWith('.gz') || undefined) ?? (url.pathname.endsWith('.gz') || undefined);
77✔
20
    }
21

22
    static isCFileReference(obj: unknown): obj is CFileReference {
23
        return obj instanceof CFileReference;
34✔
24
    }
25

26
    static from(fileReference: FileReference): CFileReference;
27
    static from(
28
        url: URL,
29
        encoding?: BufferEncoding,
30
        baseFilename?: string | undefined,
31
        gz?: boolean | undefined,
32
    ): CFileReference;
33
    static from(
34
        fileReference: FileReference | URL,
35
        encoding?: BufferEncoding,
36
        baseFilename?: string,
37
        gz?: boolean | undefined,
38
    ): CFileReference {
39
        if (CFileReference.isCFileReference(fileReference)) return fileReference;
9✔
40
        if (fileReference instanceof URL) return new CFileReference(fileReference, encoding, baseFilename, gz);
8!
41
        return new CFileReference(
8✔
42
            fileReference.url,
43
            fileReference.encoding,
44
            fileReference.baseFilename,
45
            fileReference.gz,
46
        );
47
    }
48

49
    public toJson() {
50
        return {
×
51
            url: this.url.href,
52
            encoding: this.encoding,
53
            baseFilename: this.baseFilename,
54
            gz: this.gz,
55
        };
56
    }
57
}
58

59
/**
60
 *
61
 * @param file - a URL, file path, or FileReference
62
 * @param encoding - optional encoding used to decode the file.
63
 * @param baseFilename - optional base filename used with data URLs.
64
 * @param gz - optional flag to indicate if the file is gzipped.
65
 * @returns a FileReference
66
 */
67
export function toFileReference(
68
    file: UrlOrReference,
69
    encoding?: BufferEncoding,
70
    baseFilename?: string,
71
    gz?: boolean | undefined,
72
): FileReference {
73
    const fileReference = typeof file === 'string' ? toFileURL(file) : file;
76✔
74
    if (fileReference instanceof URL) return new CFileReference(fileReference, encoding, baseFilename, gz);
76✔
75
    return CFileReference.from(fileReference);
9✔
76
}
77

78
export function isFileReference(ref: UrlOrReference): ref is FileReference {
79
    return CFileReference.isCFileReference(ref) || (!(ref instanceof URL) && typeof ref !== 'string');
25✔
80
}
81

82
export function renameFileReference(ref: FileReference, newUrl: URL): FileReference {
83
    return new CFileReference(newUrl, ref.encoding, ref.baseFilename, ref.gz);
2✔
84
}
85

86
export function toFileResourceRequest(
87
    file: UrlOrReference,
88
    encoding?: BufferEncoding,
89
    signal?: AbortSignal,
90
): FileResourceRequest {
91
    const fileReference = typeof file === 'string' ? toFileURL(file) : file;
29✔
92
    if (fileReference instanceof URL) return { url: fileReference, encoding, signal };
29✔
93
    return { url: fileReference.url, encoding: encoding ?? fileReference.encoding, signal };
3✔
94
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc