font-basic v1.0.1
Font Basic
font-basic
is a lightweight and flexible npm package designed to streamline the management and usage of font families in web projects. It provides an easy-to-use API for defining, loading, and applying fonts in a consistent manner across your applications.
Table of Contents
Installation
You can install the package using npm:
npm install font-basic
or yarn:
yarn add font-basic
Usage
Basic Usage
To get started with font-basic
, simply import it into your project and define the fonts you want to use:
import FontBasic from 'font-basic';
// Define your font families
FontBasic.addFonts({
'custom-font': {
normal: 'https://path-to-your-font.woff2',
bold: 'https://path-to-your-font-bold.woff2',
},
});
// Apply font to an element
FontBasic.applyFont('custom-font', 'normal', '.my-text');
Advanced Configuration
You can apply additional configurations such as loading fallback fonts or defining global styles. Here’s an example:
import FontBasic from 'font-basic';
// Configuring with fallbacks
FontBasic.addFonts({
'custom-font': {
normal: ['https://path-to-your-font.woff2', 'Arial', 'sans-serif'],
bold: ['https://path-to-your-font-bold.woff2', 'Arial Black', 'sans-serif'],
},
});
// Set default font for the entire application
FontBasic.setDefaultFont('custom-font', 'normal');
// Alternatively, apply to specific classes
FontBasic.applyFont('custom-font', 'bold', '.my-title');
API Reference
FontBasic.addFonts(fonts: Object)
Adds font definitions to font-basic
.
- fonts: An object where each key is a font family name and its value is an object of font styles.
FontBasic.applyFont(fontFamily: string, style: string, selector: string)
Applies the specified font family and style to the selected elements.
- fontFamily: The name of the font family as defined in the
addFonts
method. - style: The style of the font to apply (
normal
orbold
). - selector: The CSS selector for the elements to which the font should be applied.
FontBasic.setDefaultFont(fontFamily: string, style: string)
Sets a default font for the entire application.
- fontFamily: The name of the font family to set as default.
- style: The style of the font to set as default.
Contributing
We welcome contributions to font-basic
. If you'd like to contribute, please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature/YourFeatureName
). - Make your changes and commit them (
git commit -m 'Add some feature'
). - Push to the branch (
git push origin feature/YourFeatureName
). - Open a pull request.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Enjoy using font-basic
in your projects!
3 months ago