Skip to content

archoleat/validate-font-file-name

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

73 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Validate Font File Name

NPM Version NPM Downloads ESM Provenance CodeQL Specs Commitlint Editorconfig Prettier ESLint Remark

Table of Contents

Installation

bun i -D @archoleat/validate-font-file-name

Usage

import { validateFontFileName } from '@archoleat/validate-font-file-name';

const validFontFileName = 'OpenSans-Regular.woff2';
const invalidFontFileName = 'OpenSans.woff2';

// returns: true
console.log(await validateFontFileName({ file: validFontFileName }));

// returns: {current time} [ERROR] 'OpenSans.woff2' doesn't match with '/(^[A-Z][a-z]+([A-Z][a-z]+)?)-(Thin|Hairline|ExtraLight|UltraLight|Light|Regular|Medium|SemiBold|DemiBold|Bold|ExtraBold|UltraBold|Black|Heavy|ExtraBlack|UltraBlack)\.(otf|ttf|woff|woff2)$/'.
console.log(await validateFontFileName({ file: invalidFontFileName }));

Your Regex

You can also specify your regex:

import { validateFontFileName } from '@archoleat/validate-font-file-name';

// You can also specify `new RegExp()` and a regular `string`
const yourRegex = /OpenSans-regular/;

const validFontFileName = 'OpenSans-regular';
const invalidFontFileName = 'OpenSans.woff2';

// returns: true
console.log(await validateFontFileName({
  file: validFontFileName,
  regex: yourRegex,
}));

// returns: {current time} [ERROR] 'OpenSans.woff2' doesn't match with '/OpenSans-regular/'.
console.log(await validateFontFileName({
  file: invalidFontFileName,
  regex: yourRegex,
}));

Naming Convention

The font family and font weight must be in Pascal Case and separated by a hyphen.

Extensions that are allowed: otf, ttf, woff, woff2.

{FontFamily}-{FontWeight}.{extension}

Contributing

Please read CONTRIBUTING to start contributing.

License

This project is licensed under the MIT license.