Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,24 @@ Do **not** use `Math.random()` in `fontName` — that renames both font files an

`webfont()` resolves to an object with generated font buffers (and optional `template` output). The `config` property contains the **effective options** used for the run (defaults, discovered config, and any options you passed in), plus optional **output metadata** when a configuration file was found or loaded.

#### TypeScript

`Result` and `ResultConfig` are exported from the package entry, so you can annotate `webfont()` output directly instead of relying on `ReturnType` inference:

```ts
import { webfont, type Result, type ResultConfig } from "webfont";

const result: Result = await webfont({
files: "src/svg-icons/**/*.svg",
});

const config: ResultConfig | undefined = result.config;

if (config?.filePath) {
console.log(`Loaded config from ${config.filePath}`);
}
```

#### `result.config.filePath`

- Type: `string` | `undefined`
Expand Down
12 changes: 11 additions & 1 deletion src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import index from ".";
import index, { type Result, type ResultConfig, webfont } from ".";

describe("index", () => {
it("should be exported", () => {
expect(typeof index === "function").toBe(true);
});

it("should expose webfont as both the default and a named export", () => {
expect(index).toBe(webfont);
});

it("should re-export the public Result and ResultConfig types", () => {
expectTypeOf<Result["config"]>().toEqualTypeOf<ResultConfig | undefined>();
expectTypeOf<ResultConfig>().toHaveProperty("filePath");
expectTypeOf<ResultConfig["filePath"]>().toEqualTypeOf<string | undefined>();
});
});
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ import { webfont } from "./standalone";

export { diagnoseGlyphsData, diagnoseSvgContents } from "./lib/svgDiagnostics/diagnoseSvgContents";
export { webfont } from "./standalone";
export type { Result } from "./types/Result";
export type { ResultConfig } from "./types/ResultConfig";
export type { SvgDiagnosticCode, SvgGlyphDiagnostic, SvgToolsOptions } from "./types/SvgToolsOptions";
export default webfont;