file-lang-map 1.0.0 → 1.1.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.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  **Fast, zero-dependency way to identify programming languages from filenames and extensions.**
4
4
 
5
- ### Why
5
+ ## Why
6
6
 
7
7
  Most language detection libraries are either too heavy or too slow (looping over arrays).
8
8
  `file-lang-map` pre-indexes GitHub
@@ -12,8 +12,9 @@ hash maps, ensuring instant lookups with a tiny footprint.
12
12
  ## Features
13
13
 
14
14
  - **O(1) Performance:** Lookups are instant, regardless of how many languages exist.
15
- - **Browser Ready:** Zero dependencies (no `fs`, no `path`). Works in Vite, Next.js, React, Vue.
16
- - **Collision Aware:** Correctly handles ambiguous extensions (e.g., `.rs` returns both "Rust" and "RenderScript").
15
+ - **Browser Ready:** Zero dependencies (no `fs`, no `path`). Works in browser and Node.js.
16
+ - **TypeScript Support:** Includes built-in type definitions.
17
+ - **Collision Aware:** Correctly handles ambiguous extensions (e.g., `.h` returns "C", "C++" and "Objective-C").
17
18
  - **Auto-Updated:** Data is fetched directly from GitHub Linguist sources.
18
19
  - **Tiny:** Tree-shakable. Only load what you use.
19
20
 
@@ -93,13 +94,16 @@ const lang = getLanguage('javascript');
93
94
 
94
95
  ### 4. Get All Languages by Type
95
96
 
96
- Useful for filtering lists or building dropdowns.
97
+ Useful for filtering lists or building dropdowns. Returns an array of language names (strings).
97
98
 
98
99
  ```typescript
99
100
  import {getLanguagesByType} from 'file-lang-map';
100
101
 
101
102
  const programmingLangs = getLanguagesByType('programming');
102
- // Returns: [ { name: "JavaScript", type: "programming", ... }, { name: "Python"... }, ... ]
103
+ // Returns: ['JavaScript', 'Python', 'TypeScript', 'Rust', ...]
104
+
105
+ const dataLangs = getLanguagesByType('data');
106
+ // Returns: ['JSON', 'YAML', 'CSV', 'TOML', ...]
103
107
  ```
104
108
 
105
109
  ## API Reference
@@ -119,14 +123,14 @@ Look up a full language object by name. Case-insensitive (`"python"`, `"Python"`
119
123
  - **name**: language name
120
124
  - **Returns**: language object
121
125
 
122
- ### `getLanguagesByType(type: LanguageType): Language[]`
126
+ ### `getLanguagesByType(type: LanguageType): string[]`
123
127
 
124
- Get all full language objects belonging to a specific type.
128
+ Get all language names belonging to a specific type.
125
129
 
126
130
  - **type**: `'programming' | 'data' | 'markup' | 'prose'`.
127
- - **Returns**: Array of language objects.
131
+ - **Returns**: Array of language names (strings).
128
132
 
129
- ## Contributing
133
+ ## Contributing and Development
130
134
 
131
135
  This package is **self-updating**. The data is fetched from GitHub Linguist automatically.
132
136
  To refresh the data locally:
@@ -135,12 +139,21 @@ To refresh the data locally:
135
139
  npm run generate
136
140
  ```
137
141
 
138
- ## How Self-Updating Works
142
+ ### Running Tests
143
+
144
+ The project has two test commands:
145
+
146
+ - **`npm test`**: Uses native Node.js glob patterns (`test/**/*.test.ts`). Requires Node.js 20.11+ or 22+.
147
+ - **`npm run test:ci`**: Uses shell `find` command for file discovery. Compatible with Node.js 18+.
148
+
149
+ The CI pipeline tests on Node 18 and 24, so `test:ci` ensures compatibility with older Node versions that don't support
150
+ glob patterns in the `--test` flag.
151
+
152
+ ### How Self-Updating Works
139
153
 
140
- The project uses a `linguist-lock.json` file to track the state of the upstream `languist.yml` (sha256 hash of
141
- linguisl.yml).
154
+ The project creates and uses a `linguist-lock.json` file to track the state of the upstream `linguist.yml`.
142
155
 
143
- - When you or CI/CD run `npm run generate`, it downloads the latest data and calculates a hash.
156
+ - When the CI/CD run `npm run generate`, it downloads the latest data and calculates a hash.
144
157
  - If the hash differs from `linguist-lock.json`, the lock file is updated.
145
158
  - The CI/CD pipeline (`.github/workflows/update-and-publish.yml)` checks for changes in `linguist-lock.json` to decide
146
159
  whether to release a new version.
package/dist/index.d.mts CHANGED
@@ -10,24 +10,24 @@ interface Language {
10
10
  * The pretty display name of the language (e.g., "C++", "JavaScript", "JSON").
11
11
  * Use this for UI labels.
12
12
  */
13
- name: string;
13
+ readonly name: string;
14
14
  /**
15
15
  * The category of the language.
16
16
  */
17
- type: LanguageType;
17
+ readonly type: LanguageType;
18
18
  /**
19
19
  * List of file extensions associated with this language (e.g., [".js", ".mjs"]).
20
20
  */
21
- extensions: string[];
21
+ readonly extensions: string[];
22
22
  /**
23
23
  * List of specific filenames associated with this language (e.g., ["Jenkinsfile"]).
24
24
  */
25
- filenames: string[];
25
+ readonly filenames: string[];
26
26
  /**
27
27
  * The parent group name, if applicable (e.g., "Shell" for "Alpine Abuild", "TypeScript" for "TSX").
28
28
  * Note: This refers to Linguist's inheritance grouping, not the 'type'.
29
29
  */
30
- group?: string;
30
+ readonly group?: string;
31
31
  }
32
32
 
33
33
  /**
@@ -51,29 +51,29 @@ interface Language {
51
51
  declare function getLanguage(languageName: string): Language | null;
52
52
  /**
53
53
  * Get all languages belonging to a specific type category.
54
- * Returns an array of full Language objects, not just names.
54
+ * Returns an array of language names (strings).
55
55
  *
56
56
  * @param {LanguageType} type - The category: 'programming' | 'data' | 'markup' | 'prose'
57
- * @returns {Language[]} Array of Language objects matching the type, or empty array if none found
57
+ * @returns {string[]} Array of language names matching the type, or empty array if none found
58
58
  *
59
59
  * @example
60
60
  * const programmingLangs = getLanguagesByType('programming');
61
- * // => [{ name: 'JavaScript', type: 'programming', ... }, { name: 'Python', ... }, ...]
61
+ * // => ['JavaScript', 'Python', 'TypeScript', 'Rust', ...]
62
62
  *
63
63
  * @example
64
64
  * const dataLangs = getLanguagesByType('data');
65
- * // => [{ name: 'JSON', type: 'data', ... }, { name: 'YAML', ... }, ...]
65
+ * // => ['JSON', 'YAML', 'CSV', ...]
66
66
  *
67
67
  * @example
68
68
  * const markupLangs = getLanguagesByType('markup');
69
- * // => [{ name: 'HTML', type: 'markup', ... }, { name: 'XML', ... }, ...]
69
+ * // => ['HTML', 'XML', 'Markdown', ...]
70
70
  *
71
71
  * @example
72
72
  * // @ts-ignore - invalid type
73
73
  * const invalid = getLanguagesByType('invalid');
74
74
  * // => []
75
75
  */
76
- declare function getLanguagesByType(type: LanguageType): Language[];
76
+ declare function getLanguagesByType(type: LanguageType): string[];
77
77
  /**
78
78
  * Get potential language names for a given file path or filename.
79
79
  * Returns an array of language names because some extensions map to multiple languages (e.g., .rs → Rust, RenderScript).
package/dist/index.d.ts CHANGED
@@ -10,24 +10,24 @@ interface Language {
10
10
  * The pretty display name of the language (e.g., "C++", "JavaScript", "JSON").
11
11
  * Use this for UI labels.
12
12
  */
13
- name: string;
13
+ readonly name: string;
14
14
  /**
15
15
  * The category of the language.
16
16
  */
17
- type: LanguageType;
17
+ readonly type: LanguageType;
18
18
  /**
19
19
  * List of file extensions associated with this language (e.g., [".js", ".mjs"]).
20
20
  */
21
- extensions: string[];
21
+ readonly extensions: string[];
22
22
  /**
23
23
  * List of specific filenames associated with this language (e.g., ["Jenkinsfile"]).
24
24
  */
25
- filenames: string[];
25
+ readonly filenames: string[];
26
26
  /**
27
27
  * The parent group name, if applicable (e.g., "Shell" for "Alpine Abuild", "TypeScript" for "TSX").
28
28
  * Note: This refers to Linguist's inheritance grouping, not the 'type'.
29
29
  */
30
- group?: string;
30
+ readonly group?: string;
31
31
  }
32
32
 
33
33
  /**
@@ -51,29 +51,29 @@ interface Language {
51
51
  declare function getLanguage(languageName: string): Language | null;
52
52
  /**
53
53
  * Get all languages belonging to a specific type category.
54
- * Returns an array of full Language objects, not just names.
54
+ * Returns an array of language names (strings).
55
55
  *
56
56
  * @param {LanguageType} type - The category: 'programming' | 'data' | 'markup' | 'prose'
57
- * @returns {Language[]} Array of Language objects matching the type, or empty array if none found
57
+ * @returns {string[]} Array of language names matching the type, or empty array if none found
58
58
  *
59
59
  * @example
60
60
  * const programmingLangs = getLanguagesByType('programming');
61
- * // => [{ name: 'JavaScript', type: 'programming', ... }, { name: 'Python', ... }, ...]
61
+ * // => ['JavaScript', 'Python', 'TypeScript', 'Rust', ...]
62
62
  *
63
63
  * @example
64
64
  * const dataLangs = getLanguagesByType('data');
65
- * // => [{ name: 'JSON', type: 'data', ... }, { name: 'YAML', ... }, ...]
65
+ * // => ['JSON', 'YAML', 'CSV', ...]
66
66
  *
67
67
  * @example
68
68
  * const markupLangs = getLanguagesByType('markup');
69
- * // => [{ name: 'HTML', type: 'markup', ... }, { name: 'XML', ... }, ...]
69
+ * // => ['HTML', 'XML', 'Markdown', ...]
70
70
  *
71
71
  * @example
72
72
  * // @ts-ignore - invalid type
73
73
  * const invalid = getLanguagesByType('invalid');
74
74
  * // => []
75
75
  */
76
- declare function getLanguagesByType(type: LanguageType): Language[];
76
+ declare function getLanguagesByType(type: LanguageType): string[];
77
77
  /**
78
78
  * Get potential language names for a given file path or filename.
79
79
  * Returns an array of language names because some extensions map to multiple languages (e.g., .rs → Rust, RenderScript).