0.0.87 • Published 3 years ago

hydra-svg-js v0.0.87

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Hydra-SVG-JS

Software License Latest Version on NPM npm

This package allows you to use and manage your favorite svg icon libraries within your project.

Find your favorite icon package already made in our hydra-packs package!

ActionsDescriptions
hydratefunctionmerge attributes and append child elements to create an icon.
observefunctionattach a MutationObserver to rehydrate with the new icon selections.
purgefunction commandcreate a custom file of only the icons used in your project.
generatefunction commandcreate your own package of icons to use in your own projects or share with others.
injectfunction commandhard code your svg elements into your project files
ejectfunction commandremove your hard coded svg elements

Table of Contents


  1. Installation
  2. Usage
  3. Functions
  4. Functions with Commands
  5. Credits
  6. License (MIT)

Installation

Back to Top


  1. Install the package with npm or yarn:
npm install hydra-svg-js

yarn add hydra-svg-js

And you're done!

Usage

Back to Top


Actions can be used as functions in a file, or a command on the command line unless they are meant for the DOM.

These actions will be performed on any svg element that has both the pack and icon attribute, assuming that they name an icon that exists in the pack named.

Functions

Back to Top


Hydrate

Hydrate merge attributes and append child elements to create an icon. As opposed to other packages that replace tags, this starts with and keeps your svg tag which prevents flickering and makes it easier to handle icon attributes together with added custom attributes.

hydrate( packs, svgs, options = { observe: false })
packsobject{ pack-name:{ icon-name: { icon-object }}}
svgsarray[SVGElement]
optionsobject{ observe: false }
observeboolean

Observe option is a builtin call to the observe function below, after the icons have been hydrated.

Observe

observe( packs, svgs)
packsobject{ pack-name: { icon-name: { icon-object }}}
svgsarray[SVGElement]

Functions with Commands

Back to Top


Purge

command

hydra purge [packs...] [-i, --input]=src [-o, --output]=dist
packsarraypath: ./pack.json module: hydra-pack
inputstringglob 'src/**/*.{js,html}'
outputstringsrc/purged will output src/purged.json

function

purge( packs, input, output, overrides = {includes: {}, excludes: {}, extends: {}})
packsobject{ pack-name:{ icon-name: { icon-object }}}
inputstringglob 'src/**/*.{js,html}'
outputstringsrc/purged will output src/purged.json
overridesobject{ includes: {}, excludes: {}, extends: {}}
includesobject { pack-name: [ icon-name ]}
excludesobject { pack-name: [ icon-name ]}
extendsobject { pack-name: { icon-name: { icon-object }}}

Generate

Generate provides a way create your own package of icons to use in your own projects or share with others. For the intended outcome, you must name the directory after the name of your package, and each svg file after the name of the svg icon within. The generator determines the name of the package and icon accordingly.

Example: 1. input: src/packs/bootstrap/alarm.svg 2. output: dist/packs/bootstrap.json 3. contents: { "alarm": ...iconObject }

SVGO is already builtin and enabled to optimize your svg icons before they are generated into json.

SVGO default settings are used except that removeViewbox is disabled, and removeDimensions is enabled.

command

hydra generate [packs] [-i, --input]=src [-o, --output]=dist [-p, --optimize] [-n, --no-optimize]
packsstring arrayName of pack and folder within the input directory. E.g. bootstrap for src/packs/bootstrap
inputstringglob 'src/**/*.{js,html}'
outputstringTo output the json file within the named directoy. E.g. the bootstrap pack with the output src/packs will result in src/packs/bootstrap.json
optimizebooleanUse the default settings to optimize your svg element with SVGO
no-optimizebooleanDisable svg icon optimization

function

