gulp-stacksvg 5.0.0 → 6.0.0

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.
Files changed (2) hide show
  1. package/lib/index.js +18 -30
  2. package/package.json +51 -53
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createHmac } from "node:crypto"
2
- import { Transform } from "node:stream"
3
2
  import { basename, extname, sep } from "node:path"
3
+ import { Transform } from "node:stream"
4
4
 
5
5
  import { parse } from "node-html-parser"
6
6
  import PluginError from "plugin-error"
@@ -39,13 +39,9 @@ export function stacksvg () {
39
39
  * @param {function} cb - Callback function.
40
40
  */
41
41
  function transform (file, _, cb) {
42
- if (file.isStream()) {
43
- return cb(new PluginError(`gulp-stacksvg`, `Streams are not supported!`))
44
- }
42
+ if (file.isStream()) return cb(new PluginError(`gulp-stacksvg`, `Streams are not supported!`))
45
43
 
46
- if (file.isNull() || !parse(file.contents.toString()).querySelector(`svg`)) {
47
- return cb()
48
- }
44
+ if (file.isNull() || !parse(file.contents.toString()).querySelector(`svg`)) return cb()
49
45
 
50
46
  let iconDom = parse(file.contents.toString()).removeWhitespace()
51
47
  let iconSvg = iconDom.querySelector(`svg`)
@@ -57,9 +53,7 @@ export function stacksvg () {
57
53
  extname(file.relative),
58
54
  )
59
55
 
60
- if (iconId in ids) {
61
- return cb(new PluginError(`gulp-stacksvg`, `File name should be unique: ${iconId}`))
62
- }
56
+ if (iconId in ids) return cb(new PluginError(`gulp-stacksvg`, `File name should be unique: ${iconId}`))
63
57
 
64
58
  ids[iconId] = true
65
59
  iconSvg.setAttribute(`id`, iconId)
@@ -68,9 +62,7 @@ export function stacksvg () {
68
62
  let widthAttr = iconSvg.getAttribute(`width`)?.replace(/[^0-9]/g, ``)
69
63
  let heightAttr = iconSvg.getAttribute(`height`)?.replace(/[^0-9]/g, ``)
70
64
 
71
- if (!viewBoxAttr && widthAttr && heightAttr) {
72
- iconSvg.setAttribute(`viewBox`, `0 0 ${widthAttr} ${heightAttr}`)
73
- }
65
+ if (!viewBoxAttr && widthAttr && heightAttr) iconSvg.setAttribute(`viewBox`, `0 0 ${widthAttr} ${heightAttr}`)
74
66
 
75
67
  excessAttrs.forEach((attr) => iconSvg.removeAttribute(attr))
76
68
  iconSvg.querySelectorAll(`[id]`).forEach(changeInnerId)
@@ -94,13 +86,13 @@ export function stacksvg () {
94
86
  * @param {Element} elem - Child element to update.
95
87
  */
96
88
  function updateUsingId (elem) {
97
- if (~elem.rawAttrs.search(`#${oldId}`)) {
98
- // eslint-disable-next-line guard-for-in
99
- for (let attr in elem._attrs) {
100
- let attrValue = elem._attrs[attr].replace(`#${oldId}`, `#${newId}`)
89
+ if (elem.rawAttrs.search(`#${oldId}`) === -1) return
101
90
 
102
- elem.setAttribute(attr, attrValue)
103
- }
91
+ for (let attr in elem._attrs) {
92
+ if (!Object.hasOwn(elem._attrs, attr)) continue
93
+
94
+ let attrValue = elem._attrs[attr].replace(`#${oldId}`, `#${newId}`)
95
+ elem.setAttribute(attr, attrValue)
104
96
  }
105
97
  }
106
98
  }
@@ -118,10 +110,12 @@ export function stacksvg () {
118
110
  newNsAlias = namespaces.get(nsId).slice(6)
119
111
  changeNsAlias(iconDom, oldNsAlias, newNsAlias)
120
112
  }
121
- } else if (nsId === XLINK) {
113
+ }
114
+ else if (nsId === XLINK) {
122
115
  newNsAlias = ``
123
116
  changeNsAlias(iconDom, oldNsAlias, newNsAlias)
124
- } else {
117
+ }
118
+ else {
125
119
  for (let ns of namespaces.values()) {
126
120
  if (ns === attrName) {
127
121
  newNsAlias = `${oldNsAlias}${getHash(nsId)}`
@@ -157,13 +151,9 @@ export function stacksvg () {
157
151
  * @param {function} cb - Callback function.
158
152
  */
159
153
  function flush (cb) {
160
- if (isEmpty) {
161
- return cb()
162
- }
154
+ if (isEmpty) return cb()
163
155
 
164
- for (let [nsId, nsAttr] of namespaces) {
165
- rootSvg.setAttribute(nsAttr, nsId)
166
- }
156
+ for (let [nsId, nsAttr] of namespaces) rootSvg.setAttribute(nsAttr, nsId)
167
157
 
168
158
  let file = new Vinyl({ path: `stack.svg`, contents: Buffer.from(stack.toString()) })
169
159
 
@@ -189,9 +179,7 @@ function changeNsAlias (iconDom, oldAlias, newAlias) {
189
179
  iconDom.querySelectorAll(`*`).forEach((elem) => {
190
180
  let prefix = newAlias === `` ? `` : `${newAlias}:`
191
181
 
192
- if (elem.rawTagName.startsWith(`${oldAlias}:`)) {
193
- elem.rawTagName = `${prefix}${elem.rawTagName.slice((oldAlias.length + 1))}`
194
- }
182
+ if (elem.rawTagName.startsWith(`${oldAlias}:`)) elem.rawTagName = `${prefix}${elem.rawTagName.slice((oldAlias.length + 1))}`
195
183
 
196
184
  for (let name of Object.keys(elem._attrs)) {
197
185
  if (name.startsWith(`${oldAlias}:`)) {
package/package.json CHANGED
@@ -1,54 +1,52 @@
1
1
  {
2
- "name": "gulp-stacksvg",
3
- "description": "The gulp plugin to combine svg files into one using the stack method.",
4
- "version": "5.0.0",
5
- "license": "MIT",
6
- "author": {
7
- "name": "Sergey Artemov",
8
- "email": "firefoxic.dev@gmail.com"
9
- },
10
- "homepage": "https://github.com/firefoxic/gulp-stacksvg#readme",
11
- "bugs": {
12
- "url": "https://github.com/firefoxic/gulp-stacksvg/issues"
13
- },
14
- "repository": {
15
- "type": "git",
16
- "url": "git://github.com/firefoxic/gulp-stacksvg.git"
17
- },
18
- "type": "module",
19
- "exports": "./lib/index.js",
20
- "files": [
21
- "./lib/"
22
- ],
23
- "engines": {
24
- "node": "^20.12 || >=22.11"
25
- },
26
- "dependencies": {
27
- "node-html-parser": "^6.1.13",
28
- "plugin-error": "^2.0.1",
29
- "vinyl": "^3.0.0"
30
- },
31
- "devDependencies": {
32
- "@firefoxic/eslint-config": "^4.0.0",
33
- "@firefoxic/update-changelog": "^1.0.0",
34
- "eslint": "^9.13.0",
35
- "gulp": "^5.0.0"
36
- },
37
- "keywords": [
38
- "gulp",
39
- "gulpplugin",
40
- "svg",
41
- "icon",
42
- "sprite",
43
- "stack",
44
- "vector"
45
- ],
46
- "scripts": {
47
- "lint": "eslint",
48
- "test": "node --test",
49
- "pretest": "pnpm lint",
50
- "preversion": "pnpm test",
51
- "version": "update-changelog",
52
- "postversion": "pnpm publish --provenance --access public --no-git-checks"
53
- }
54
- }
2
+ "name": "gulp-stacksvg",
3
+ "description": "The gulp plugin to combine svg files into one using the stack method.",
4
+ "version": "6.0.0",
5
+ "license": "MIT",
6
+ "author": {
7
+ "name": "Sergey Artemov",
8
+ "email": "firefoxic.dev@gmail.com"
9
+ },
10
+ "homepage": "https://github.com/firefoxic/gulp-stacksvg#readme",
11
+ "bugs": {
12
+ "url": "https://github.com/firefoxic/gulp-stacksvg/issues"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git://github.com/firefoxic/gulp-stacksvg.git"
17
+ },
18
+ "type": "module",
19
+ "exports": "./lib/index.js",
20
+ "files": [
21
+ "./lib/"
22
+ ],
23
+ "engines": {
24
+ "node": ">=22.22"
25
+ },
26
+ "dependencies": {
27
+ "node-html-parser": "^7.0.2",
28
+ "plugin-error": "^2.0.1",
29
+ "vinyl": "^3.0.1"
30
+ },
31
+ "scripts": {
32
+ "help": "make help",
33
+ "eslint": "eslint"
34
+ },
35
+ "peerDependencies": {
36
+ "gulp": "^5.0.1"
37
+ },
38
+ "devDependencies": {
39
+ "@firefoxic/eslint-config": "^6.0.1",
40
+ "eslint": "^9.39.2",
41
+ "gulp": "^5.0.1"
42
+ },
43
+ "keywords": [
44
+ "gulp",
45
+ "gulpplugin",
46
+ "svg",
47
+ "icon",
48
+ "sprite",
49
+ "stack",
50
+ "vector"
51
+ ]
52
+ }