Skip to content

rwoodr/fontcheck

Repository files navigation

fontcheck.js

Test if a font or list of fonts is available in users browser

Versions

There are two versions available: fontcheck.js (1.x.x) and fontcheck-module.js (2.x.x). The first is a simple function, easy to copy and paste and a simple way to check a few fonts (one at a time). The module version is a better choice if you need to check a large number of fonts, it accepts an array of font names and returns a promise. The promise will resolve to an array of fonts that were detected.

Demo

Check out the example to see it in action

Usage - simple function version (fontcheck.min.js)

// Log true if font Consolas is available
console.log(fontCheck('Consolas'));

Usage - module version (fontcheck-module.min.js)

import FontCheckModule from './fontcheck-module.min.js';

let fontCheck = new FontCheckModule();

// Check single font
console.log(fontCheck.isUsable('Arial'));

// Check array of fonts
fontCheck.filterFonts(['Consolas', 'Menlo', 'Times New Roman'])
    .then(result => console.log(result));
    .catch(error => console.log(error));

Install

Simple function version:
Copy and paste the contents of fontcheck.min.js into your code
or
Save a copy of fontcheck.min.js and reference it in a <script> tag

Module version:
Save a copy of fontcheck-module.min.js and use import in your code

Yarn install (module version)

$ yarn add fontcheck

Copyright

Copyright 2018 Robert Woodruff

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Alternatives

Here are the alternatives I tested before doing it myself:

test-fonts.json

The test-fonts.json file I am using for the demo page is Copyright 2016 orleika/available-fonts which is published under the MIT License.

About

Test if a font is available in users browser

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published