Stringify and write a
.glyphs
font file atomically
Converts a Javascript object into a string for use with the .glyphs
font format and writes it to disk. Creates directories for you as needed.
npm install --save write-glyphs-file
const WRITE_GLYPHS = require('write-glyphs-file')
WRITE_GLYPHS('my-font.glyphs', { familyName: 'My Font' /* ... */ })
.then(() => {
console.log('done writing')
})
Returns a Promise
that resolves once the file has finished writing.
Write the file synchronously, blocking further execution until it’s done.
const WRITE_GLYPHS = require('write-glyphs-file')
WRITE_GLYPHS.sync('my-font.glyphs', { familyName: 'My Font' /* ... */ })
console.log('done writing')
Type: Object
Type: number
Default: 0o666
Mode used when writing the file.
The Glyphs font editing software saves fonts to files using the .glyphs
extension. The format closely follows the NeXTSTEP “plain text” property list format, an old format that vaguely resembles JSON. For example:
{ "array" = ( "string", "string" ); }
However, the formatting of a .glyphs
file is a little more specific than the generic NeXTSTEP specfication. For example, a .glyphs
file will contain a familyName
key with the name of your font family as its value:
{ familyName = "My Font"; }
Which is equivalent to this Javascript object:
{ familyName: "My Font" }
A standard way of safely stringifying this object to a valid NeXTSTEP property list would be to wrap all keys in quotes:
{ "familyName" = "My Font"; }
However, Glyphs will not find your familyName
if its key is quoted like that. To try to output files as close as possible to the original .glyphs
files, this package will not quote strings as long as they only contain “word” characters (A-Za-z0-9_
).
Similarly, a one-line file can be a valid NeXTSTEP property list as the parsing relies on commas, semicolons, parentheses, and braces. However, Glyphs’ parser seems to break down if a .glyphs
file doesn’t also use new lines to break up the text.
write-glyphs-file
will write the following as opposed to compressing it on one line:
{
familyName = "My Font";
}
- load-nextstep-plist - Read and parse NeXTSTEP property list files, including the
.glyphs
font format
Stringification is modelled on Chee’s nextstep-plist
.
The file writing logic is modelled on Sindre Sorhus’s write-json-file
.
This software is free to use, modify, and redistribute under a GNU General Public License.