How to use tslib - 10 common examples

To help you get started, we’ve selected a few tslib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github angular / core-builds / esm5 / testing / src / r3_test_bed_compiler.js View on Github external
R3TestBedCompiler.prototype.getOverriddenProviders = function (providers) {
        var _this = this;
        if (!providers || !providers.length || this.providerOverridesByToken.size === 0)
            return [];
        var overrides = this.getProviderOverrides(providers);
        var hasMultiProviderOverrides = overrides.some(isMultiProvider);
        var overriddenProviders = tslib_1.__spread(providers, overrides);
        // No additional processing is required in case we have no multi providers to override
        if (!hasMultiProviderOverrides) {
            return overriddenProviders;
        }
        var final = [];
        var seenMultiProviders = new Set();
        // We iterate through the list of providers in reverse order to make sure multi provider
        // overrides take precedence over the values defined in provider list. We also fiter out all
        // multi providers that have overrides, keeping overridden values only.
        forEachRight(overriddenProviders, function (provider) {
            var token = getProviderToken(provider);
            if (isMultiProvider(provider) && _this.providerOverridesByToken.has(token)) {
                if (!seenMultiProviders.has(token)) {
                    seenMultiProviders.add(token);
                    if (provider && provider.useValue && Array.isArray(provider.useValue)) {
                        forEachRight(provider.useValue, function (value) {
github fossasia / susper.com / node_modules / tslint / lib / rules / typeofCompareRule.js View on Github external
var Rule = /** @class */ (function (_super) {
    tslib_1.__extends(Rule, _super);
    function Rule() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    Rule.prototype.apply = function (sourceFile) {
        return this.applyWithFunction(sourceFile, walk);
    };
    /* tslint:disable:object-literal-sort-keys */
    Rule.metadata = {
        ruleName: "typeof-compare",
        description: "Makes sure result of `typeof` is compared to correct string values",
        optionsDescription: "Not configurable.",
        options: null,
        optionExamples: [true],
        type: "functionality",
        typescriptOnly: false,
        deprecationMessage: !/^2\.1\./.test(ts.version)
github maierj / fastlane-action / node_modules / @firebase / installations / dist / index.cjs.js View on Github external
function getId(app) {
    return tslib.__awaiter(this, void 0, void 0, function () {
        var appConfig, _a, installationEntry, registrationPromise;
        return tslib.__generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    appConfig = extractAppConfig(app);
                    return [4 /*yield*/, getInstallationEntry(appConfig)];
                case 1:
                    _a = _b.sent(), installationEntry = _a.installationEntry, registrationPromise = _a.registrationPromise;
                    if (registrationPromise) {
                        registrationPromise.catch(console.error);
                    }
                    else {
                        // If the installation is already registered, update the authentication
                        // token if needed.
                        refreshAuthToken(appConfig).catch(console.error);
                    }
github angular / compiler-builds / src / output / output_jit.js View on Github external
var fnArgValues = [];
        for (var argName in vars) {
            fnArgNames.push(argName);
            fnArgValues.push(vars[argName]);
        }
        if (createSourceMap) {
            // using `new Function(...)` generates a header, 1 line of no arguments, 2 lines otherwise
            // E.g. ```
            // function anonymous(a,b,c
            // /**/) { ... }```
            // We don't want to hard code this fact, so we auto detect it via an empty function first.
            var emptyFn = new (Function.bind.apply(Function, tslib_1.__spread([void 0], fnArgNames.concat('return null;'))))().toString();
            var headerLines = emptyFn.slice(0, emptyFn.indexOf('return null;')).split('\n').length - 1;
            fnBody += "\n" + ctx.toSourceMapGenerator(sourceUrl, headerLines).toJsComment();
        }
        return new (Function.bind.apply(Function, tslib_1.__spread([void 0], fnArgNames.concat(fnBody))))().apply(void 0, tslib_1.__spread(fnArgValues));
    }
    function jitStatements(sourceUrl, statements, reflector, createSourceMaps) {
github fossasia / susper.com / node_modules / tslint / lib / rules / code-examples / preferWhile.examples.js View on Github external
*     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Lint = require("../../index");
// tslint:disable: object-literal-sort-keys
exports.codeExamples = [
    {
        description: "Prefer `while` loops instead of `for` loops without an initializer and incrementor.",
        config: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n            \"rules\": { \"prefer-while\": true }\n        "], ["\n            \"rules\": { \"prefer-while\": true }\n        "]))),
        pass: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n            for(let i = 1; i < 10; i++) {\n                console.log(i);\n            }\n\n            for (let i = 0; i < 10; i+=1) {\n                console.log(i);\n            }\n\n            for (let i = 0; i < 10;) {\n                i += 1;\n            }\n        "], ["\n            for(let i = 1; i < 10; i++) {\n                console.log(i);\n            }\n\n            for (let i = 0; i < 10; i+=1) {\n                console.log(i);\n            }\n\n            for (let i = 0; i < 10;) {\n                i += 1;\n            }\n        "]))),
        fail: Lint.Utils.dedent(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["\n            for(;;) {\n                console.log('Hello World');\n            }\n\n            for(;true===true;) {\n                console.log('Hello World');\n            }\n        "], ["\n            for(;;) {\n                console.log('Hello World');\n            }\n\n            for(;true===true;) {\n                console.log('Hello World');\n            }\n        "]))),
    },
];
var templateObject_1, templateObject_2, templateObject_3;
github fossasia / susper.com / node_modules / tslint / lib / rules / noVoidExpressionRule.js View on Github external
};
    /* tslint:disable:object-literal-sort-keys */
    Rule.metadata = {
        ruleName: "no-void-expression",
        description: "Requires expressions of type `void` to appear in statement position.",
        optionsDescription: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n            If `", "` is provided, `() => returnsVoid()` will be allowed.\n            Otherwise, it must be written as `() => { returnsVoid(); }`."], ["\n            If \\`", "\\` is provided, \\`() => returnsVoid()\\` will be allowed.\n            Otherwise, it must be written as \\`() => { returnsVoid(); }\\`."])), OPTION_IGNORE_ARROW_FUNCTION_SHORTHAND),
        options: {
            type: "array",
            items: {
                type: "string",
                enum: [OPTION_IGNORE_ARROW_FUNCTION_SHORTHAND],
            },
            minLength: 0,
            maxLength: 1,
        },
        rationale: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n            It's misleading returning the results of an expression whose type is `void`.\n            Attempting to do so is likely a symptom of expecting a different return type from a function.\n            For example, the following code will log `undefined` but looks like it logs a value:\n\n            ```\n            const performWork = (): void => {\n                workFirst();\n                workSecond();\n            };\n\n            console.log(performWork());\n            ```\n        "], ["\n            It's misleading returning the results of an expression whose type is \\`void\\`.\n            Attempting to do so is likely a symptom of expecting a different return type from a function.\n            For example, the following code will log \\`undefined\\` but looks like it logs a value:\n\n            \\`\\`\\`\n            const performWork = (): void => {\n                workFirst();\n                workSecond();\n            };\n\n            console.log(performWork());\n            \\`\\`\\`\n        "]))),
        requiresTypeInfo: true,
        type: "functionality",
        typescriptOnly: false,
    };
    /* tslint:enable:object-literal-sort-keys */
    Rule.FAILURE_STRING = "Expression has type `void`. Put it on its own line as a statement.";
    return Rule;
}(Lint.Rules.TypedRule));
exports.Rule = Rule;
github johandb / svg-drawing-tool / node_modules / @angular / common / esm5 / src / i18n / format_date.js View on Github external
if (typeof value === 'string') {
        value = value.trim();
        var parsedNb = parseFloat(value);
        // any string that only contains numbers, like "1234" but not like "1234hello"
        if (!isNaN(value - parsedNb)) {
            return new Date(parsedNb);
        }
        if (/^(\d{4}-\d{1,2}-\d{1,2})$/.test(value)) {
            /* For ISO Strings without time the day, month and year must be extracted from the ISO String
            before Date creation to avoid time offset and errors in the new Date.
            If we only replace '-' with ',' in the ISO String ("2015,01,01"), and try to create a new
            date, some browsers (e.g. IE 9) will throw an invalid Date error.
            If we leave the '-' ("2015-01-01") and try to create a new Date("2015-01-01") the timeoffset
            is applied.
            Note: ISO months are 0 for January, 1 for February, ... */
            var _a = tslib_1.__read(value.split('-').map(function (val) { return +val; }), 3), y = _a[0], m = _a[1], d = _a[2];
            return new Date(y, m - 1, d);
        }
        var match = void 0;
        if (match = value.match(ISO8601_DATE_REGEX)) {
            return isoStringToDate(match);
        }
    }
    var date = new Date(value);
    if (!isDate(date)) {
        throw new Error("Unable to convert \"" + value + "\" into a date");
    }
    return date;
}
/**
github angular / compiler-builds / esm5 / src / schema / dom_element_schema_registry.js View on Github external
SCHEMA.forEach(function (encodedType) {
            var type = {};
            var _a = tslib_1.__read(encodedType.split('|'), 2), strType = _a[0], strProperties = _a[1];
            var properties = strProperties.split(',');
            var _b = tslib_1.__read(strType.split('^'), 2), typeNames = _b[0], superName = _b[1];
            typeNames.split(',').forEach(function (tag) { return _this._schema[tag.toLowerCase()] = type; });
            var superType = superName && _this._schema[superName.toLowerCase()];
            if (superType) {
                Object.keys(superType).forEach(function (prop) { type[prop] = superType[prop]; });
            }
            properties.forEach(function (property) {
                if (property.length > 0) {
                    switch (property[0]) {
                        case '*':
                            // We don't yet support events.
                            // If ever allowing to bind to events, GO THROUGH A SECURITY REVIEW, allowing events
                            // will
                            // almost certainly introduce bad XSS vulnerabilities.
                            // type[property.substring(1)] = EVENT;
                            break;
                        case '!':
github ezolenko / rollup-plugin-typescript2 / dist / rollup-plugin-typescript2.cjs.js View on Github external
throw new Error("couldn't find '" + tsconfig + "' in " + process.cwd());
    var text = tsModule.sys.readFile(fileName);
    var result = tsModule.parseConfigFileTextToJson(fileName, text);
    if (result.error) {
        printDiagnostics(context, convertDiagnostic("config", [result.error]));
        throw new Error("failed to parse " + fileName);
    }
    return tsModule.parseJsonConfigFileContent(result.config, tsModule.sys, path.dirname(fileName), getOptionsOverrides(pluginOptions, result.config), fileName);
}

// The injected id for helpers.
var TSLIB = "tslib";
var tslibSource;
try {
    // tslint:disable-next-line:no-string-literal no-var-requires
    var tslibPath = require.resolve("tslib/" + require("tslib/package.json")["module"]);
    tslibSource = fs.readFileSync(tslibPath, "utf8");
}
catch (e) {
    console.warn("Error loading `tslib` helper library.");
    throw e;
}

function typescript(options) {
    // tslint:disable-next-line:no-var-requires
    var createFilter = require("rollup-pluginutils").createFilter;
    // tslint:enable-next-line:no-var-requires
    var watchMode = false;
    var round = 0;
    var targetCount = 0;
    var rollupOptions;
    var context;
github ezolenko / rollup-plugin-typescript2 / dist / rollup-plugin-typescript2.es.js View on Github external
throw new Error("couldn't find '" + tsconfig + "' in " + process.cwd());
    var text = tsModule.sys.readFile(fileName);
    var result = tsModule.parseConfigFileTextToJson(fileName, text);
    if (result.error) {
        printDiagnostics(context, convertDiagnostic("config", [result.error]));
        throw new Error("failed to parse " + fileName);
    }
    return tsModule.parseJsonConfigFileContent(result.config, tsModule.sys, dirname(fileName), getOptionsOverrides(pluginOptions, result.config), fileName);
}

// The injected id for helpers.
var TSLIB = "tslib";
var tslibSource;
try {
    // tslint:disable-next-line:no-string-literal no-var-requires
    var tslibPath = require.resolve("tslib/" + require("tslib/package.json")["module"]);
    tslibSource = readFileSync(tslibPath, "utf8");
}
catch (e) {
    console.warn("Error loading `tslib` helper library.");
    throw e;
}

function typescript(options) {
    // tslint:disable-next-line:no-var-requires
    var createFilter = require("rollup-pluginutils").createFilter;
    // tslint:enable-next-line:no-var-requires
    var watchMode = false;
    var round = 0;
    var targetCount = 0;
    var rollupOptions;
    var context;