file-lang-map 1.1.0 → 1.1.2

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
@@ -1,22 +1,22 @@
1
1
  # file-lang-map
2
2
 
3
- **Fast, zero-dependency way to identify programming languages from filenames and extensions.**
3
+ **Fast, zero-dependency way to identify programming languages from paths, filenames, and extensions.**
4
4
 
5
5
  ## Why
6
6
 
7
- Most language detection libraries are either too heavy or too slow (looping over arrays).
8
- `file-lang-map` pre-indexes GitHub
9
- Linguist [languages.yml](https://github.com/github/linguist/blob/master/lib/linguist/languages.yml) data into optimized
10
- hash maps, ensuring instant lookups with a tiny footprint.
7
+ Some language detectors can be heavy or rely on linear scans. `file-lang-map` pre-indexes GitHub
8
+ Linguist [languages.yml](https://github.com/github/linguist/blob/master/lib/linguist/languages.yml) into compact lookup
9
+ maps, giving near-instant lookups, a small bundle size, and zero runtime dependencies.
11
10
 
12
11
  ## Features
13
12
 
14
- - **O(1) Performance:** Lookups are instant, regardless of how many languages exist.
15
- - **Browser Ready:** Zero dependencies (no `fs`, no `path`). Works in browser and Node.js.
13
+ - **O(1) (average-case) Performance:** Lookups are instant, regardless of how many languages exist.
14
+ - **Browser Ready:** Zero runtime dependencies. Works in browser and Node.js.
16
15
  - **TypeScript Support:** Includes built-in type definitions.
16
+ - **Flexible:** Works with full and relative paths, filenames, or just extensions for all platforms.
17
+ - **Tiny:** Tree-shakable. Only load what you use. (Use named imports and a bundler that supports tree-shaking)
17
18
  - **Collision Aware:** Correctly handles ambiguous extensions (e.g., `.h` returns "C", "C++" and "Objective-C").
18
- - **Auto-Updated:** Data is fetched directly from GitHub Linguist sources.
19
- - **Tiny:** Tree-shakable. Only load what you use.
19
+ - **Auto-Updated:** Data is fetched directly from GitHub Linguist sources using GitHub actions weekly.
20
20
 
21
21
  ## Installation
22
22
 
@@ -24,11 +24,45 @@ hash maps, ensuring instant lookups with a tiny footprint.
24
24
  npm install file-lang-map
25
25
  ```
26
26
 
27
- ## Usage
27
+ ## Quick Start
28
+
29
+ ```typescript
30
+ import {getLanguageByFileName, getLanguage, getLanguagesByType} from 'file-lang-map';
31
+
32
+ // Get all possible languages from filename (may return null if unknown)
33
+ const languages = getLanguageByFileName('path/to/file.js');
34
+ if (languages === null) {
35
+ console.log('not found')
36
+ } else {
37
+ console.log(languages)
38
+ // ['JavaScript']
39
+ }
40
+
41
+ // Get language metadata by name. Case-insensitive lookup ("javascript" or "JavaScript").
42
+ const language = getLanguage('JavaScript');
43
+ /*
44
+ {
45
+ name: 'JavaScript',
46
+ type: 'programming',
47
+ extensions: ['.js', '.cjs', '.mjs', ... ], // list of all know extensions
48
+ filenames: ['Jakefile'] // list of all known filenames
49
+ }
50
+ */
51
+
52
+ // You can optionally filter results by type (e.g., only 'programming')
53
+ const prog = getLanguageByFileName('data.json', 'programming');
54
+ // prog === null because JSON is a 'data' type
55
+
56
+ // Get list of all known "programming" languages (also available - 'data', 'markup', 'prose')
57
+ const programmingLanguages = getLanguagesByType('programming');
58
+ // ['JavaScript', 'Python', 'TypeScript', 'Rust', ...]
59
+ ```
60
+
61
+ ## Examples
28
62
 
29
63
  ### 1. Identify Language by Filename
30
64
 
31
- Handles full paths, exact filenames, and extensions. Returns an array of language names.
65
+ Handles full paths (absolute or relative), exact filenames, and extensions. Returns an array of language names.
32
66
 
33
67
  ```typescript
34
68
  import {getLanguageByFileName} from 'file-lang-map';
@@ -67,10 +101,13 @@ const json = getLanguageByFileName('data.json', 'programming');
67
101
  ### 3. Get Language Metadata
68
102
 
69
103
  Lookup full language details by name (case-insensitive).
104
+ Language object includes all possible extensions for the language, name, possible filenames, and type.
70
105
 
71
106
  ```typescript
72
107
  import {getLanguage} from 'file-lang-map';
73
108
 
109
+ // Case-insensitive lookup.
110
+ // Returns language object which includes all possible extensions for the language, name...
74
111
  const lang = getLanguage('javascript');
75
112
  /*
76
113
  {
package/dist/index.js CHANGED
@@ -2379,6 +2379,9 @@ var extensions_default = {
2379
2379
  ".pat": [
2380
2380
  "max"
2381
2381
  ],
2382
+ ".metta": [
2383
+ "metta"
2384
+ ],
2382
2385
  ".moo": [
2383
2386
  "mercury",
2384
2387
  "moocode"
@@ -4775,6 +4778,9 @@ var filenames_default = {
4775
4778
  Cask: [
4776
4779
  "emacs lisp"
4777
4780
  ],
4781
+ Eask: [
4782
+ "emacs lisp"
4783
+ ],
4778
4784
  "Project.ede": [
4779
4785
  "emacs lisp"
4780
4786
  ],
@@ -7518,6 +7524,7 @@ var languages_default = {
7518
7524
  ".spacemacs",
7519
7525
  ".viper",
7520
7526
  "Cask",
7527
+ "Eask",
7521
7528
  "Project.ede",
7522
7529
  "_emacs",
7523
7530
  "abbrev_defs"
@@ -9720,6 +9727,14 @@ var languages_default = {
9720
9727
  ],
9721
9728
  filenames: []
9722
9729
  },
9730
+ metta: {
9731
+ name: "MeTTa",
9732
+ type: "programming",
9733
+ extensions: [
9734
+ ".metta"
9735
+ ],
9736
+ filenames: []
9737
+ },
9723
9738
  mercury: {
9724
9739
  name: "Mercury",
9725
9740
  type: "programming",
@@ -14124,6 +14139,7 @@ var types_default = {
14124
14139
  "Mako",
14125
14140
  "Mathematical Programming System",
14126
14141
  "Max",
14142
+ "MeTTa",
14127
14143
  "Mercury",
14128
14144
  "Meson",
14129
14145
  "Metal",
package/dist/index.mjs CHANGED
@@ -2351,6 +2351,9 @@ var extensions_default = {
2351
2351
  ".pat": [
2352
2352
  "max"
2353
2353
  ],
2354
+ ".metta": [
2355
+ "metta"
2356
+ ],
2354
2357
  ".moo": [
2355
2358
  "mercury",
2356
2359
  "moocode"
@@ -4747,6 +4750,9 @@ var filenames_default = {
4747
4750
  Cask: [
4748
4751
  "emacs lisp"
4749
4752
  ],
4753
+ Eask: [
4754
+ "emacs lisp"
4755
+ ],
4750
4756
  "Project.ede": [
4751
4757
  "emacs lisp"
4752
4758
  ],
@@ -7490,6 +7496,7 @@ var languages_default = {
7490
7496
  ".spacemacs",
7491
7497
  ".viper",
7492
7498
  "Cask",
7499
+ "Eask",
7493
7500
  "Project.ede",
7494
7501
  "_emacs",
7495
7502
  "abbrev_defs"
@@ -9692,6 +9699,14 @@ var languages_default = {
9692
9699
  ],
9693
9700
  filenames: []
9694
9701
  },
9702
+ metta: {
9703
+ name: "MeTTa",
9704
+ type: "programming",
9705
+ extensions: [
9706
+ ".metta"
9707
+ ],
9708
+ filenames: []
9709
+ },
9695
9710
  mercury: {
9696
9711
  name: "Mercury",
9697
9712
  type: "programming",
@@ -14096,6 +14111,7 @@ var types_default = {
14096
14111
  "Mako",
14097
14112
  "Mathematical Programming System",
14098
14113
  "Max",
14114
+ "MeTTa",
14099
14115
  "Mercury",
14100
14116
  "Meson",
14101
14117
  "Metal",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "file-lang-map",
3
- "version": "1.1.0",
4
- "description": "Identify programming languages from filenames and extensions.",
3
+ "version": "1.1.2",
4
+ "description": "Identify programming languages from paths, filenames and extensions.",
5
5
  "keywords": [
6
6
  "linguist",
7
7
  "detect-language",