Add prepublish

This commit is contained in:
Sofía Aritz 2023-05-20 21:47:24 +02:00
parent 686be9bf11
commit fa3e874a95
10 changed files with 3 additions and 113 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
.idea/ .idea/
node_modules/ node_modules/
dist/

9
dist/css2.d.ts vendored
View file

@ -1,9 +0,0 @@
export type Variant = {
weight: number;
style: string;
};
export interface Spec {
font: string;
variants: Variant[];
}
export declare function parse_spec(input: string): Spec;

47
dist/css2.js vendored
View file

@ -1,47 +0,0 @@
export function parse_spec(input) {
let spec = {};
let [family_name, ...rest] = input.split(":");
spec["font"] = family_name.replace("+", " ");
let variants = [];
if (rest.length > 0) {
let contains_italic = false;
let is_custom_weight = false;
let raxis = rest.join("");
let [raxis_tag_list, axis_tuple_list] = raxis.split("@");
let axis_tag_list = raxis_tag_list.split(",");
for (let axis of axis_tag_list) {
if (axis === "ital") {
contains_italic = true;
}
if (axis === "wght") {
is_custom_weight = true;
}
}
for (let tuple of axis_tuple_list.split(";")) {
if (contains_italic) {
let [italic, weight] = tuple.split(",");
if (weight == null || weight.length === 0) {
weight = "400";
}
variants.push({
weight: Number(weight),
style: italic === "1" ? "italic" : "normal",
});
}
else {
variants.push({
weight: Number(tuple),
style: "normal",
});
}
}
}
else {
variants.push({
weight: 400,
style: "normal",
});
}
spec["variants"] = variants;
return spec;
}

0
dist/index.d.ts vendored
View file

0
dist/index.js vendored
View file

5
dist/metadata.d.ts vendored
View file

@ -1,5 +0,0 @@
import { FontMetadata } from "./utils";
export declare function retrieve_font_metadata(font: string, mirror: string): Promise<{
url: string;
metadata: FontMetadata;
}>;

25
dist/metadata.js vendored
View file

@ -1,25 +0,0 @@
import { parse } from "pb-parser";
import { base_url } from "./utils";
async function font_metadata_folder(folder, font, mirror) {
let url = base_url(mirror, folder, font) + "/METADATA.pb";
try {
let response = await (await fetch(url));
if (response.ok) {
return [url, await response.text()];
}
return null;
}
catch (e) {
return null;
}
}
export async function retrieve_font_metadata(font, mirror) {
let fontname = font.replace(" ", "").toLowerCase();
let [url, raw_metadata] = (await font_metadata_folder("ofl", fontname, mirror))
|| (await font_metadata_folder("ufl", fontname, mirror))
|| (await font_metadata_folder("apache", fontname, mirror));
return {
url,
metadata: parse(raw_metadata)
};
}

23
dist/utils.d.ts vendored
View file

@ -1,23 +0,0 @@
export interface FontInfo {
copyright?: string;
filename: string;
full_name?: string;
name?: string;
post_script_name?: string;
style: string;
weight: number;
}
export interface FontMetadata {
name: string;
designer?: string;
license?: string;
category: string;
date_added?: string;
font: FontInfo[] | FontInfo;
axes?: {
tag: string;
max_value: number;
min_value: number;
};
}
export declare function base_url(mirror: string, folder: string, font: string): string;

3
dist/utils.js vendored
View file

@ -1,3 +0,0 @@
export function base_url(mirror, folder, font) {
return `${mirror}/${folder}/${font}`;
}

View file

@ -5,7 +5,8 @@
"types": "dist/index.d.ts", "types": "dist/index.d.ts",
"license": "Apache-2.0", "license": "Apache-2.0",
"scripts": { "scripts": {
"test": "mocha --require ts-node/register src/**/*.spec.ts" "test": "mocha --require ts-node/register src/**/*.spec.ts",
"prepublish": "tsc"
}, },
"devDependencies": { "devDependencies": {
"@types/mocha": "^10.0.1", "@types/mocha": "^10.0.1",