Skip to content

Commit

Permalink
feat: adding config option to prevent ligature unicode generation
Browse files Browse the repository at this point in the history
  • Loading branch information
wszydlak committed Jul 27, 2021
1 parent a91ded0 commit 3f2b456
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = {
rules: {
"max-lines": ["error", 510],
"max-lines-per-function": ["error", 495],
"max-statements": ["error", 27],
"max-statements": ["error", 28],
},
},
{
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ webfont({
- Default: Gets is from `fontName` if not set, but you can specify any value.
- Description: Template font family name you want.

#### `ligatures`

- Type: `boolean`
- Default: `true`
- Description: Turn on/off adding ligature unicode

#### `glyphTransformFn`

- Type: `function`
Expand Down
6 changes: 6 additions & 0 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ if (cli.flags.sort === false) {

}

if (cli.flags.ligatures === false) {

optionsBase.ligatures = cli.flags.ligatures;

}

if (cli.flags.addHashInFontUrl) {

optionsBase.addHashInFontUrl = cli.flags.addHashInFontUrl;
Expand Down
4 changes: 4 additions & 0 deletions src/cli/meow/__mocks__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ meowMock.showHelp = () => `
Keeps the files in the same order of entry
--no-ligatures
Prevents adding ligature unicode
--verbose
Tell me everything!.
Expand Down
8 changes: 8 additions & 0 deletions src/cli/meow/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ const meowCLI = meow(`
Keeps the files in the same order of entry
--no-ligatures
Prevents adding ligature unicode
--verbose
Tell me everything!.
Expand Down Expand Up @@ -193,6 +197,10 @@ const meowCLI = meow(`
alias: "h",
type: "boolean",
},
ligatures: {
default: true,
type: "boolean",
},
normalize: {
type: "boolean",
},
Expand Down
7 changes: 6 additions & 1 deletion src/standalone/glyphsData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,18 @@ export const getGlyphsData : GlyphsDataGetter = (files, options) => {
sortedGlyphsData = glyphsData.sort(sortCallback);
}

const { ligatures } = options;

return Promise.all(sortedGlyphsData.map((glyphData: GlyphData) => new Promise((resolve, reject) => {
metadataProvider(glyphData.srcPath, (error, metadata) => {
if (error) {
return reject(error);
}

metadata.unicode.push(metadata.name.replace(/-/gu, "_"));
if (ligatures) {
metadata.unicode.push(metadata.name.replace(/-/gu, "_"));
}

glyphData.metadata = metadata;

return resolve(glyphData);
Expand Down
15 changes: 15 additions & 0 deletions src/standalone/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,21 @@ describe("standalone", () => {
expect(result.glyphsData.length > 0).toBe(true);
});

it("should remove ligature unicode when `ligatures` set to `false`", async () => {
const result = await standalone({
files: `${fixturesGlob}/svg-icons/**/*`,
ligatures: false,
template: "css",
});

expect(Array.isArray(result.glyphsData)).toBe(true);
expect(result.glyphsData.length > 0).toBe(true);

result.glyphsData.forEach((glyph) => {
expect(glyph.metadata?.unicode).toHaveLength(1);
});
});

it("should export `hash` in `result`", () => {
expect.assertions(1);

Expand Down
1 change: 1 addition & 0 deletions src/standalone/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const getOptions: OptionsGetter = (initialOptions) => {
},
},
glyphTransformFn: null,
ligatures: true,

/*
* Maybe allow setup from CLI
Expand Down
1 change: 1 addition & 0 deletions src/types/OptionsBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ export type OptionsBase = {
prependUnicode?: boolean | unknown;
metadata?: unknown;
sort?: boolean;
ligatures?: boolean;
addHashInFontUrl?: boolean | unknown;
};

0 comments on commit 3f2b456

Please sign in to comment.