@wkovacs64/add-icon 0.1.0-dev.b5c05efe → 0.1.0-dev.e2dd6945
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -120
- package/dist/config.d.ts +3 -3
- package/dist/iconify.d.ts +2 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1 -0
- package/dist/types.d.ts +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,58 +14,27 @@ npm install @wkovacs64/add-icon
|
|
|
14
14
|
Or use it directly with npx without installing:
|
|
15
15
|
|
|
16
16
|
```bash
|
|
17
|
-
npx @wkovacs64/add-icon
|
|
17
|
+
npx @wkovacs64/add-icon <icon> [options]
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
## Usage
|
|
21
21
|
|
|
22
22
|
### Basic Usage
|
|
23
23
|
|
|
24
|
-
Download an icon:
|
|
24
|
+
Download an icon to the specified directory:
|
|
25
25
|
|
|
26
26
|
```bash
|
|
27
|
-
npx @wkovacs64/add-icon heroicons:arrow-up-circle
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
Specify an output directory:
|
|
31
|
-
|
|
32
|
-
```bash
|
|
33
|
-
npx @wkovacs64/add-icon heroicons:arrow-up-circle --output-dir ./my-icons
|
|
27
|
+
npx @wkovacs64/add-icon heroicons:arrow-up-circle --output-dir ./app/assets/svg-icons
|
|
34
28
|
```
|
|
35
29
|
|
|
36
30
|
### Transformations
|
|
37
31
|
|
|
38
|
-
The tool fetches SVG icons directly from the Iconify API with width and height attributes removed automatically. You can
|
|
39
|
-
|
|
40
|
-
### Custom Transformations
|
|
41
|
-
|
|
42
|
-
You can write custom transforms in either JavaScript or TypeScript!
|
|
32
|
+
The tool fetches SVG icons directly from the Iconify API with width and height attributes removed automatically. You can optionally provide a transform file using either JavaScript or TypeScript containing custom transformations for more advanced modifications.
|
|
43
33
|
|
|
44
|
-
####
|
|
45
|
-
|
|
46
|
-
Create a custom transform file (e.g., `my-transform.js`):
|
|
47
|
-
|
|
48
|
-
```js
|
|
49
|
-
/**
|
|
50
|
-
* Custom transform to add a title element to SVG
|
|
51
|
-
* @param {Object} args - Transform arguments
|
|
52
|
-
* @param {string} args.svg - SVG content
|
|
53
|
-
* @param {string} args.iconName - Icon name (e.g., 'heroicons:arrow-up-circle')
|
|
54
|
-
* @param {string} args.prefix - Icon set prefix (e.g., 'heroicons')
|
|
55
|
-
* @param {string} args.name - Icon name without prefix (e.g., 'arrow-up-circle')
|
|
56
|
-
* @returns {string} - Transformed SVG
|
|
57
|
-
*/
|
|
58
|
-
export default function addTitle(args) {
|
|
59
|
-
const titleElement = `<title>${args.iconName}</title>`;
|
|
60
|
-
return args.svg.replace(/<svg([^>]*)>/, `<svg$1>${titleElement}`);
|
|
61
|
-
}
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
#### TypeScript Transform
|
|
65
|
-
|
|
66
|
-
Create a custom transform file (e.g., `my-transform.ts`) that will be imported directly:
|
|
34
|
+
#### TypeScript Transform Example
|
|
67
35
|
|
|
68
36
|
```ts
|
|
37
|
+
// my-transform.ts
|
|
69
38
|
import type { TransformArgs } from '@wkovacs64/add-icon';
|
|
70
39
|
|
|
71
40
|
/**
|
|
@@ -82,37 +51,17 @@ export default function addTitle(args: TransformArgs): string {
|
|
|
82
51
|
Then use it with the CLI:
|
|
83
52
|
|
|
84
53
|
```bash
|
|
85
|
-
# JavaScript transform
|
|
86
|
-
npx @wkovacs64/add-icon heroicons:arrow-up-circle --transform ./my-transform.js
|
|
87
|
-
|
|
88
|
-
# TypeScript transform
|
|
89
54
|
npx @wkovacs64/add-icon heroicons:arrow-up-circle --transform ./my-transform.ts
|
|
90
55
|
```
|
|
91
56
|
|
|
92
|
-
|
|
57
|
+
### Configuration File
|
|
93
58
|
|
|
94
59
|
You can create a configuration file in your project root, using either JavaScript (`add-icon.config.js`) or TypeScript (`add-icon.config.ts`).
|
|
95
60
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
```js
|
|
99
|
-
// Define custom transform
|
|
100
|
-
function addCustomAttribute(args) {
|
|
101
|
-
return args.svg.replace(/<svg/, `<svg data-icon="${args.iconName}"`);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export default {
|
|
105
|
-
outputDir: './assets/icons',
|
|
106
|
-
transforms: [addCustomAttribute],
|
|
107
|
-
};
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
### TypeScript Configuration
|
|
111
|
-
|
|
112
|
-
You can create a TypeScript configuration file and the tool will import it directly:
|
|
61
|
+
#### TypeScript Configuration Example
|
|
113
62
|
|
|
114
63
|
```ts
|
|
115
|
-
import type {
|
|
64
|
+
import type { Config, TransformArgs, TransformFunction } from '@wkovacs64/add-icon';
|
|
116
65
|
|
|
117
66
|
// Define custom transform
|
|
118
67
|
function addCustomAttribute(args: TransformArgs): string {
|
|
@@ -122,70 +71,11 @@ function addCustomAttribute(args: TransformArgs): string {
|
|
|
122
71
|
const config = {
|
|
123
72
|
outputDir: './assets/icons',
|
|
124
73
|
transforms: [addCustomAttribute],
|
|
125
|
-
} satisfies
|
|
74
|
+
} satisfies Config;
|
|
126
75
|
|
|
127
76
|
export default config;
|
|
128
77
|
```
|
|
129
78
|
|
|
130
|
-
> **Note:** TypeScript configuration and transform files are compiled in-memory using esbuild, without creating temporary JavaScript files. This provides a seamless TypeScript experience with no extra build steps.
|
|
131
|
-
|
|
132
|
-
## Using as a Library
|
|
133
|
-
|
|
134
|
-
You can also use iconify-cli as a library in your own projects:
|
|
135
|
-
|
|
136
|
-
### JavaScript
|
|
137
|
-
|
|
138
|
-
```js
|
|
139
|
-
import { downloadIcon } from '@wkovacs64/add-icon';
|
|
140
|
-
|
|
141
|
-
// Create custom transform
|
|
142
|
-
function addCustomAttribute(args) {
|
|
143
|
-
return args.svg.replace(/<svg/, `<svg data-custom="${args.iconSet}"`);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// Download an icon with transforms
|
|
147
|
-
async function downloadCustomIcon() {
|
|
148
|
-
const iconPath = await downloadIcon('heroicons:heart', {
|
|
149
|
-
outputDir: './icons',
|
|
150
|
-
transforms: [addCustomAttribute],
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
console.log(`Icon saved to: ${iconPath}`);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
downloadCustomIcon();
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
### TypeScript
|
|
160
|
-
|
|
161
|
-
```ts
|
|
162
|
-
import { downloadIcon, type TransformArgs } from '@wkovacs64/add-icon';
|
|
163
|
-
|
|
164
|
-
// Create custom transform
|
|
165
|
-
const addCustomAttribute = (args: TransformArgs): string => {
|
|
166
|
-
return args.svg.replace(/<svg/, `<svg data-custom="${args.iconSet}"`);
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
// Download an icon with transforms
|
|
170
|
-
async function downloadCustomIcon(): Promise<void> {
|
|
171
|
-
try {
|
|
172
|
-
const iconPath = await downloadIcon('heroicons:heart', {
|
|
173
|
-
outputDir: './icons',
|
|
174
|
-
transforms: [addCustomAttribute],
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
console.log(`Icon saved to: ${iconPath}`);
|
|
178
|
-
} catch (error) {
|
|
179
|
-
console.error(
|
|
180
|
-
'Error downloading icon:',
|
|
181
|
-
error instanceof Error ? error.message : String(error),
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
downloadCustomIcon();
|
|
187
|
-
```
|
|
188
|
-
|
|
189
79
|
## License
|
|
190
80
|
|
|
191
81
|
MIT
|
package/dist/config.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Config } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Default configuration
|
|
4
4
|
*/
|
|
5
|
-
export declare const defaultConfig:
|
|
5
|
+
export declare const defaultConfig: Config;
|
|
6
6
|
/**
|
|
7
7
|
* Loads configuration from file if it exists
|
|
8
8
|
* @param configPath - Path to config file
|
|
9
9
|
* @returns Configuration object
|
|
10
10
|
*/
|
|
11
|
-
export declare function loadConfig(configPath?: string): Promise<
|
|
11
|
+
export declare function loadConfig(configPath?: string): Promise<Config>;
|
package/dist/iconify.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Config } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Parses an icon reference into iconSet and iconName
|
|
4
4
|
* @param iconReference - Reference in format 'iconSet:iconName'
|
|
@@ -14,4 +14,4 @@ export declare function parseIconReference(iconReference: string): {
|
|
|
14
14
|
* @param config - Configuration options
|
|
15
15
|
* @returns Path to saved icon file
|
|
16
16
|
*/
|
|
17
|
-
export declare function downloadIcon(iconReference: string, config:
|
|
17
|
+
export declare function downloadIcon(iconReference: string, config: Config): Promise<string>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export type {
|
|
1
|
+
import type { TransformFunction, TransformArgs, Config } from './types.js';
|
|
2
|
+
export type { TransformFunction, TransformArgs, Config };
|
|
3
3
|
export { downloadIcon, parseIconReference } from './iconify.js';
|
|
4
|
+
export { loadConfig, defaultConfig } from './config.js';
|
|
4
5
|
export declare function runCli(): void;
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { importModule } from './import-module.js';
|
|
|
6
6
|
import { getPackageInfo } from './package-info.js';
|
|
7
7
|
// Re-export other useful functions
|
|
8
8
|
export { downloadIcon, parseIconReference } from './iconify.js';
|
|
9
|
+
export { loadConfig, defaultConfig } from './config.js';
|
|
9
10
|
// Create CLI program
|
|
10
11
|
const program = new Command();
|
|
11
12
|
// Set up the program with package info
|
package/dist/types.d.ts
CHANGED
|
@@ -12,13 +12,13 @@ export type TransformArgs = {
|
|
|
12
12
|
/**
|
|
13
13
|
* SVG transformation function type
|
|
14
14
|
*/
|
|
15
|
-
export type
|
|
15
|
+
export type TransformFunction = (args: TransformArgs) => Promise<string> | string;
|
|
16
16
|
/**
|
|
17
|
-
* Configuration options for the
|
|
17
|
+
* Configuration options for the add-icon CLI
|
|
18
18
|
*/
|
|
19
|
-
export type
|
|
19
|
+
export type Config = {
|
|
20
20
|
/** Directory to output icons */
|
|
21
21
|
outputDir: string;
|
|
22
22
|
/** Array of transform functions to apply to icons */
|
|
23
|
-
transforms?:
|
|
23
|
+
transforms?: TransformFunction[];
|
|
24
24
|
};
|