當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript app-root-path.require函數代碼示例

本文整理匯總了TypeScript中app-root-path.require函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript require函數的具體用法?TypeScript require怎麽用?TypeScript require使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了require函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: async

import * as path from "path";
import * as stream from "stream";
import * as test from "tape";
import * as appRoot from "app-root-path";

// Only used to type annotate (typeof Logger) dynamic imports. Will not emit import() if only used that way. 
import * as NodeLoggerType from "../src/index.ts";

const Log: typeof NodeLoggerType = appRoot.require("/lib/index");

test("Logger test", async (assert) => {
    const testStreams = [createStringStream(), createStringStream()];
    const log = Log.createFromConfigFile();
    log.level = "INFO";
    log.destinations = testStreams;
    log.logFunctions = [Log.LogFunction.defaultJson];
    
    const isError = log.isErrorOrVerboser();
    const isWarn = log.isWarnOrVerboser();
    const isInfo = log.isInfoOrVerboser();
    const isDebug = log.isDebugOrVerboser();
    assert.true(isError, "INFO is more verbose than ERROR");
    assert.true(isWarn, "INFO is more verbose than WARN");
    assert.true(isInfo, "INFO is as verbose as INFO");
    assert.false(isDebug, "INFO is less verbose than DBUG");

    let res0: NodeLoggerType.Message;
    let res1: NodeLoggerType.Message;    
    await log.error(new Error("test exception without tag"));
    res0 = JSON.parse(testStreams[0].read());
    res1 = JSON.parse(testStreams[1].read());
開發者ID:HardwareProjects,項目名稱:node-logger,代碼行數:31,代碼來源:logger-test.ts

示例2:

/// <reference path="app-root-path.d.ts" />
import * as root from 'app-root-path';

let resolvedPath: string;
resolvedPath = root.resolve('../dir');
resolvedPath = root.path;
resolvedPath = root.toString();
let resolvedModule: any = root.require('app-root-path');
root.setPath('C:\\app-root');

開發者ID:Agamnentzar,項目名稱:DefinitelyTyped,代碼行數:9,代碼來源:app-root-path-tests.ts

示例3: require

import { invert, isArray } from 'lodash';
import { GRAPHIQL_ROUTE } from '../ENDPOINTS';
import { logger } from '@sample-stack/utils';

var reqlib: any = require('app-root-path');

let persistCache = true;
let queryMap;
try {
    queryMap = reqlib.require('@sample-stack/graphql-gql/extracted_queries.json');

} catch (err) {
    logger.warn('extracted_queries.json file is unavailable, disabling persist queries');
}
export const persistedQueryMiddleware = (req, res, next) => {

    if (queryMap) {
        const invertedMap = invert(queryMap);

        if (isArray(req.body)) {
            req.body = req.body.map(body => {
                const id = body['id'];
                return {
                    query: invertedMap[id],
                    ...body,
                };
            });
            next();
        } else {
            if (!__DEV__ || (req.get('Referer') || '').indexOf(GRAPHIQL_ROUTE) < 0) {
                res.status(500).send('Unknown GraphQL query has been received, rejecting...');
開發者ID:baotaizhang,項目名稱:fullstack-pro,代碼行數:31,代碼來源:persistedQuery.ts


注:本文中的app-root-path.require函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。