MCPcopy Create free account
hub / github.com/p2r3/convert / FormatDefinition

Class FormatDefinition

src/FormatHandler.ts:36–140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34 * that can be supported by handlers.
35 */
36export class FormatDefinition implements IFormatDefinition {
37 public readonly name: string;
38 public readonly format: string;
39 public readonly extension: string;
40 public readonly mime: string;
41 public readonly category?: string[] | string;
42
43 constructor(
44 name: string,
45 format: string,
46 extension: string,
47 mime: string,
48 category?: string[] | string
49 ) {
50 this.name = name
51 this.format = format
52 this.extension = extension
53 this.mime = mime
54 this.category = category
55 }
56
57 /**
58 * Returns `FileFormat` object that uses this format definition
59 * and specified options
60 * @param ref Format identifier for the handler's internal reference.
61 * @param from Whether conversion **from** this format is supported.
62 * @param to Whether conversion **to** this format is supported.
63 * @param lossless (Optional) Whether the format is lossless in this context. Defaults to `false`.
64 * @param override Format definition values to override
65 * @returns
66 */
67 supported(ref: string, from: boolean, to: boolean, lossless?: boolean, override: Partial<IFormatDefinition> = {}): FileFormat {
68 return {
69 ...this,
70 ...override,
71 internal: ref,
72 from: from,
73 to: to,
74 lossless: lossless ?? false
75 }
76 }
77
78 /**
79 * Returns a builder to fluently create FileFormat.
80 * Builder can be used to create FileFormat based on this format definition
81 */
82 builder(ref: string) {
83 const def = this;
84
85 const builder = {
86 // FileFormat fields
87 name: def.name,
88 format: def.format,
89 extension: def.extension,
90 mime: def.mime,
91 category: def.category,
92 internal: ref,
93 from: false,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…