Skip to content

Instantly share code, notes, and snippets.

@quitequinn
Last active March 14, 2024 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quitequinn/601e234980b1aa563dba194fa1125e50 to your computer and use it in GitHub Desktop.
Save quitequinn/601e234980b1aa563dba194fa1125e50 to your computer and use it in GitHub Desktop.
List all Font/Type Weight/Style names (usually used to infer Subfamily name) (Warning 9954+ styles / 255950+ with Italic)
///////////////////////////////
// All Weights
let weights = [];
///////////////////////////////
// All core weights
const coreWeights = ["Hairline", "Thin", "Mager", "Maigre", "Light", "Chiaro", "Lite", "Leicht", "Demi", "Book", "Buch", "Regular", "Normal", "Medium", "Stark", "Thick", "Kräftig", "Viertelfett", "Halbfett", "Dreiviertelfett", "Dark", "Bold", "Neretto", "Gras", "Fett", "Extrafett", "Black", "Nero", "Heavy", "Nerissimo", "Ultra", "Fat", "Poster"];
///////////////////////////////
///////////////////////////////
// Prepend modifiers to each core weight separated by a space and include original weight
const modifiers = ["Demi", "Semi", "Extra", "Ultra", "Super", "Plus"];
let withModifierWeights = coreWeights.map((weight) => {
let newWeights = [];
modifiers.forEach((modifier) => {
newWeights.push(modifier + " " + weight);
});
newWeights.push(weight);
return newWeights;
}).reduce((a, b) => {
return a.concat(b);
});
weights = [...weights, ...withModifierWeights]; // Adding these back to the list of weights
// ///////////////////////////////
// ///////////////////////////////
// // Add in italic variations of each weight
// // This is commented out because it changes the list length from 9954 to 300578 and could crash your browser
// const italics = ["Italic", "Slant", "Oblique", "Cursive", "Rotalic", "Reverse", "Crab Claw", "Crabclaw", "South Paw", "Southpaw", "Backwards", "Backslant", "Backslanted"];
// let withItalicWeights = weights.map((el) => {
// let newEls = [];
// italics.forEach((modifier) => {
// newEls.push(el + " " + modifier);
// });
// return newEls;
// }).reduce((a, b) => {
// return a.concat(b);
// });
// weights = [...weights, ...withItalicWeights]; // Adding these back to the list of weights
///////////////////////////////
///////////////////////////////
// Add a version of each weight where the keys in alternativeSpelling are replaced with each of their values for any of the words that are present in the weight
const alternativeSpelling = {
Hairline: ["Hl", "Hln", "Hlnn", "Hlnne", "Hlnnne"],
ExtraThin: ["Xthin", "Xthn", "Xth", "Xt", "Xthin", "Xthn", "Xth", "Xtra", "Xtr", "XThin", "XThn", "XTh", "XT", "XThin", "XThn", "XTh"],
Thin: ["Thn"],
ExtraLight: ["Xlight", "XLight", "Xlt", "XLt", "Xlgt", "XLgt", "Xl", "XL", "Xlt", "XLt", "Xlght", "XLght" ],
Light: ["Lt", "Lght"],
Regular: ["Reg", "Rg"],
Dark: ["Drk"],
Bold: ["Bd", "Bld"], // B causes too many match issues but should be included
Black: ["Blak", "Blk"],
Extra: ["Xt", "Xtra", "Xtr"], // X causes too many match issues but should be included
Ultra: ["Ult", "Ultre", "Ul", "Ulta"],
Super: ["Supr"],
Plus: ["Pls"],
Italic: ["Ital", "It"],
Oblique: ["Obl"],
Slant: ["Sl"],
Cursive: ["Cur"],
Rotalic: ["Rot"],
Reverse: ["Rev"],
Crabclaw: ["Crab", "Claw"],
Southpaw: ["South", "Paw"],
Backwards: ["Back", "Bck"],
Backslant: ["Bsl"],
};
let withAlternativeWeights = weights.map((el) => {
let newEls = [];
Object.keys(alternativeSpelling).forEach((key) => {
if (el.indexOf(key) !== -1) {
alternativeSpelling[key].forEach((alternative) => {
newEls.push(el.replace(key, alternative));
});
}
});
newEls.push(el);
return newEls;
}).reduce((a, b) => {
return a.concat(b);
});
// Remove duplicates to reduce iterations
weights = weights.filter((item, pos) => {
return weights.indexOf(item) == pos;
});
// Make sure to include any weight that has multiple words with alternative spellings (first pass)
withAlternativeWeights = withAlternativeWeights.map((el) => {
let newEls = [];
el.split(" ").forEach((word) => {
Object.keys(alternativeSpelling).forEach((key) => {
if (word.indexOf(key) !== -1) {
alternativeSpelling[key].forEach((alternative) => {
newEls.push(el.replace(word, word.replace(key, alternative)));
});
}
});
});
newEls.push(el);
return newEls;
}).reduce((a, b) => {
return a.concat(b);
});
// Remove duplicates to reduce iterations
weights = weights.filter((item, pos) => {
return weights.indexOf(item) == pos;
});
// Make sure to include any weight that has multiple words with alternative spellings (second pass)
withAlternativeWeights = withAlternativeWeights.map((el) => {
let newEls = [];
el.split(" ").forEach((word) => {
Object.keys(alternativeSpelling).forEach((key) => {
if (word.indexOf(key) !== -1) {
alternativeSpelling[key].forEach((alternative) => {
newEls.push(el.replace(word, word.replace(key, alternative)));
});
}
});
});
newEls.push(el);
return newEls;
}).reduce((a, b) => {
return a.concat(b);
});
// Remove duplicates
withAlternativeWeights = withAlternativeWeights.filter((item, pos) => {
return withAlternativeWeights.indexOf(item) == pos;
});
weights = withAlternativeWeights; // Adding these back to the list of weights
///////////////////////////////
///////////////////////////////
// Create list where each item in weights is lowercased
let withLowercaseWeights = weights.map((weight) => {
return weight.toLowerCase();
});
///////////////////////////////
///////////////////////////////
// Create list where each item in withLowercaseWeights gets its first letter capitalized
let withCapitalizedWeights = withLowercaseWeights.map((weight) => {
return weight.charAt(0).toUpperCase() + weight.slice(1);
});
weights = [...weights, ...withLowercaseWeights, ...withCapitalizedWeights]; // Adding these back to the list of weights
////////////////////////////////
//////////////////////////////
// Create list where each item in weights has there spaces replaced with a -
let withDashedWeights = weights.map((weight) => {
return weight.replace(/ /g, "-");
});
///////////////////////////////
///////////////////////////////
// Create list where each item in weights has there spaces replaced with a _
let withUnderscoreWeights = weights.map((weight) => {
return weight.replace(/ /g, "_");
});
///////////////////////////////
///////////////////////////////
// Create list where each item in weights has there spaces removed
let withNoSpaceWeights = weights.map((weight) => {
return weight.replace(/ /g, "");
});
weights = [...weights, ...withDashedWeights, ...withUnderscoreWeights, ...withNoSpaceWeights]; // Adding these back to the list of weights
///////////////////////////////
///////////////////////////////
// Remove duplicates of weights
weights = weights.filter((item, pos) => {
return weights.indexOf(item) == pos;
});
///////////////////////////////
///////////////////////////////
// And there you are... all weights
console.log(weights);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment