soaring-symbols 0.1.0-alpha.2 → 0.1.0-alpha.3

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/package.json +10 -4
  2. package/utils/index.js +61 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "soaring-symbols",
3
- "version": "0.1.0-alpha.2",
3
+ "version": "0.1.0-alpha.3",
4
4
  "description": "A curated collection of airline branding assets — logos, icons, and tail designs in SVG format.",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
@@ -32,7 +32,10 @@
32
32
  "travel"
33
33
  ],
34
34
  "exports": {
35
- ".": "./index.js",
35
+ ".": {
36
+ "types": "./index.d.ts",
37
+ "import": "./index.js"
38
+ },
36
39
  "./assets/*": "./assets/*"
37
40
  },
38
41
  "files": [
@@ -41,6 +44,7 @@
41
44
  "index.js",
42
45
  "index.d.ts",
43
46
  "scripts/",
47
+ "utils/",
44
48
  "API.md",
45
49
  "README.md",
46
50
  "LICENSE"
@@ -52,10 +56,12 @@
52
56
  "lint:svg": "node scripts/lint-svg.js",
53
57
  "generate": "node scripts/generate.js"
54
58
  },
59
+ "dependencies": {
60
+ "slugify": "^1.6.6"
61
+ },
55
62
  "devDependencies": {
56
63
  "@types/jsdom": "^27.0.0",
57
64
  "jsdom": "^27.0.1",
58
- "lodash.sortby": "^4.7.0",
59
- "slugify": "^1.6.6"
65
+ "lodash.sortby": "^4.7.0"
60
66
  }
61
67
  }
package/utils/index.js ADDED
@@ -0,0 +1,61 @@
1
+ const { readFileSync, existsSync } = require('fs')
2
+ const { join } = require('path')
3
+ const slugify = require('slugify').default
4
+
5
+ function toSlug(name) {
6
+ return slugify(name, {
7
+ lower: true,
8
+ strict: true,
9
+ })
10
+ }
11
+
12
+ const extractColorsFromSvg = (filePath) => {
13
+ const content = readFileSync(filePath, 'utf8')
14
+ const colorRegex = /fill="(#[0-9A-Fa-f]{6}|#[0-9A-Fa-f]{3})"/gi
15
+ const matches = [...content.matchAll(colorRegex)]
16
+ const colors = [...new Set(matches.map((match) => match[1]))]
17
+ return colors.length > 0 ? colors : null
18
+ }
19
+
20
+ const determineColorModel = (colors) => {
21
+ if (!colors) return null
22
+ return colors.length > 1 ? 'multi' : 'single'
23
+ }
24
+
25
+ const assetTypes = ['icon', 'logo', 'tail']
26
+ const assetsDir = join(__dirname, '..', 'assets')
27
+
28
+ const getAirlineAssets = (slug) => {
29
+ const airlineDir = join(assetsDir, slug)
30
+
31
+ const assets = {}
32
+ assetTypes.forEach((assetType) => {
33
+ const colorAssetPath = join(airlineDir, `${assetType}.svg`)
34
+ const monoAssetPath = join(airlineDir, `${assetType}-mono.svg`)
35
+ const colorAssetExists = existsSync(colorAssetPath)
36
+ const monoAssetExists = existsSync(monoAssetPath)
37
+
38
+ if (colorAssetExists) {
39
+ const colors = extractColorsFromSvg(colorAssetPath)
40
+ const color_model = determineColorModel(colors)
41
+ assets[assetType] = {
42
+ has_mono_file: monoAssetExists,
43
+ }
44
+ if (color_model) {
45
+ assets[assetType].color_model = color_model
46
+ assets[assetType].colors = colors
47
+ }
48
+ } else if (monoAssetExists) {
49
+ assets[assetType] = {
50
+ has_mono_file: true,
51
+ }
52
+ }
53
+ })
54
+
55
+ return assets
56
+ }
57
+
58
+ module.exports = {
59
+ toSlug,
60
+ getAirlineAssets,
61
+ }