Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vscode-nls

Package Overview
Dependencies
Maintainers
10
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vscode-nls - npm Package Compare versions

Comparing version 5.0.1 to 5.1.0

6

lib/browser/main.d.ts

@@ -1,5 +0,5 @@

import { Options, LocalizeInfo } from '../common/common';
import { Options, LocalizeFunc } from '../common/common';
export { MessageFormat, BundleFormat, Options, LocalizeInfo, LocalizeFunc, LoadFunc, KeyInfo } from '../common/common';
export declare function loadMessageBundle(_file?: string): (key: string | number | LocalizeInfo, message: string, ...args: any[]) => string;
export declare function config(options?: Options): typeof loadMessageBundle;
export declare function loadMessageBundle(file?: string): LocalizeFunc;
export declare function config(opts?: Options): typeof loadMessageBundle;
//# sourceMappingURL=main.d.ts.map

@@ -22,3 +22,29 @@ "use strict";

Object.defineProperty(exports, "BundleFormat", { enumerable: true, get: function () { return common_2.BundleFormat; } });
function loadMessageBundle(_file) {
var nlsData;
try {
// Requiring this file will be intercepted by VS Code and will contain actual NLS data.
// @ts-ignore
nlsData = require('vscode-nls-web-data');
}
catch (e) {
console.error('Loading vscode-nls-web-data failed. Are you running this outside of VS Code? If so, you may need to intercept the import call with your bundled NLS data.');
nlsData = {};
}
var options;
function loadMessageBundle(file) {
if (!file) {
// No file. We are in dev mode. Return the default
// localize function.
return common_1.localize;
}
// Remove extension since we load json files.
if (file.endsWith('.js') || file.endsWith('.ts')) {
file = file.substring(0, file.length - 3);
}
if (file.startsWith('/')) {
file = file.substring(1);
}
if (nlsData && nlsData[file]) {
return createScopedLocalizeFunction(nlsData[file]);
}
return function (key, message) {

@@ -30,3 +56,3 @@ var args = [];

if (typeof key === 'number') {
throw new Error("Browser implementation does currently not support externalized strings.");
throw new Error('Externalized strings were not present in the environment.');
}

@@ -39,3 +65,5 @@ else {

exports.loadMessageBundle = loadMessageBundle;
function config(options) {
// This API doesn't really do anything in practice because the message bundle _has_ to be loaded
// ahead of time via 'vscode-nls-web-data'.
function config(opts) {
var _a;

@@ -46,2 +74,26 @@ (0, common_1.setPseudo)(((_a = options === null || options === void 0 ? void 0 : options.locale) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'pseudo');

exports.config = config;
function createScopedLocalizeFunction(messages) {
return function (key, message) {
var args = [];
for (var _i = 2; _i < arguments.length; _i++) {
args[_i - 2] = arguments[_i];
}
if ((0, common_1.isNumber)(key)) {
if (key >= messages.length) {
console.error("Broken localize call found. Index out of bounds. Stacktrace is\n: ".concat(new Error('').stack));
return;
}
return (0, common_1.format)(messages[key], args);
}
else {
if ((0, common_1.isString)(message)) {
console.warn("Message ".concat(message, " didn't get externalized correctly."));
return (0, common_1.format)(message, args);
}
else {
console.error("Broken localize call found. Stacktrace is\n: ".concat(new Error('').stack));
}
}
};
}
ral_1.default.install(Object.freeze({

@@ -48,0 +100,0 @@ loadMessageBundle: loadMessageBundle,

@@ -64,2 +64,4 @@ export declare enum MessageFormat {

export declare function isDefined(value: any): boolean;
export declare function isNumber(value: any): value is number;
export declare function isString(value: any): value is string;
export declare let isPseudo: boolean;

@@ -66,0 +68,0 @@ export declare function setPseudo(pseudo: boolean): void;

@@ -7,3 +7,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.config = exports.loadMessageBundle = exports.localize = exports.format = exports.setPseudo = exports.isPseudo = exports.isDefined = exports.BundleFormat = exports.MessageFormat = void 0;
exports.config = exports.loadMessageBundle = exports.localize = exports.format = exports.setPseudo = exports.isPseudo = exports.isString = exports.isNumber = exports.isDefined = exports.BundleFormat = exports.MessageFormat = void 0;
var ral_1 = require("./ral");

@@ -34,2 +34,11 @@ var MessageFormat;

exports.isDefined = isDefined;
var toString = Object.prototype.toString;
function isNumber(value) {
return toString.call(value) === '[object Number]';
}
exports.isNumber = isNumber;
function isString(value) {
return toString.call(value) === '[object String]';
}
exports.isString = isString;
exports.isPseudo = false;

@@ -36,0 +45,0 @@ function setPseudo(pseudo) {

@@ -15,9 +15,2 @@ "use strict";

Object.defineProperty(exports, "BundleFormat", { enumerable: true, get: function () { return common_2.BundleFormat; } });
var toString = Object.prototype.toString;
function isNumber(value) {
return toString.call(value) === '[object Number]';
}
function isString(value) {
return toString.call(value) === '[object String]';
}
function isBoolean(value) {

@@ -33,3 +26,3 @@ return value === true || value === false;

options = { locale: undefined, language: undefined, languagePackSupport: false, cacheLanguageResolution: true, messageFormat: common_1.MessageFormat.bundle };
if (isString(process.env.VSCODE_NLS_CONFIG)) {
if ((0, common_1.isString)(process.env.VSCODE_NLS_CONFIG)) {
try {

@@ -40,7 +33,7 @@ var vscodeOptions_1 = JSON.parse(process.env.VSCODE_NLS_CONFIG);

var value = vscodeOptions_1.availableLanguages['*'];
if (isString(value)) {
if ((0, common_1.isString)(value)) {
language = value;
}
}
if (isString(vscodeOptions_1.locale)) {
if ((0, common_1.isString)(vscodeOptions_1.locale)) {
options.locale = vscodeOptions_1.locale.toLowerCase();

@@ -57,9 +50,9 @@ }

}
if (isString(vscodeOptions_1._cacheRoot)) {
if ((0, common_1.isString)(vscodeOptions_1._cacheRoot)) {
options.cacheRoot = vscodeOptions_1._cacheRoot;
}
if (isString(vscodeOptions_1._languagePackId)) {
if ((0, common_1.isString)(vscodeOptions_1._languagePackId)) {
options.languagePackId = vscodeOptions_1._languagePackId;
}
if (isString(vscodeOptions_1._translationsConfigFile)) {
if ((0, common_1.isString)(vscodeOptions_1._translationsConfigFile)) {
options.translationsConfigFile = vscodeOptions_1._translationsConfigFile;

@@ -102,3 +95,3 @@ try {

}
if (isNumber(key)) {
if ((0, common_1.isNumber)(key)) {
if (key >= messages.length) {

@@ -111,3 +104,3 @@ console.error("Broken localize call found. Index out of bounds. Stacktrace is\n: ".concat(new Error('').stack));

else {
if (isString(message)) {
if ((0, common_1.isString)(message)) {
console.warn("Message ".concat(message, " didn't get externalized correctly."));

@@ -227,3 +220,3 @@ return (0, common_1.format)(message, args);

var messageKey = entry.keys[i];
var key = isString(messageKey) ? messageKey : messageKey.key;
var key = (0, common_1.isString)(messageKey) ? messageKey : messageKey.key;
var translatedMessage = translations[key];

@@ -436,3 +429,3 @@ if (translatedMessage === undefined) {

if (opts) {
if (isString(opts.locale)) {
if ((0, common_1.isString)(opts.locale)) {
options.locale = opts.locale.toLowerCase();

@@ -439,0 +432,0 @@ options.language = options.locale;

{
"name": "vscode-nls",
"version": "5.0.1",
"version": "5.1.0",
"description": "NPM module to externalize and localize VSCode extensions",

@@ -5,0 +5,0 @@ "author": "Microsoft Corporation",

@@ -43,2 +43,6 @@ # vscode-nls

### 5.1.0
* Enable a mechanism for something to inject data into vscode-nls. This will be used by VS Code to inject translations into the nls module so that vscode-nls can work in the web. [Context in this PR](https://github.com/microsoft/vscode-nls/pull/42).
### 5.0.1

@@ -45,0 +49,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc