0.0.1 • Published 4 years ago

@reactive-solutions/icon-typification v0.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

Icon Typification

Script to auto generate a union type for your icons.

Why?

We got tired to lookup all the icons inside app and extend the type on our own.

Get Started

Install Package

npm i @reactive-solutions/icon-typification

Prepare package.json

{
    ...
    "scripts": {
        "extract-icons": "ts-node ./node_modules/@reactive-solutions/icon-typification/extract-icons.ts --type-name=MyAppIconType ..."
    ...
}

Run script

npm run extract-icons

Sample Run

- src
  - assets
    - icons
      - user-icon.svg
      - add-icon.svg
> ts-node ./node_modules/@reactive-solutions/icon-typification/extract-icons.ts --type-name=MyAppIconType --source=src/assets/icons --extension=svg --suffix=icon

user
add
done.

Sample Output

export type MyAppIconType =
'user' |
'add';

Parameters

ParameterTypeDefaultDescription
type-namestringIconTypeTypescript type name for icons.
sourcestring./src/assets/iconsIcon source directory
extensionstringsvgIcon file extension without '.'
outputstring./src/app/sharedTarget directory for output file
filenamestringcustom-iconTarget file name without extension
prefixstringnullIcon file prefix like "icon-add.svg". Prefix will be removed
suffixstringnullIcon file suffix like "add-icon.svg". Suffix will be removed

Use Case

@Component({
  selector: 'rs-icon',
  templateUrl: './icon.component.html'
})
export class IconComponent {
  @Input() icon: MyAppIconType;
}