generate( packs, input, output, options = {
	optimize: {},
	hook: {folder: null, object: null, file: null}
})
packsstring arrayName of the pack and folder within the input directory. E.g. bootstrap for src/packs/bootstrap. Name multiple with an array for more than one. Use an empty array as the symbol for all within the directory.
inputstringglob 'src/**/*.{js,html}'
outputstringTo output the json file within the named directoy. E.g. the bootstrap pack with the output src/packs will result in src/packs/bootstrap.json
optimizeboolean objectSet to false in order to disable optimization or override the configuration defaults.
hookobject{ folder: () => {}, object: () => {} file: () => {} }
foldernull function callback({ total, input, output,path.parse(input)}) This hook is called for each folder right before each icon object is generated and output file is written.
objectnull function callback({ count, total, name }) This hook is right after each icon object is generated and before the output file is written.
filenull function callback({ total, input, output,path.parse(output)}) This hook is called after the output file is written.

Inject

Make sure to run eject each time before running inject to ensure that your svg starts from a clean slate. Otherwise attributes from a prior injection may remain. Inject merges with the attributes already written so that any user made customizations are not lost. A record of the old icon attributes are not kept in memory to be removed. Therefore, those old icon attributes are assumed to also be user made customizations.

command

hydra inject [packs] [-i, --input]=src
packsarraypath: ./pack.json module: hydra-pack
inputstringglob 'src/**/*.{html}'

function

inject( packs, input)
packsobject{ pack-name:{ icon-name: { icon-object }}}
inputstringglob 'src/**/*.{html}'

Eject

command

hydra eject [packs] [-i, --input]=src
packsarraypath: ./pack.json module: hydra-pack
inputstringglob 'src/**/*.{html}'

function

eject( packs, input)
packsobject{ pack-name:{ icon-name: { icon-object }}}
inputstringglob 'src/**/*.{html}'

Credits

Back to Top

License

Back to Top

The MIT License (MIT). Please see License File for more information.

0.0.87

3 years ago

0.0.86

3 years ago

0.0.85

3 years ago

0.0.84

3 years ago

0.0.83

3 years ago

0.0.80

3 years ago

0.0.81

3 years ago

0.0.82

3 years ago

0.0.76

3 years ago

0.0.77

3 years ago

0.0.78

3 years ago

0.0.79

3 years ago

0.0.73

3 years ago

0.0.74

3 years ago

0.0.75

3 years ago

0.0.70

3 years ago

0.0.71

3 years ago

0.0.72

3 years ago

0.0.69

3 years ago

0.0.67

3 years ago

0.0.68

3 years ago

0.0.63

3 years ago

0.0.64

3 years ago

0.0.65

3 years ago

0.0.66

3 years ago

0.0.60

3 years ago

0.0.61

3 years ago

0.0.59

3 years ago

0.0.53

3 years ago

0.0.54

3 years ago

0.0.55

3 years ago

0.0.56

3 years ago

0.0.57

3 years ago

0.0.58

3 years ago

0.0.52

3 years ago

0.0.51

3 years ago

0.0.50

3 years ago

0.0.49

3 years ago

0.0.48

3 years ago

0.0.45

3 years ago

0.0.46

3 years ago

0.0.47

3 years ago

0.0.41

3 years ago

0.0.42

3 years ago

0.0.43

3 years ago

0.0.44

3 years ago

0.0.40

3 years ago

0.0.39

3 years ago

0.0.38

3 years ago

0.0.37

3 years ago

0.0.33

3 years ago

0.0.34

3 years ago

0.0.35

3 years ago

0.0.36

3 years ago

0.0.20

3 years ago

0.0.21

3 years ago

0.0.22

3 years ago

0.0.23

3 years ago

0.0.24

3 years ago

0.0.25

3 years ago

0.0.30

3 years ago

0.0.31

3 years ago

0.0.32

3 years ago

0.0.26

3 years ago

0.0.27

3 years ago

0.0.28

3 years ago

0.0.29

3 years ago

0.0.19

3 years ago

0.0.18

3 years ago

0.0.16

3 years ago

0.0.17

3 years ago

0.0.13

3 years ago

0.0.14

3 years ago

0.0.15

3 years ago

0.0.12

3 years ago

0.0.11

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago