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


TypeScript util.deprecate函數代碼示例

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


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

示例1: bar

/////////////////////////////////////////////////////
/// util tests : https://nodejs.org/api/util.html ///
/////////////////////////////////////////////////////

namespace util_tests {
    {
        // Old and new util.inspect APIs
        util.inspect(["This is nice"], false, 5);
        util.inspect(["This is nice"], false, null);
        util.inspect(["This is nice"], { colors: true, depth: 5, customInspect: false });
        util.inspect(["This is nice"], { colors: true, depth: null, customInspect: false });
        // util.deprecate
        const foo = () => {};
        // $ExpectType () => void
        util.deprecate(foo, 'foo() is deprecated, use bar() instead');
        // $ExpectType <T extends Function>(fn: T, message: string) => T
        util.deprecate(util.deprecate, 'deprecate() is deprecated, use bar() instead');
    }
}

////////////////////////////////////////////////////
/// Stream tests : http://nodejs.org/api/stream.html
////////////////////////////////////////////////////

// http://nodejs.org/api/stream.html#stream_readable_pipe_destination_options
function stream_readable_pipe_test() {
    var r = fs.createReadStream('file.txt');
    var z = zlib.createGzip();
    var w = fs.createWriteStream('file.txt.gz');
    r.pipe(z).pipe(w);
開發者ID:DenisCarriere,項目名稱:DefinitelyTyped,代碼行數:30,代碼來源:node-tests.ts

示例2: deprecate

import { map } from 'starry.map'
import { deprecate } from 'util'

export = deprecate(function asyncOperation(operation, iterable, asyncAction) {
  return operation(map(iterable, asyncAction))
}, 'Use starry.map instead')
開發者ID:seangenabe,項目名稱:starry,代碼行數:6,代碼來源:index.ts

示例3: convertResult

import { deprecate } from 'util';
import DataEntity, { DataInput } from '../data-entity';
import { isPlainObject, getFirst, castArray, isString } from '../../utils';

/**
 * Convert legacy processor results into DataEntities if possible.
 * But in order to be more backwards compatible legacy modules
 * can return an array of buffers or strings.
*/
export function convertResult(input: DataInput[]|Buffer[]|string[]): DataEntity[] {
    if (input == null) return [];
    if (Array.isArray(input) && input.length === 0) return [];

    if (DataEntity.isDataEntityArray(input)) return input;
    if (DataEntity.isDataEntity(input)) return [input];
    const first = getFirst<object|string|Buffer>(input);
    if (first == null) return [];

    // @ts-ignore
    if (Array.isArray(first)) return input;

    if (Buffer.isBuffer(first) || isString(first)) return deprecateType(input);
    if (isPlainObject(first)) return DataEntity.makeArray(input);

    throw new Error('Invalid return type for processor');
}

const deprecateType = deprecate((result: any): DataEntity[] => {
    return castArray<DataEntity>(result);
}, 'Legacy processors should return an array of Objects or DataEntities');
開發者ID:jeffmontagna,項目名稱:teraslice,代碼行數:30,代碼來源:shim-utils.ts

示例4: deprecate

import dllConf from './config/dll.conf'
import prodConf from './config/prod.conf'
import { appPath } from './util'
import { bindDevLogger, bindProdLogger, bindDllLogger, printBuildError } from './util/logHelper'
import { BuildConfig } from './util/types'

const customizeChain = (chain, config) => {
  if (config.webpackChain instanceof Function) {
    config.webpackChain(chain, webpack)
  }
}

const deprecatedCustomizeConfig = deprecate((baseConfig, customConfig) => {
  if (customConfig instanceof Function) {
    return customConfig(baseConfig, webpack)
  } else if (customConfig instanceof Object) {
    return webpackMerge({}, baseConfig, customConfig)
  }
}, chalk.yellow(`h5.webpack配置項即將停止支持,請盡快遷移到新配置項。新配置項文檔:https://nervjs.github.io/taro/docs/config-detail.html#h5`))

const buildDll = async (config: BuildConfig): Promise<any> => {
  if (config.enableDll === false) return Promise.resolve()
  return new Promise((resolve, reject) => {
    const webpackChain = dllConf(config)
    const webpackConfig = webpackChain.toConfig()
    const compiler = webpack(webpackConfig)
    bindDllLogger(compiler)

    compiler.run((err) => {
      if (err) {
        printBuildError(err)
開發者ID:topud,項目名稱:taro,代碼行數:31,代碼來源:index.ts

示例5: function

  }

  return this
}

const multi = Pipeline.prototype.multi
Pipeline.prototype.multi = function () {
  this._transactions += 1
  return multi.apply(this, arguments)
}

const execBuffer = Pipeline.prototype.execBuffer
const exec = Pipeline.prototype.exec
Pipeline.prototype.execBuffer = deprecate(function () {
  if (this._transactions > 0) {
    this._transactions -= 1
  }
  return execBuffer.apply(this, arguments)
}, 'Pipeline#execBuffer: Use Pipeline#exec instead')

Pipeline.prototype.exec = function (callback: CallbackFunction) {
  if (this._transactions > 0) {
    this._transactions -= 1
    return (this.options.dropBufferSupport ? exec : execBuffer).apply(this, arguments)
  }
  if (!this.nodeifiedPromise) {
    this.nodeifiedPromise = true
    asCallback(this.promise, callback)
  }
  if (!this._queue.length) {
    this.resolve([])
  }
開發者ID:luin,項目名稱:ioredis,代碼行數:32,代碼來源:pipeline.ts


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