Socket
Socket
Sign inDemoInstall

@vscode/vscode-languagedetection

Package Overview
Dependencies
0
Maintainers
11
Versions
22
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.15 to 1.0.16

cli/index.js

5

package.json
{
"name": "@vscode/vscode-languagedetection",
"version": "1.0.15",
"version": "1.0.16",
"description": "An npm package that uses guesslang's ML model to detect source code languages",
"main": "dist/lib/index.js",
"bin": {
"vscode-languagedetection": "cli/index.js"
},
"module": "dist/lib/index.js",

@@ -7,0 +10,0 @@ "types": "dist/lib/index.d.ts",

32

README.md

@@ -5,3 +5,3 @@ # vscode-languagedetection

Usage:
## Usage

@@ -16,14 +16,8 @@ First install it in your project:

Then instantiate a ModuleOperations and pass it in the `model.json` and `weights` file content:
Then instantiate a ModuleOperations and run the run the model on a string of code:
> NOTE: This is only for VS Code. In the future, you shouldn't have to do this.
```ts
import { ModelJSON, ModelOperations } from "@vscode/vscode-languagedetection";
import { ModelOperations } from "@vscode/vscode-languagedetection";
const modulOperations = new ModelOperations(async () => {
return JSON.parse(readFileSync(join(__dirname, '..', '..', 'model', 'model.json')).toString()) as ModelJSON;
}, async () => {
return readFileSync(join(__dirname, '..', '..', 'model', 'group1-shard1of1.bin')).buffer;
});
const modulOperations = new ModelOperations();

@@ -87,2 +81,20 @@ const result = await modulOperations.runModel(`

### Advanced options
By default, this library will work in Node.js. It uses the `fs` and `path` modules provided by Node.js to read in the `model.json` file and the weights file, `group1-shard1of1.bin`, that are contained in this repo.
You can overwrite that behavior using the first two optional parameters of `ModelOperations`:
```ts
modelJSONFunc?: () => Promise<any> // This must return a JSON.parse() object
weightsFunc?: () => Promise<ArrayBuffer>
```
These allow you to overwrite the model loading behavior of this package if you happen to be in a non-traditional environment. For an example of this, check out how [VS Code is doing it](https://github.com/microsoft/vscode/blob/3a1cf8e51e3797a2d9ccb12d207378de364596c4/src/vs/workbench/services/languageDetection/browser/languageDetectionService.ts#L60-L80).
The third parameter is the options bag that has:
* `minContentSize?: number` - The minimum number of characters in a file to be considered for language detection. Defaults to `20`.
* `maxContentSize?: number` - The maximum number of characters *that will be used* in a file to be considered for language detection. Defaults to `100000`.
## Local development

@@ -89,0 +101,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc