linguist-js 2.8.1 → 2.9.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/dist/cli.js CHANGED
@@ -22,6 +22,7 @@ commander_1.program
22
22
  .option('-j|--json [bool]', 'Display the output as JSON', false)
23
23
  .option('-t|--tree <traversal>', 'Which part of the output JSON to display (dot-delimited)')
24
24
  .option('-F|--listFiles [bool]', 'Whether to list every matching file under the language results', false)
25
+ .option('-m|--minSize <size>', 'Minimum size of file to show language results for (must have a unit: b, kb, mb, %, or loc)')
25
26
  .option('-q|--quick [bool]', 'Skip complex language analysis (alias for -{A|I|H|S}=false)', false)
26
27
  .option('-o|--offline [bool]', 'Use packaged data files instead of fetching latest from GitHub', false)
27
28
  .option('-L|--calculateLines [bool]', 'Calculate lines of code totals', true)
@@ -62,7 +63,39 @@ if (args.analyze)
62
63
  const { files, languages, unknown } = data;
63
64
  // Print output
64
65
  if (!args.json) {
65
- const sortedEntries = Object.entries(languages.results).sort((a, b) => a[1].bytes < b[1].bytes ? +1 : -1);
66
+ // Ignore languages with a bytes/% size less than the declared min size
67
+ if (args.minSize) {
68
+ const totalSize = languages.bytes;
69
+ const minSizeAmt = parseFloat(args.minSize.replace(/[a-z]+$/i, '')); // '2KB' -> 2
70
+ const minSizeUnit = args.minSize.replace(/^\d+/, '').toLowerCase(); // '2KB' -> 'kb'
71
+ const checkBytes = minSizeUnit !== 'loc'; // whether to check bytes or loc
72
+ const conversionFactors = {
73
+ 'b': n => n,
74
+ 'kb': n => n * 1e3,
75
+ 'mb': n => n * 1e6,
76
+ '%': n => n * totalSize / 100,
77
+ 'loc': n => n,
78
+ };
79
+ const minBytesSize = conversionFactors[minSizeUnit](+minSizeAmt);
80
+ const other = { bytes: 0, lines: { total: 0, content: 0, code: 0 } };
81
+ // Apply specified minimums: delete language results that do not reach the threshold
82
+ for (const [lang, data] of Object.entries(languages.results)) {
83
+ const checkUnit = checkBytes ? data.bytes : data.lines.code;
84
+ if (checkUnit < minBytesSize) {
85
+ // Add to 'other' count
86
+ other.bytes += data.bytes;
87
+ other.lines.total += data.lines.total;
88
+ other.lines.content += data.lines.content;
89
+ other.lines.code += data.lines.code;
90
+ // Remove language result
91
+ delete languages.results[lang];
92
+ }
93
+ }
94
+ if (other.bytes) {
95
+ languages.results["Other"] = { ...other, type: null };
96
+ }
97
+ }
98
+ const sortedEntries = Object.entries(languages.results).sort((a, b) => (a[1].bytes < b[1].bytes ? +1 : -1));
66
99
  const totalBytes = languages.bytes;
67
100
  console.log(`\n Analysed ${files.bytes.toLocaleString()} B from ${files.count} files with linguist-js`);
68
101
  console.log(`\n Language analysis results: \n`);
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = pcre;
4
3
  /** Convert a PCRE regex into JS. */
5
4
  function pcre(regex) {
6
5
  let finalRegex = regex;
@@ -36,3 +35,4 @@ function pcre(regex) {
36
35
  // Return final regex
37
36
  return RegExp(finalRegex, [...finalFlags].join(''));
38
37
  }
38
+ exports.default = pcre;
@@ -3,8 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.parseGeneratedDataFile = parseGeneratedDataFile;
7
- exports.default = loadFile;
6
+ exports.parseGeneratedDataFile = void 0;
8
7
  const fs_1 = __importDefault(require("fs"));
9
8
  const path_1 = __importDefault(require("path"));
10
9
  const cross_fetch_1 = __importDefault(require("cross-fetch"));
@@ -31,7 +30,9 @@ function parseGeneratedDataFile(fileContent) {
31
30
  var _a;
32
31
  return [...(_a = fileContent.match(/(?<=name\.match\(\/).+?(?=(?<!\\)\/)/gm)) !== null && _a !== void 0 ? _a : []];
33
32
  }
33
+ exports.parseGeneratedDataFile = parseGeneratedDataFile;
34
34
  /** Load a data file from github-linguist. */
35
35
  function loadFile(file, offline = false) {
36
36
  return offline ? loadLocalFile(file) : loadWebFile(file);
37
37
  }
38
+ exports.default = loadFile;
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = parseAttributes;
4
3
  const norm_path_1 = require("./norm-path");
5
4
  /**
6
5
  * Parses a gitattributes file.
@@ -35,3 +34,4 @@ function parseAttributes(content, folderRoot = '.') {
35
34
  }
36
35
  return output;
37
36
  }
37
+ exports.default = parseAttributes;
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = parseGitignore;
4
3
  function parseGitignore(content) {
5
4
  const readableData = content
6
5
  // Remove comments unless escaped
@@ -10,3 +9,4 @@ function parseGitignore(content) {
10
9
  const arrayData = readableData.split(/\r?\n/).filter(data => data);
11
10
  return arrayData;
12
11
  }
12
+ exports.default = parseGitignore;
@@ -3,7 +3,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.default = readFileChunk;
7
6
  const fs_1 = __importDefault(require("fs"));
8
7
  /**
9
8
  * Read part of a file on disc.
@@ -21,3 +20,4 @@ async function readFileChunk(filename, onlyFirstLine = false) {
21
20
  }
22
21
  return content;
23
22
  }
23
+ exports.default = readFileChunk;
@@ -3,7 +3,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.default = walk;
7
6
  const fs_1 = __importDefault(require("fs"));
8
7
  const path_1 = __importDefault(require("path"));
9
8
  const parse_gitignore_1 = __importDefault(require("./parse-gitignore"));
@@ -88,3 +87,4 @@ function walk(data) {
88
87
  folders: [...allFolders],
89
88
  };
90
89
  }
90
+ exports.default = walk;
package/dist/index.js CHANGED
@@ -46,7 +46,7 @@ async function analyse(rawPaths, opts = {}) {
46
46
  const manualFileContent = [(_a = opts.fileContent) !== null && _a !== void 0 ? _a : []].flat();
47
47
  // Normalise input option arguments
48
48
  opts = {
49
- calculateLines: (_b = opts.calculateLines) !== null && _b !== void 0 ? _b : true, // default to true if unset
49
+ calculateLines: (_b = opts.calculateLines) !== null && _b !== void 0 ? _b : true,
50
50
  checkIgnored: !opts.quick,
51
51
  checkDetected: !opts.quick,
52
52
  checkAttributes: !opts.quick,
@@ -380,6 +380,11 @@ disambiguations:
380
380
  pattern: '^import [a-z]'
381
381
  - language: Lean 4
382
382
  pattern: '^import [A-Z]'
383
+ - extensions: ['.lp']
384
+ rules:
385
+ - language: Linear Programming
386
+ pattern: '^(?i:minimize|minimum|min|maximize|maximum|max)(?i:\s+multi-objectives)?$'
387
+ - language: Answer Set Programming
383
388
  - extensions: ['.ls']
384
389
  rules:
385
390
  - language: LoomScript
@@ -469,8 +474,8 @@ disambiguations:
469
474
  - language: MAXScript
470
475
  - extensions: ['.msg']
471
476
  rules:
472
- - language: omnetpp-msg
473
- pattern: '^cplusplus \{\{|^namespace[\s]*([^.\s]*\.)*[^.\s]*;|^struct \{|^message [\S]* (extends)? [\S]*[\s]*\{|^packet \{|^class (extends) [\S]*[\s]*\{|^enum \{|^import ([^.\s]*\.)*[^.\s]*;'
477
+ - language: OMNeT++ MSG
478
+ pattern: '^cplusplus\(?[\S]*\)?[\s]*\{?\{?|^namespace[\s]+([^.\s]*\.)*[^.\s]*;|^struct[\s]+[\S]+|^message[\s]+[\S]+(extends )?[\S]*[\s]*|^packet[\s]+[\S]+|^class[\s]+[\S]+(extends )?[\S]*[\s]*|^enum[\s]+[\S]+|^import ([^.\s]*\.)*[^.\s]*;'
474
479
  - extensions: ['.n']
475
480
  rules:
476
481
  - language: Roff
@@ -707,6 +712,11 @@ disambiguations:
707
712
  rules:
708
713
  - language: STL
709
714
  pattern: '\A\s*solid(?:$|\s)[\s\S]*^endsolid(?:$|\s)'
715
+ - extensions: ['.svx']
716
+ rules:
717
+ - language: Survex data
718
+ pattern: '\A(;|\*[^*]+$)'
719
+ - language: mdsvex
710
720
  - extensions: ['.sw']
711
721
  rules:
712
722
  - language: Sway
@@ -849,7 +859,6 @@ named_patterns:
849
859
  freebasic:
850
860
  - '(?i)^[ \t]*#(?:define|endif|endmacro|ifn?def|include|lang|macro|pragma)(?:$|\s)'
851
861
  - '(?i)^[ \t]*dim( shared)? [a-z_][a-z0-9_]* as [a-z_][a-z0-9_]* ptr'
852
- - '(?i)^[ \t]*dim( shared)? as [a-z_][a-z0-9_]* [a-z_][a-z0-9_]*'
853
862
  gsc:
854
863
  - '^\s*#\s*(?:using|insert|include|define|namespace)[ \t]+\w'
855
864
  - '^\s*(?>(?:autoexec|private)\s+){0,2}function\s+(?>(?:autoexec|private)\s+){0,2}\w+\s*\('
package/ext/languages.yml CHANGED
@@ -271,6 +271,16 @@ AngelScript:
271
271
  codemirror_mode: clike
272
272
  codemirror_mime_type: text/x-c++src
273
273
  language_id: 389477596
274
+ Answer Set Programming:
275
+ type: programming
276
+ color: "#A9CC29"
277
+ extensions:
278
+ - ".lp"
279
+ interpreters:
280
+ - clingo
281
+ tm_scope: source.answersetprogramming
282
+ ace_mode: prolog
283
+ language_id: 433009171
274
284
  Ant Build System:
275
285
  type: data
276
286
  color: "#A9157E"
@@ -305,7 +315,7 @@ ApacheConf:
305
315
  - ".htaccess"
306
316
  - apache2.conf
307
317
  - httpd.conf
308
- tm_scope: source.apache-config
318
+ tm_scope: source.apacheconf
309
319
  ace_mode: apache_conf
310
320
  language_id: 16
311
321
  Apex:
@@ -313,6 +323,7 @@ Apex:
313
323
  color: "#1797c0"
314
324
  extensions:
315
325
  - ".cls"
326
+ - ".apex"
316
327
  - ".trigger"
317
328
  tm_scope: source.apex
318
329
  ace_mode: java
@@ -712,6 +723,7 @@ C:
712
723
  - ".c"
713
724
  - ".cats"
714
725
  - ".h"
726
+ - ".h.in"
715
727
  - ".idc"
716
728
  interpreters:
717
729
  - tcc
@@ -2799,9 +2811,9 @@ HTML+EEX:
2799
2811
  - heex
2800
2812
  - leex
2801
2813
  extensions:
2802
- - ".eex"
2803
- - ".html.heex"
2804
- - ".html.leex"
2814
+ - ".html.eex"
2815
+ - ".heex"
2816
+ - ".leex"
2805
2817
  ace_mode: text
2806
2818
  codemirror_mode: htmlmixed
2807
2819
  codemirror_mime_type: text/html
@@ -3349,6 +3361,14 @@ JSONiq:
3349
3361
  - ".jq"
3350
3362
  tm_scope: source.jsoniq
3351
3363
  language_id: 177
3364
+ Jai:
3365
+ type: programming
3366
+ color: "#ab8b4b"
3367
+ ace_mode: text
3368
+ tm_scope: source.jai
3369
+ extensions:
3370
+ - ".jai"
3371
+ language_id: 70127133
3352
3372
  Janet:
3353
3373
  type: programming
3354
3374
  color: "#0886a5"
@@ -3606,6 +3626,16 @@ Just:
3606
3626
  - ".just"
3607
3627
  ace_mode: text
3608
3628
  language_id: 128447695
3629
+ KDL:
3630
+ type: data
3631
+ color: "#ffb3b3"
3632
+ extensions:
3633
+ - ".kdl"
3634
+ tm_scope: source.kdl
3635
+ ace_mode: tcl
3636
+ codemirror_mode: yacas
3637
+ codemirror_mime_type: text/x-yacas
3638
+ language_id: 931123626
3609
3639
  KRL:
3610
3640
  type: programming
3611
3641
  color: "#28430A"
@@ -3879,6 +3909,13 @@ Limbo:
3879
3909
  tm_scope: none
3880
3910
  ace_mode: text
3881
3911
  language_id: 201
3912
+ Linear Programming:
3913
+ type: programming
3914
+ extensions:
3915
+ - ".lp"
3916
+ tm_scope: none
3917
+ ace_mode: text
3918
+ language_id: 377204539
3882
3919
  Linker Script:
3883
3920
  type: data
3884
3921
  extensions:
@@ -4372,6 +4409,21 @@ MiniYAML:
4372
4409
  codemirror_mode: yaml
4373
4410
  codemirror_mime_type: text/x-yaml
4374
4411
  language_id: 4896465
4412
+ MiniZinc:
4413
+ type: programming
4414
+ color: "#06a9e6"
4415
+ extensions:
4416
+ - ".mzn"
4417
+ tm_scope: source.mzn
4418
+ ace_mode: text
4419
+ language_id: 238874535
4420
+ MiniZinc Data:
4421
+ type: data
4422
+ extensions:
4423
+ - ".dzn"
4424
+ tm_scope: source.mzn
4425
+ ace_mode: text
4426
+ language_id: 938193433
4375
4427
  Mint:
4376
4428
  type: programming
4377
4429
  extensions:
@@ -4882,6 +4934,26 @@ OCaml:
4882
4934
  - ocamlscript
4883
4935
  tm_scope: source.ocaml
4884
4936
  language_id: 255
4937
+ OMNeT++ MSG:
4938
+ type: programming
4939
+ extensions:
4940
+ - ".msg"
4941
+ color: "#a0e0a0"
4942
+ tm_scope: source.msg
4943
+ ace_mode: text
4944
+ aliases:
4945
+ - omnetpp-msg
4946
+ language_id: 664100008
4947
+ OMNeT++ NED:
4948
+ type: programming
4949
+ extensions:
4950
+ - ".ned"
4951
+ color: "#08607c"
4952
+ tm_scope: source.ned
4953
+ ace_mode: text
4954
+ aliases:
4955
+ - omnetpp-ned
4956
+ language_id: 924868392
4885
4957
  Oberon:
4886
4958
  type: programming
4887
4959
  extensions:
@@ -5108,6 +5180,15 @@ Org:
5108
5180
  tm_scope: none
5109
5181
  ace_mode: text
5110
5182
  language_id: 267
5183
+ OverpassQL:
5184
+ type: programming
5185
+ color: "#cce2aa"
5186
+ wrap: true
5187
+ extensions:
5188
+ - ".overpassql"
5189
+ tm_scope: source.overpassql
5190
+ ace_mode: text
5191
+ language_id: 689079655
5111
5192
  Ox:
5112
5193
  type: programming
5113
5194
  extensions:
@@ -7085,6 +7166,14 @@ SuperCollider:
7085
7166
  tm_scope: source.supercollider
7086
7167
  ace_mode: text
7087
7168
  language_id: 361
7169
+ Survex data:
7170
+ type: data
7171
+ color: "#ffcc99"
7172
+ tm_scope: none
7173
+ ace_mode: text
7174
+ extensions:
7175
+ - ".svx"
7176
+ language_id: 24470517
7088
7177
  Svelte:
7089
7178
  type: markup
7090
7179
  color: "#ff3e00"
@@ -8076,6 +8165,7 @@ XML:
8076
8165
  - ".glade"
8077
8166
  - ".gml"
8078
8167
  - ".gmx"
8168
+ - ".gpx"
8079
8169
  - ".grxml"
8080
8170
  - ".gst"
8081
8171
  - ".hzp"
@@ -8239,6 +8329,14 @@ XSLT:
8239
8329
  codemirror_mime_type: text/xml
8240
8330
  color: "#EB8CEB"
8241
8331
  language_id: 404
8332
+ Xmake:
8333
+ type: programming
8334
+ color: "#22a079"
8335
+ filenames:
8336
+ - xmake.lua
8337
+ tm_scope: source.xmake
8338
+ ace_mode: text
8339
+ language_id: 225223071
8242
8340
  Xojo:
8243
8341
  type: programming
8244
8342
  color: "#81bd41"
@@ -8542,6 +8640,17 @@ mcfunction:
8542
8640
  tm_scope: source.mcfunction
8543
8641
  ace_mode: text
8544
8642
  language_id: 462488745
8643
+ mdsvex:
8644
+ type: markup
8645
+ color: "#5f9ea0"
8646
+ tm_scope: none
8647
+ ace_mode: markdown
8648
+ codemirror_mode: gfm
8649
+ codemirror_mime_type: text/x-gfm
8650
+ wrap: true
8651
+ extensions:
8652
+ - ".svx"
8653
+ language_id: 566198445
8545
8654
  mupad:
8546
8655
  type: programming
8547
8656
  color: "#244963"
@@ -8570,22 +8679,6 @@ nesC:
8570
8679
  ace_mode: text
8571
8680
  tm_scope: source.nesc
8572
8681
  language_id: 417
8573
- omnetpp-msg:
8574
- type: programming
8575
- extensions:
8576
- - ".msg"
8577
- color: "#a0e0a0"
8578
- tm_scope: source.msg
8579
- ace_mode: text
8580
- language_id: 664100008
8581
- omnetpp-ned:
8582
- type: programming
8583
- extensions:
8584
- - ".ned"
8585
- color: "#08607c"
8586
- tm_scope: source.ned
8587
- ace_mode: text
8588
- language_id: 924868392
8589
8682
  ooc:
8590
8683
  type: programming
8591
8684
  color: "#b0b77e"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "linguist-js",
3
- "version": "2.8.1",
3
+ "version": "2.9.0",
4
4
  "description": "Analyse languages used in a folder. Powered by GitHub Linguist, although it doesn't need to be installed.",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -42,8 +42,8 @@
42
42
  "binary-extensions": "^2.3.0 <3",
43
43
  "commander": "^9.5.0 <10",
44
44
  "common-path-prefix": "^3.0.0",
45
- "cross-fetch": "^3.1.8 <4",
46
- "ignore": "^5.3.2",
45
+ "cross-fetch": "^3.2.0 <4",
46
+ "ignore": "^7.0.3",
47
47
  "isbinaryfile": "^4.0.10 <5",
48
48
  "js-yaml": "^4.1.0",
49
49
  "node-cache": "^5.1.2"
package/readme.md CHANGED
@@ -50,11 +50,11 @@ Running LinguistJS on this folder will return the following JSON:
50
50
  "files": {
51
51
  "count": 5,
52
52
  "bytes": 6020,
53
- "lines": {
54
- "total": 100,
55
- "content": 90,
56
- "code": 80,
57
- },
53
+ "lines": {
54
+ "total": 100,
55
+ "content": 90,
56
+ "code": 80,
57
+ },
58
58
  "results": {
59
59
  "/src/index.ts": "TypeScript",
60
60
  "/src/cli.js": "JavaScript",
@@ -69,26 +69,46 @@ Running LinguistJS on this folder will return the following JSON:
69
69
  "languages": {
70
70
  "count": 3,
71
71
  "bytes": 6010,
72
- "lines": {
73
- "total": 90,
74
- "content": 80,
75
- "code": 70,
76
- },
72
+ "lines": {
73
+ "total": 90,
74
+ "content": 80,
75
+ "code": 70,
76
+ },
77
77
  "results": {
78
- "JavaScript": { "type": "programming", "bytes": 1000, "lines": { "total": 49, "content": 49, "code": 44 }, "color": "#f1e05a" },
79
- "Markdown": { "type": "prose", "bytes": 3000, "lines": { "total": 10, "content": 5, "code": 5 }, "color": "#083fa1" },
80
- "Ruby": { "type": "programming", "bytes": 10, "lines": { "total": 1, "content": 1, "code": 1 }, "color": "#701516" },
81
- "TypeScript": { "type": "programming", "bytes": 2000, "lines": { "total": 30, "content": 25, "code": 20 }, "color": "#2b7489" },
78
+ "JavaScript": {
79
+ "type": "programming",
80
+ "bytes": 1000,
81
+ "lines": { "total": 49, "content": 49, "code": 44 },
82
+ "color": "#f1e05a"
83
+ },
84
+ "Markdown": {
85
+ "type": "prose",
86
+ "bytes": 3000,
87
+ "lines": { "total": 10, "content": 5, "code": 5 },
88
+ "color": "#083fa1"
89
+ },
90
+ "Ruby": {
91
+ "type": "programming",
92
+ "bytes": 10,
93
+ "lines": { "total": 1, "content": 1, "code": 1 },
94
+ "color": "#701516"
95
+ },
96
+ "TypeScript": {
97
+ "type": "programming",
98
+ "bytes": 2000,
99
+ "lines": { "total": 30, "content": 25, "code": 20 },
100
+ "color": "#2b7489"
101
+ },
82
102
  },
83
103
  },
84
104
  "unknown": {
85
105
  "count": 1,
86
106
  "bytes": 10,
87
- "lines": {
88
- "total": 10,
89
- "content": 10,
90
- "code": 10,
91
- },
107
+ "lines": {
108
+ "total": 10,
109
+ "content": 10,
110
+ "code": 10,
111
+ },
92
112
  "filenames": {
93
113
  "no-lang": 10,
94
114
  },