Nixinova / LinguistJS

Analyse and list all languages used in a folder. Implementation of and powered by GitHub's Linguist.
ISC License
39 stars 12 forks source link

Allow analysis of raw file content #10

Closed Nixinova closed 2 years ago

Nixinova commented 2 years ago

Discussed in https://github.com/Nixinova/Linguist/discussions/9

Originally posted by **lowlighter** February 8, 2022 From what I understand, the exported `analyse` function only takes a list of paths as inputs, and from there it'll walk on each file in given directories: https://github.com/Nixinova/Linguist/blob/9a15a06266b45a0075351c8884a519d42cc252b0/src/index.ts#L16-L18 Would it be possible to expose another entry point which directly accepts a raw string as argument and returns the result instead ?

This requires a refactoring of all the index.ts source as each stage in the analysis would need to be able to be called separately.

The function header would be something like this:

interface Metadata { filename: string, /* extension: string //? */, size: number, /* ... */ };
export default async function analyseSingle(content: string | string[], metadata: Metadata, opts?: T.Options): Promise<T.Results> {
Nixinova commented 2 years ago

This shouldn't need a rewrite actually, it can be done without having to move too much about see https://github.com/Nixinova/Linguist/commit/1878abfa665bd9e25ab2989533c51bfe2c77617c Will add this change for 2.3.

princefishthrower commented 8 months ago

@Nixinova - so, as far as I can tell, this is not yet in the codebase! Has the API changed for raw input or is there a more updated example?

Nixinova commented 8 months ago

See https://github.com/Nixinova/LinguistJS/issues/30#issuecomment-1985362112 :+1: