css-font-face-src is a focused JavaScript and TypeScript library designed to parse and serialize the `src` property value of CSS `@font-face` rules. It transforms complex CSS `src` strings into an array of structured objects, distinguishing between local font references and remote URLs (with optional format and `tech()` fragments), and can convert these objects back into a valid CSS string. The current stable version is 2.1.0. The package has a moderate release cadence, with significant updates in major versions like v2.0.0 introducing TypeScript support and minor versions adding support for newer CSS specifications (e.g., CSS Fonts Module Level 4 `tech()` fragment in v2.1.0). Its primary differentiator is its dedicated, precise parsing capability for this specific CSS property, providing a reliable programmatic interface for manipulating font declarations.
npm install css-font-face-srcVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates parsing a CSS `src` string, inspecting the resulting object structure, modifying it, and then serializing it back into a CSS string, showcasing both `parse` and `serialize` functions along with TypeScript type usage.
For TypeScript projects, ensure `tsconfig.json` is set up correctly. For JavaScript projects, ensure bundlers are configured to ignore `.d.ts` files if conflicts arise, or explicitly use CommonJS `require` syntax if experiencing issues with module resolution.
Cast your array of font face source objects like `serialize(myArray as FontFaceSrcItem[])` to provide the compiler with the expected type definition.
Ensure you are using version 0.2.2 or higher. Earlier versions may have missing grammar files, causing runtime errors.
If using ESM, ensure you are destructuring named exports: `import { parse, serialize } from 'css-font-face-src';`. If using CommonJS and expecting `parser.parse`, then `const parser = require('css-font-face-src');` is correct. If you incorrectly assumed `require` directly returned `parse`, change to `const { parse } = require('css-font-face-src');`.Explicitly cast the array to `FontFaceSrcItem[]`. For example: `serialize([{ local: 'Font' }] as FontFaceSrcItem[])`.No dependency data recorded yet.