Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

css-font-face-src

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

css-font-face-src

A CSS @font-face src property value parser

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

CSS @font-face rule src field parser – css-font-face-src

NPM version

A CSS @font-face src property value parser.

Basically it provides two operations:

  • parse: To convert a CSS property string to an array of easily readable objects. Each object either describes a local font (referenced using its family name) or a remote font (referenced using its URL).
  • serialize: To convert an object array back to a CSS property string.

Examples

JavaScript verison (CJS, using require)

Parse
const parser = require('css-font-face-src');

console.log(parser.parse('local("The Font"), url("font.otf") format("opentype"), url("font.woff"), local("Another Font")'));

will return:

[
    { local: 'The Font' },
    { url: 'font.otf', format: 'opentype' },
    { url: 'font.woff' },
    { local: 'Another Font' }
]
Serialize
const parser = require('css-font-face-src');

console.log(
    parser.serialize([
        { local: 'The Font' },
        { url: 'font.otf', format: 'opentype' },
        { url: 'font.woff' },
        { local: 'Another Font' }
    ])
);

will return:

'local("The Font"), url("font.otf") format("opentype"), url("font.woff"), local("Another Font")'

JavaScript version (ESM, using import)

Parse
import { parse } from 'css-font-face-src';

console.log(parse('local("The Font"), url("font.otf") format("opentype"), url("font.woff"), local("Another Font")'));

will return:

[
    { local: 'The Font' },
    { url: 'font.otf', format: 'opentype' },
    { url: 'font.woff' },
    { local: 'Another Font' }
]
Serialize
import { serialize } from 'css-font-face-src';

console.log(
    serialize([
        { local: 'The Font' },
        { url: 'font.otf', format: 'opentype' },
        { url: 'font.woff' },
        { local: 'Another Font' }
    ])
);

will return:

'local("The Font"), url("font.otf") format("opentype"), url("font.woff"), local("Another Font")'

TypeScript version

Parse
import { parse } from 'css-font-face-src';

console.log(parse('local("The Font"), url("font.otf") format("opentype"), url("font.woff"), local("Another Font")'));

will return:

[
    { local: 'The Font' },
    { url: 'font.otf', format: 'opentype' },
    { url: 'font.woff' },
    { local: 'Another Font' }
]
Serialize
import { serialize, FontFaceSrcItem } from 'css-font-face-src';

console.log(
    serialize([
        { local: 'The Font' },
        { url: 'font.otf', format: 'opentype' },
        { url: 'font.woff' },
        { local: 'Another Font' }
    ] as FontFaceSrcItem[])
);

will return:

'local("The Font"), url("font.otf") format("opentype"), url("font.woff"), local("Another Font")'

Build status

Build Status

Author

Christoph Burgmer. Licensed under BSD-2-Clause. Reach out on Twitter.

Keywords

FAQs

Package last updated on 24 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc