@archoleat/validate-font-file-name 1.0.0 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -3
- package/index.d.ts +15 -10
- package/index.js +1 -1
- package/package.json +4 -5
package/README.md
CHANGED
|
@@ -14,10 +14,16 @@
|
|
|
14
14
|
## Table of Contents
|
|
15
15
|
|
|
16
16
|
- [Installation](#installation)
|
|
17
|
+
|
|
17
18
|
- [Usage](#usage)
|
|
19
|
+
- [Your Regex](#your-regex)
|
|
20
|
+
|
|
18
21
|
- [Naming Convention](#naming-convention)
|
|
22
|
+
|
|
19
23
|
- [Troubleshooting](#troubleshooting)
|
|
24
|
+
|
|
20
25
|
- [Contributing](#contributing)
|
|
26
|
+
|
|
21
27
|
- [License](#license)
|
|
22
28
|
|
|
23
29
|
## Installation
|
|
@@ -45,11 +51,11 @@ import validateFontFileName from '@archoleat/validate-font-file-name';
|
|
|
45
51
|
const validFontFileName = 'src/fonts/OpenSans-Regular.woff2';
|
|
46
52
|
const invalidFontFileName = 'src/fonts/OpenSans.woff2';
|
|
47
53
|
|
|
48
|
-
console.log(validateFontFileName(validFontFileName))
|
|
49
54
|
// returns: true
|
|
55
|
+
console.log(validateFontFileName(validFontFileName))
|
|
50
56
|
|
|
57
|
+
// returns: '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)$/'.
|
|
51
58
|
console.log(validateFontFileName(invalidFontFileName))
|
|
52
|
-
// returns: 'OpenSans.woff2' doesn't match the '{FontFamily}-{FontWeight}.{ext}'.
|
|
53
59
|
```
|
|
54
60
|
|
|
55
61
|
or
|
|
@@ -60,11 +66,31 @@ import validateFontFileName from '@archoleat/validate-font-file-name';
|
|
|
60
66
|
const validFontFileName = 'OpenSans-Regular.woff2';
|
|
61
67
|
const invalidFontFileName = 'OpenSans.woff2';
|
|
62
68
|
|
|
69
|
+
// returns: true
|
|
63
70
|
console.log(validateFontFileName(validFontFileName))
|
|
71
|
+
|
|
72
|
+
// returns: '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)$/'.
|
|
73
|
+
console.log(validateFontFileName(invalidFontFileName))
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Your Regex
|
|
77
|
+
|
|
78
|
+
You can also specify your pattern:
|
|
79
|
+
|
|
80
|
+
```js
|
|
81
|
+
import validateFontFileName from '@archoleat/validate-font-file-name';
|
|
82
|
+
|
|
83
|
+
// You can also specify `new RegExp()` and a regular `string`
|
|
84
|
+
const yourPattern = /OpenSans-regular/;
|
|
85
|
+
|
|
86
|
+
const validFontFileName = 'OpenSans-regular';
|
|
87
|
+
const invalidFontFileName = 'OpenSans.woff2';
|
|
88
|
+
|
|
64
89
|
// returns: true
|
|
90
|
+
console.log(validateFontFileName(validFontFileName))
|
|
65
91
|
|
|
92
|
+
// returns: 'OpenSans.woff2' doesn't match with '/OpenSans-regular/'.
|
|
66
93
|
console.log(validateFontFileName(invalidFontFileName))
|
|
67
|
-
// returns: 'OpenSans.woff2' doesn't match the '{FontFamily}-{FontWeight}.{ext}'.
|
|
68
94
|
```
|
|
69
95
|
|
|
70
96
|
## Naming Convention
|
package/index.d.ts
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The function `validateFontFileName`
|
|
3
|
-
* file name
|
|
2
|
+
* The asynchronous function `validateFontFileName` validates
|
|
3
|
+
* if a given font file name matches a specific pattern.
|
|
4
4
|
*
|
|
5
|
-
* @param {string} file - The `
|
|
6
|
-
* a
|
|
7
|
-
*
|
|
5
|
+
* @param {string} file - The `file` parameter in the `validateFontFileName`
|
|
6
|
+
* function is a string that represents the file name of a font file that
|
|
7
|
+
* you want to validate.
|
|
8
8
|
*
|
|
9
|
-
* @
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* @param {RegExp | string} regex - The `regex` parameter in the
|
|
10
|
+
* `validateFontFileName` function is used to provide a custom regular
|
|
11
|
+
* expression pattern for validating the font file name. If a custom
|
|
12
|
+
* regex pattern is not provided, the function uses a default pattern
|
|
13
|
+
* to validate the font file name.
|
|
14
|
+
*
|
|
15
|
+
* @returns The function `validateFontFileName` is returning a boolean value.
|
|
16
|
+
* It returns `true` if the file name matches the specified pattern,
|
|
17
|
+
* and `false` if it does not match.
|
|
13
18
|
*/
|
|
14
|
-
declare const validateFontFileName: (file: string) => Promise<boolean>;
|
|
19
|
+
declare const validateFontFileName: (file: string, regex?: RegExp | string) => Promise<boolean>;
|
|
15
20
|
|
|
16
21
|
export { validateFontFileName as default };
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{parse as
|
|
1
|
+
import{parse as N}from"node:path";import f from"chalk";const _=async(e,t="")=>{const o="[A-Z][a-z]",n=`^${o}+(${o}+)?`,E=["Thin","Hairline","ExtraLight","UltraLight","Light","Regular","Medium","SemiBold","DemiBold","Bold","ExtraBold","UltraBold","Black","Heavy","ExtraBlack","UltraBlack"].join("|"),c=["otf","ttf","woff","woff2"].join("|"),l=`(${n})`,r=`(${E})`,s=`(${c})$`,i=new RegExp(`${l}-${r}\\.${s}`),a=N(e).base,T=typeof t=="string"&&t!==""?new RegExp(t):t||i;return T.test(a)?!0:(console.error(f.red.bold(`'${a}' doesn't match with '${T}'.`)),!1)};export{_ as default};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@archoleat/validate-font-file-name",
|
|
3
3
|
"description": "Checking font file names for standardization",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.4",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
7
7
|
"email": "archoleat@gmail.com",
|
|
@@ -40,8 +40,7 @@
|
|
|
40
40
|
"type": "module",
|
|
41
41
|
"types": "index.d.ts",
|
|
42
42
|
"exports": {
|
|
43
|
-
".": "./index.js"
|
|
44
|
-
"./*": "./commitlint.config.ts"
|
|
43
|
+
".": "./index.js"
|
|
45
44
|
},
|
|
46
45
|
"files": [
|
|
47
46
|
"index.d.ts",
|
|
@@ -64,10 +63,10 @@
|
|
|
64
63
|
"chalk": "^5.3.0"
|
|
65
64
|
},
|
|
66
65
|
"devDependencies": {
|
|
66
|
+
"@archoleat/commitlint-define-config": "^1.0.0",
|
|
67
67
|
"@archoleat/semantic-release-define-config": "^1.1.0",
|
|
68
68
|
"@commitlint/cli": "^18.6.1",
|
|
69
|
-
"@commitlint/config-conventional": "^
|
|
70
|
-
"@commitlint/types": "^18.6.1",
|
|
69
|
+
"@commitlint/config-conventional": "^19.1.0",
|
|
71
70
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
72
71
|
"@semantic-release/changelog": "^6.0.3",
|
|
73
72
|
"@semantic-release/git": "^10.0.1",
|