Managing packages

Iconify Tools has several functions to help automate downloading, comparing and updating packages.

Async

Most functions listed below are asynchronous.

If you are not familiar with asynchronous functions in JavaScript, read up on Promise class, async and await keywords.

Simplest way to use asynchronous functions is to wrap all your code in anonymous asynchronous function, then await functions:

// Anonymous async function. Not needed if you are using Node 17 or newer.
(async () => {
   // Create new SVG instance.
   const svg = new SVG(reallyBadIcon);

   // Wait for cleanupSVG() to finish working by adding 'await' before function call.
   await cleanupSVG(svg);

   // Do other stuff
   console.log(svg.toMinifiedString());

   // Close function and immediately execute it.
})();

To catch errors, use try and catch:

// Anonymous async function. Not needed if you are using Node 17 or newer.
(async () => {
   // Create new SVG instance.
   const svg = new SVG(reallyBadIcon);

   // Wait for cleanupSVG() to finish working by adding 'await' before function call.
   try {
       await cleanupSVG(svg);
   } catch (err) {
       // Clean up failed: see error message
       console.error(err);
       return;
   }

   // Do other stuff
   console.log(svg.toMinifiedString());

   // Close function and immediately execute it.
})();

Check out various tutorials for async and await. There are many free good tutorials on YouTube.

Downloading packages

These functions download packages from various sources.

Functions can be used to download source for icon sets, which can be imported using importDirectory() function.

Functions can also be used to compare exported data with previously published data, then publish new version if package was changed.

Additionally, there are few functions to download files by URL:

  • sendAPIQuery() is a wrapper for fetch with support for cache. It is used by functions like importFromFigma().
  • downloadFile() is also a wrapper for fetch that simplifies downloading of binary files, such as archives. It is used by GitHub and NPM downloaders.

Versions

When publishing packages, you might want to change package version. Iconify Tools offers several functions to help you automate process:

Functions to get version number or commit hash from local files:

Functiosn to get version number or commit hash from remote package/repository:

Comparing directories

When automating build process, publishing new package when nothing was changed makes no sense. There is a function in Iconify Tools to check for changes:

Unlike simple comparison, this function ignores version numbers in package.json, hidden files and different line endings.