1.1.0 • Published 4 years ago

@ibnlanre/css-weight v1.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

CSS-Font-Weight

License: MIT TypeScript code style: prettier version Twitter

A utility to convert font weight names into number values

Acceptable values include:
    EXTRABOLD, Extra Bold, extra bold, extra-bold, extra_bold

Installation

Local

npm install @ibnlanre/css-weight

API

Script tags

<script src="./node_modules/@ibnlanre/weight.js" type="module"></script>

ES6

import cssWeight from "./node_modules/@ibnlanre/weight.js"
import { openType } from cssWeight
import { weights } from cssWeight

CommonJS

const cssWeight = require("@ibnlanre/css-weight");
const openType = cssWeight.openType;

Reference

openType[300] //-> [ 'Light' ]
cssWeight.weights[350] //-> [ 'Book', 'Demi' ]

Single Arguments

cssWeight(""); //-> "missing query"
cssWeight({ MDN: true }); //-> "query must be a string"
cssWeight("--=HAIR9876LINE Condensed");
//-> { style: 'normal', weight: 200, stretch: 'condensed' }
cssWeight("Italic Book", { MDN: true });
//-> { style: 'italic', weight: 'normal', stretch: 'normal' }

Multiple Arguments

cssWeight("Oblique Poster, Semi_Expanded Demi");
// returns
// [
//   { style: 'oblique', weight: 999, stretch: 'normal' },
//   { style: 'normal', weight: 350, stretch: 'semi-expanded' }
// ]

Default Weights

ValueDescription
100UltraThin
150ExtraThin
200Thin, Hairline, UltraLight
250ExtraLite, ExtraLight
300Lite, Light
350Book, Demi
375Text
400Normal, Regular
425Thick
450Extra Thick
500Dark, Medium
550ExtraDark, Semibold, Demibold
600Bold
650ExtraBold
700UltraBold
800Black
900ExtraBlack, Heavy
999UltraBlack, Fat, Poster

OpenType Weights

To use the font weight definition in the OpenType specification, which is the same shown on MDN, use the option { MDN: true }

ValueDescription
100Thin
200ExtraLight, UltraLight
300Light
400Normal, Regular
500Dark, Medium
600DemiBold, SemiBold
700Bold
800ExtraBold, UltraBold
900Black, Heavy
950ExtraBlack, UltraBlack

References

Acknowledgements

CSS-Font-Weight was inspired by dan-gamble/postcss-font-weight-names