Skip to content
This repository has been archived by the owner on Jan 8, 2023. It is now read-only.

Saxicon class

Lachlan McDonald edited this page Apr 30, 2018 · 20 revisions

The Saxicon class is used to process SVGs and returns a SaxiconData class for outputting data URI's.

Methods

new Saxicon (options = {})

Initialise a new instance of the Saxicon class with the provided options (see following section.)

parseSync (paths)

Parsers an array of paths to SVGs, returns a new SaxiconData instance. Paths that do not exist, or cannot be read, will be captured as errors in the SaxiconData instance. Files are read synchronously.

Files must be encoded with UTF-8 and byte-order-marks are removed.

Note: At present, there is not an asynchronous version of this method.

Static Methods

removeWhitespace (doc)

Returns a SVG document with all insignificant whitespace removed.

Options

  • replaceColors (Boolean)
    When true, hex colors are replaced with their related color keywords where possible.
  • restrict (Array)
    Limit replacement to only those color keywords within this array. If empty, all colors are replaced.
  • ignore (Array)
    Color keywords in this array are excluded from replacement. If empty, no colors are excluded. Colors in this array take precedence over colors in the restrict option.
  • iconName (Function)
    Callback function used to generate icon names from the source SVG filenames.
    By default, each icon will be named after the original filename without its extension. i.e. arrow-left.svg becomes arrow-left.
    Function receives the filename as its only argument and should return the icon's name as a valid SASS string.

Advanced options:

  • removeVersion (Boolean)
    When true, the version attribute is removed from the <svg> element.
  • presentationTags (Array)
    List of tags that will have their stroke and fill attributes replaced.
  • structuralTags (Array)
    List of tags which may contain a stroke or fill attribute, that are inherited, but otherwise should not have that attribute set if not already present. This option is mainly to handle elements such as <g>.
  • ignoreTags (Array)
    Tags to ignore. These tags, and their child tags, will not have their colours replaced (essentially skipped). This option is mainly to handle elements such as <mask>.