linguist-js
Advanced tools
Comparing version 2.0.2 to 2.0.3
@@ -83,4 +83,7 @@ "use strict"; | ||
let nestedData = data; | ||
for (const part of treeParts) | ||
for (const part of treeParts) { | ||
if (!nestedData[part]) | ||
throw Error(`TraversalError: Key '${part}' cannot be found on output object.`); | ||
nestedData = nestedData[part]; | ||
} | ||
console.log(nestedData); | ||
@@ -87,0 +90,0 @@ } |
@@ -7,2 +7,3 @@ "use strict"; | ||
let finalFlags = new Set(); | ||
// Convert inline flag declarations | ||
const inlineMatches = regex.matchAll(/\?([a-z]):/g); | ||
@@ -14,7 +15,13 @@ const startMatches = regex.matchAll(/\(\?([a-z]+)\)/g); | ||
} | ||
finalRegex = finalRegex | ||
.replace(/([*+]){2}/g, '$1') // ++ and *+ modifiers | ||
.replace(/\\A/g, '^').replace(/\\Z/g, '$'); // start- and end-of-file markers | ||
// Remove invalid modifiers | ||
finalRegex = finalRegex.replace(/([*+]){2}/g, '$1'); | ||
// Remove start/end-of-file markers | ||
if (/\\[AZ]/.test(finalRegex)) { | ||
finalRegex = finalRegex.replace(/\\A/g, '^').replace(/\\Z/g, '$'); | ||
finalFlags.delete('m'); | ||
} | ||
else | ||
finalFlags.add('m'); | ||
return RegExp(finalRegex, [...finalFlags].join('')); | ||
} | ||
exports.default = pcre; |
@@ -16,6 +16,5 @@ "use strict"; | ||
const convertToRegex = (path) => (0, glob_to_regexp_1.default)('**/' + path, { globstar: true, extended: true }); | ||
const last = (arr) => arr[arr.length - 1]; | ||
async function analyse(input, opts = {}) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; | ||
var _l, _m, _o, _p; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j; | ||
var _k, _l, _m; | ||
const langData = await (0, load_data_1.default)('languages.yml').then(js_yaml_1.default.load); | ||
@@ -181,3 +180,3 @@ const vendorData = await (0, load_data_1.default)('vendor.yml').then(js_yaml_1.default.load); | ||
const fileContent = await (0, read_file_1.default)(file); | ||
if (patterns.some(pattern => (0, convert_pcre_1.default)(pattern).test(fileContent))) { | ||
if (!patterns.length || patterns.some(pattern => (0, convert_pcre_1.default)(pattern).test(fileContent))) { | ||
results.files.results[file] = heuristic.language; | ||
@@ -187,12 +186,9 @@ break; | ||
} | ||
// Default to final language | ||
const lastLanguage = last(heuristics.rules).language; | ||
(_f = (_l = results.files.results)[file]) !== null && _f !== void 0 ? _f : (_l[file] = Array.isArray(lastLanguage) ? lastLanguage[0] : lastLanguage); | ||
} | ||
} | ||
// If no heuristics, load the only language | ||
(_g = (_m = results.files.results)[file]) !== null && _g !== void 0 ? _g : (_m[file] = fileAssociations[file][0]); | ||
(_f = (_k = results.files.results)[file]) !== null && _f !== void 0 ? _f : (_k[file] = fileAssociations[file][0]); | ||
} | ||
// Skip specified categories | ||
if ((_h = opts.categories) === null || _h === void 0 ? void 0 : _h.length) { | ||
if ((_g = opts.categories) === null || _g === void 0 ? void 0 : _g.length) { | ||
const categories = ['data', 'markup', 'programming', 'prose']; | ||
@@ -225,3 +221,3 @@ const hiddenCategories = categories.filter(cat => !opts.categories.includes(cat)); | ||
const name = ext === '' ? path_1.default.basename(file) : ext; | ||
(_j = (_o = results.unknown[unknownType])[name]) !== null && _j !== void 0 ? _j : (_o[name] = 0); | ||
(_h = (_l = results.unknown[unknownType])[name]) !== null && _h !== void 0 ? _h : (_l[name] = 0); | ||
results.unknown[unknownType][name] += fileSize; | ||
@@ -233,3 +229,3 @@ results.unknown.bytes += fileSize; | ||
const { type } = langData[lang]; | ||
(_k = (_p = results.languages.results)[lang]) !== null && _k !== void 0 ? _k : (_p[lang] = { type, bytes: 0, color: langData[lang].color }); | ||
(_j = (_m = results.languages.results)[lang]) !== null && _j !== void 0 ? _j : (_m[lang] = { type, bytes: 0, color: langData[lang].color }); | ||
results.languages.results[lang].bytes += fileSize; | ||
@@ -236,0 +232,0 @@ results.languages.bytes += fileSize; |
@@ -1,2 +0,2 @@ | ||
export declare type LanguageType = 'data' | 'markup' | 'programming' | 'prose'; | ||
import { Category } from './types'; | ||
export interface LanguagesScema { | ||
@@ -6,3 +6,3 @@ [name: string]: { | ||
fs_name?: string; | ||
type: LanguageType; | ||
type: Category; | ||
color?: `#${string}`; | ||
@@ -9,0 +9,0 @@ aliases?: string[]; |
@@ -1,4 +0,4 @@ | ||
import { LanguageType } from "./schema"; | ||
export declare type Language = string | null; | ||
export declare type LanguageName = string; | ||
export declare type LanguageResult = string | null; | ||
export declare type Language = string; | ||
export declare type Category = 'data' | 'markup' | 'programming' | 'prose'; | ||
export declare type FilePath = string; | ||
@@ -9,4 +9,4 @@ export declare type Bytes = Integer; | ||
ignoredFiles?: string[]; | ||
ignoredLanguages?: LanguageName[]; | ||
categories?: LanguageType[]; | ||
ignoredLanguages?: Language[]; | ||
categories?: Category[]; | ||
keepVendored?: boolean; | ||
@@ -24,3 +24,4 @@ keepBinary?: boolean; | ||
bytes: Bytes; | ||
results: Record<FilePath, Language>; | ||
/** Note: Results use slashes as delimiters even on Windows. */ | ||
results: Record<FilePath, LanguageResult>; | ||
}; | ||
@@ -30,5 +31,5 @@ languages: { | ||
bytes: Bytes; | ||
results: Record<LanguageName, { | ||
results: Record<Language, { | ||
bytes: Bytes; | ||
type: LanguageType; | ||
type: Category; | ||
color?: `#${string}`; | ||
@@ -35,0 +36,0 @@ }>; |
{ | ||
"name": "linguist-js", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "Analyse languages used in a folder. Powered by GitHub Linguist, although it doesn't need to be installed.", | ||
@@ -40,2 +40,3 @@ "main": "dist/index.js", | ||
"binary-extensions": "^2.2.0", | ||
"commander": "^8.2.0", | ||
"cross-fetch": "^3.1.4", | ||
@@ -47,5 +48,2 @@ "glob-to-regexp": "^0.4.1", | ||
}, | ||
"optionalDependencies": { | ||
"commander": "^8.1.0" | ||
}, | ||
"devDependencies": { | ||
@@ -56,4 +54,4 @@ "@types/glob-to-regexp": "ts4.4", | ||
"deep-object-diff": "^1.1.0", | ||
"typescript": "~4.4.2" | ||
"typescript": "~4.4.3" | ||
} | ||
} |
@@ -121,5 +121,2 @@ [![Latest version](https://img.shields.io/github/v/release/Nixinova/Linguist?label=latest%20version&style=flat-square)](https://github.com/Nixinova/Linguist/releases) | ||
CLI usage requires `commander`, which is marked as an optional dependency. | ||
If an error saying `Cannot find module 'commander'` is thrown, run `npm install commander --no-save`. | ||
``` | ||
@@ -126,0 +123,0 @@ linguist --analyze [<folder>] [<...options>] |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
524
32487
160
+ Addedcommander@^8.2.0