
Research
PyPI Package Disguised as Instagram Growth Tool Harvests User Credentials
A deceptive PyPI package posing as an Instagram growth tool collects user credentials and sends them to third-party bot services.
vscode-diff
Advanced tools
A small, zero-dependency text differencing library extracted from the open source VS Code editor. The implementation is based on the difference algorithm described in "An O(ND) Difference Algorithm and its variations" by Eugene W. Myers.
The package includes typescript definitions.
npm install vscode-diff --save
Starting from version 1.71.0 VS Code introduced new diffing algorithm that can also detect code moves. It is currently used by default in VS Code and can be accessed in this library as AdvancedLinesDiffComputer
.
The legacy algorithm can be accessed as DiffComputer
.
import { DiffComputer, IDiffComputerOpts, ILineChange } from 'vscode-diff';
let originalLines: string[] = ["hello", "original", "world"];
let modifiedLines: string[] = ["hello", "modified", "world", "foobar"];
let options: IDiffComputerOpts = {
shouldPostProcessCharChanges: true,
shouldIgnoreTrimWhitespace: true,
shouldMakePrettyDiff: true,
shouldComputeCharChanges: true,
maxComputationTime: 0 // time in milliseconds, 0 => no computation limit.
}
let diffComputer = new DiffComputer(originalLines, modifiedLines, options);
let lineChanges: ILineChange[] = diffComputer.computeDiff().changes;
console.log(JSON.stringify(lineChanges, null, 2));
Output:
[
{
"originalStartLineNumber": 2,
"originalEndLineNumber": 2,
"modifiedStartLineNumber": 2,
"modifiedEndLineNumber": 2,
"charChanges": [
{
"originalStartLineNumber": 2,
"originalStartColumn": 1,
"originalEndLineNumber": 2,
"originalEndColumn": 9,
"modifiedStartLineNumber": 2,
"modifiedStartColumn": 1,
"modifiedEndLineNumber": 2,
"modifiedEndColumn": 9
}
]
},
{
"originalStartLineNumber": 3,
"originalEndLineNumber": 0,
"modifiedStartLineNumber": 4,
"modifiedEndLineNumber": 4
}
]
Each element in the produced lineChanges
array corresponds to a change from the original lines to the modified lines.
The column and row indices are 1-based. If a 0 index is present, it means that a row has been added/removed, eg:
{
"originalStartLineNumber": 3,
"originalEndLineNumber": 0,
"modifiedStartLineNumber": 4,
"modifiedEndLineNumber": 4
}
means that the 4th line in the modified text was added after line 3 in the original text.
The opposite:
{
"originalStartLineNumber": 4,
"originalEndLineNumber": 4,
"modifiedStartLineNumber": 3,
"modifiedEndLineNumber": 0
}
means that the 4th line in the original text was removed from after line 3 in the modified text.
let advOptions: ILinesDiffComputerOptions = {
ignoreTrimWhitespace: true,
computeMoves: true,
maxComputationTimeMs: 0
}
let advDiffComputer = new AdvancedLinesDiffComputer()
let advLineChanges = advDiffComputer.computeDiff(originalLines, modifiedLines, advOptions).changes;
console.log(JSON.stringify(advLineChanges, null, 2));
Output:
[
{
"originalRange": {
"startLineNumber": 2,
"endLineNumberExclusive": 3
},
"modifiedRange": {
"startLineNumber": 2,
"endLineNumberExclusive": 3
},
"innerChanges": [
{
"originalRange": {
"startLineNumber": 2,
"startColumn": 1,
"endLineNumber": 2,
"endColumn": 9
},
"modifiedRange": {
"startLineNumber": 2,
"startColumn": 1,
"endLineNumber": 2,
"endColumn": 9
}
}
]
},
{
"originalRange": {
"startLineNumber": 4,
"endLineNumberExclusive": 4
},
"modifiedRange": {
"startLineNumber": 4,
"endLineNumberExclusive": 5
},
"innerChanges": [
{
"originalRange": {
"startLineNumber": 3,
"startColumn": 6,
"endLineNumber": 3,
"endColumn": 6
},
"modifiedRange": {
"startLineNumber": 3,
"startColumn": 6,
"endLineNumber": 4,
"endColumn": 7
}
}
]
}
]
The format of the result mapping is similar to that returned by DiffComputer
but beware that then ending line number in line range is exclusive, e.g.
"originalRange": {
"startLineNumber": 2,
"endLineNumberExclusive": 3
}
as opposed to
"originalStartLineNumber": 2,
"originalEndLineNumber": 2,
AdvancedLinesDiffComputer
.charChanges
) there is a new hard coded maximum limit of 5 seconds.interface IDiffComputerResult {
quitEarly: boolean;
changes: ILineChange[];
}
Initial release
Since we do not want this package to differ from the original implementation in VS Code, no changes that differs from the source repository will be merged. Any changes that only affect this npm package (like changes to this README) are welcome via pull requests.
Steps for updating diff algorithm:
npm run build
that all code is self-contained.npm run knip
that there are no unused files or exports.npm test
to run all the tests.npm run example
and update this README with example usage code and output.Any help documenting the diff API is very welcome.
The source code of this package is directly extracted from the open source software VS Code, Copyright (c) Microsoft Corporation. The VS Code source files is licensed under the MIT license. See src/LICENSE.txt for additional details.
Only minor modifications have been made to the source files:
I am in no way affiliated to Microsoft or the VS Code team.
FAQs
Diff utility used in the Visual Studio Code source.
The npm package vscode-diff receives a total of 4,610 weekly downloads. As such, vscode-diff popularity was classified as popular.
We found that vscode-diff demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
A deceptive PyPI package posing as an Instagram growth tool collects user credentials and sends them to third-party bot services.
Product
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.
Security News
Research
Socket uncovered two npm packages that register hidden HTTP endpoints to delete all files on command.