Socket
Socket
Sign inDemoInstall

dr-font-support

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    dr-font-support

Detects supported font formats


Version published
Weekly downloads
0
Maintainers
1
Created
Weekly downloads
 

Readme

Source

dr-font-support

Clientside script to detect woff2, woff, ttf or svg font support.

The detection method is selfcontained and exposed via UMD as a function that accepts a callback. It clocks in at 5.5kb minified and 2.8kb gzipped.

Note: eot detection has been left out on purpose as browser that would otherwise require eot fonts (<IE9) have either no support for datauris or very little (IE8 only supports 32kb) - making detection more or less useless.

Usage

fontSupport(callback /*, returnOption*/)
Arguments
  • callback [function] - Once the tests have been run this callback will be executed.
  • returnOption [array|string|null] - Optional. A format string will return a boolean whether that format is supprted. An array of format strings will return the first listed supported format or null if none of them are supported. Default will return an object with formats as keys with boolean values.

Vanilla JS

With returnOption as null (default):

fontSupport(function (supported) {
	  if (supported.woff2) {
	    // woff2 is supported
	  } 
	  if (supported.woff) {
	    // woff is supported
	  } 
	  if (supported.ttf) {
	    // ttf is supported
	  } 
	  if (supported.svg) {
	    // svg is supported
	  } 
});

With returnOption as string:

fontSupport(function (supported) {
	  if (supported) {
	    // ttf is supported
	  }
}, "ttf");

With returnOption as an array:

fontSupport(function (supported) {
	switch (supported) {
		case "woff":
			// do stuff
			break;
	  		
		case "ttf":
			// do other stuff
			break;
	}
}, ["woff", "ttf"]);

AMD

require(["font-support"], function (supported) {
  // see vanilla js usage
});

Build

Install dependencies:

npm install

Build script:

node build.js

The built index.js script will then be ready for use.

Credits

Testing

The basic template for testing was hoisted from the Modernizr library.

Font generation

Uses svg2ttf and ttf2woff from Vitaly's brilliant collection of libraries.


Changelog

0.3.6

Fixed:

  • Added pre-generated WOFF2 file to avoid errors on manual builds.

0.3.5

Fixed:

  • IE11 bug: @font-face failed OpenType embedding permission check. Permission must be Installable. via nodettfpatch.
  • Subsequent calls to fontSupport didn't execute callbacks.
  • returnOption of array now returned the wrong result.

Changes:

  • WOFF2 now needs to be built manually; needs tooling to automate this :(

0.3.0

Changes:

  • Removed grunt as dependency.

0.2.0

Features:

  • woff2 added.

FAQs

Last updated on 10 Aug 2015

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc