Package Exports
- vscode-helpers
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (vscode-helpers) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
vscode-helpers
Helper functions and classes for Visual Studio Code extensions.
Table of contents
Install [↑]
From your project, run the following command:
npm install --save vscode-helpersUsage [↑]
// plain JavaScript
const vscode_helpers = require('vscode-helpers');
// the TypeScript way
import * as vscode_helpers from 'vscode-helpers';Examples [↑]
Functions [↑]
applyFuncFor [↑]
const OBJ = { factor: 1000 };
function myTestFunc(a, b) {
return (a + b) * this.factor;
}
const APPLIED_FUNC = vscode_helpers.applyFuncFor(
myTestFunc, OBJ
);
APPLIED_FUNC(5979, 23979); // 29958000asArray [↑]
const ARR_1 = vscode_helpers.asArray([ 0, 1, null, 3, 4, undefined ]); // [ 0, 1, 3, 4 ]
const ARR_2 = vscode_helpers.asArray([ 0, 1, null, 3, 4, undefined ], false); // [ 0, 1, null, 3, 4, undefined ]
const ARR_3 = vscode_helpers.asArray( 5979 ); // [ 5979 ]
const ARR_4 = vscode_helpers.asArray( null ); // [ ]asLocalTime [↑]
import * as Moment from 'moment';
let utcNow = Moment.utc();
let localNow = vscode_helpers.asLocalTime( utcNow ); // can also be a string
// or Date objectasUTC [↑]
import * as Moment from 'moment';
let localNow = Moment();
let utcNow = vscode_helpers.asUTC( localNow ); // can also be a string
// or Date objectbuildWorkflow [↑]
const WORKFLOW = vscode_helpers.buildWorkflow()
.next((prevValue) => {
return 5979;
})
.next((prevValue, context) => {
context.value = 1000;
return prevValue + 23979;
})
.next((prevValue, context) => {
return prevValue * context.value;
});
WORKFLOW.start().then((result) => {
// result === 29958
}, (err) => {
// this only happens on errors
});cloneObject [↑]
const CLONED_OBJ = vscode_helpers.cloneObject({
mk: 23979,
tm: 5979,
});compareValues [↑]
const VAL_1 = 2;
const VAL_2 = 1;
const SORTED_OBJS = [ VAL_1, VAL_2 ].sort((x, y) => {
return vscode_helpers.compareValues(x, y);
});compareValuesBy [↑]
const OBJ_1 = { sortValue: 2 };
const OBJ_2 = { sortValue: 1 };
const SORTED_OBJS = [ OBJ_1, OBJ_2 ].sort((x, y) => {
return vscode_helpers.compareValuesBy(x, y,
i => i.sortValue);
});createCompletedAction [↑]
import * as fs from 'fs';
function loadMyFileAsync() {
return new Promise<Buffer>(async (resolve, reject) => {
const COMPLETED = vscode_helpers.createCompletedAction(resolve, reject);
fs.readFile('./MyFile.txt', (err: NodeJS.ErrnoException, data: Buffer) => {
COMPLETED(err, data);
});
});
}createLogger [↑]
import * as fs from 'fs';
const LOGGER = vscode_helpers.createLogger((log) => {
fs.appendFileSync('./logFile.txt', log.message + "\r\n", 'utf8');
});
LOGGER.info('Hello, LOG!');from [↑]
let seq = vscode_helpers.from([ 1, 2, 3 ]) // can also be a generator
// or string
.select(x => '' + x)
.where(x => x !== '2');
for (const ITEM of seq) {
// [0] '1'
// [1] '3'
}invokeAfter [↑]
vscode_helpers.invokeAfter(() => {
return 23979;
}, 5979).then((res) => {
// res === 23979
}, (err) => {
// is invoked on error
});normalizeString [↑]
const str_1 = vscode_helpers.normalizeString('aBc'); // 'abc'
const str_2 = vscode_helpers.normalizeString(null); // ''
const str_3 = vscode_helpers.normalizeString('aBc', s => s.troUpperCase()); // 'ABC'randomBytes [↑]
vscode_helpers.randomBytes(5979).then((bytes) => {
// 5979 random bytes are stored
// in 'bytes' now
}, (err) => {
// error
});sleep [↑]
vscode_helpers.sleep(23979).then(() => {
// 23979 milliseconds gone
}, (err) => {
// is invoked on error
});toBooleanSafe [↑]
const bool_1 = vscode_helpers.toBooleanSafe( true ); // (true)
const bool_2 = vscode_helpers.toBooleanSafe( null ); // (false)
const bool_3 = vscode_helpers.toBooleanSafe( undefined, true ); // (true)toEOL [↑]
import { EndOfLine } as vscode from 'vscode';
const eol_1 = vscode_helpers.toEOL(); // system's EOL
const eol_2 = vscode_helpers.toEOL( EndOfLine.CRLF ); // \r\ntryClearInterval [↑]
let timer = setInterval(() => {
// do something
}, 5979);
vscode_helpers.tryClearInterval( timer );tryClearTimeout [↑]
let timer = setTimeout(() => {
// do something
}, 23979);
vscode_helpers.tryClearTimeout( timer );tryDispose [↑]
const OBJ = {
dispose: () => {
throw new Error( 'Could not dispose!' );
}
};
// (false)
vscode_helpers.tryDispose( OBJ );toStringSafe [↑]
const str_1 = vscode_helpers.toStringSafe( 123 ); // '123'
const str_2 = vscode_helpers.toStringSafe( null ); // ''
const str_3 = vscode_helpers.toStringSafe( undefined, 'abc' ); // 'abc'waitWhile [↑]
let counter = 5979;
vscode_helpers.waitWhile(() => {
return --counter < 1;
}, {
timeUntilNextCheck: 100,
timeout: 60000,
}).then((isTimeout: boolean) => {
// counter === 0
}, (err) => {
// error occurred
});withProgress [↑]
import { ProgressLocation } as vscode from 'vscode';
vscode_helpers.withProgress((context) => {
let res = 0;
for (let i = 0; i < 10; i++) {
context.message = `Task ${i + 1} of 10 ...`;
// do something
++res;
}
return res;
}, {
location: ProgressLocation.Window,
title: 'My operation',
}).then((res) => {
// res === 10
}, (err) => {
// error
});Support and contribute [↑]
If you like the module, you can support the project by sending a donation via PayPal to me.
To contribute, you can open an issue and/or fork this repository.
To work with the code:
- clone this repository
- create and change to a new branch, like
git checkout -b my_new_feature - run
npm installfrom your project folder - open that project folder in Visual Studio Code
- now you can edit and debug there
- commit your changes to your new branch and sync it with your forked GitHub repo
- make a pull request
Documentation [↑]
The API documentation can be found here.