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


TypeScript lodash.trimStart函數代碼示例

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


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

示例1: async

router.post('/save', async (req: any, res) => {
  if (req.query.type === 'file') {
    if (req.query.filename === '') {
      res.send({});
      return;
    }

    if (req.query.filename === '.json') {
      res.send({});
      return;
    }

    await fileManager.saveFile(
      req.user.id,
      `${trimStart(req.query.dirname, '/')}/${req.query.filename}`,
      req.body.content,
    );
  } else {
    await fileManager.createDir(
      req.user.id,
      `${trimStart(req.query.dirname, '/')}/${req.query.filename}`,
    );
  }

  res.send({});
});
開發者ID:pierophp,項目名稱:pinyin,代碼行數:26,代碼來源:files.controller.ts

示例2: map

        map(lines => {
            const codeElement = singleFileDOMFunctions.getCodeElementFromLineNumber(
                codeView,
                position.line,
                position.part
            )
            if (!codeElement) {
                throw new Error('(adjustPosition) could not find code element for line provided')
            }

            const actualLine = lines[position.line - 1]
            const documentLine = codeElement.textContent || ''

            const actualLeadingWhiteSpace = actualLine.length - trimStart(actualLine).length
            const documentLeadingWhiteSpace = documentLine.length - trimStart(documentLine).length

            const modifier = direction === AdjustmentDirection.ActualToCodeView ? -1 : 1
            const delta = Math.abs(actualLeadingWhiteSpace - documentLeadingWhiteSpace) * modifier

            return {
                line: position.line,
                character: position.character + delta,
            }
        })
開發者ID:JoYiRis,項目名稱:sourcegraph,代碼行數:24,代碼來源:code_intelligence.ts

示例3: trimStart

import {trim, trimStart, trimEnd, pad, padStart, padEnd} from "lodash";

const trimStr: string = "     trim        ";
console.log("trimStart()");
console.log("*" + trimStart(trimStr) + "*");
console.log("trimEnd()");
console.log("*" + trimEnd(trimStr) + "*");
console.log("trim()");
console.log("*" + trim(trimStr) + "*");


const padStr: string = "pad";
console.log("padStart()");
console.log(padStart(padStr, 10, "_"));
console.log("padEnd()");
console.log(padEnd(padStr, 10, "_"));
console.log("pad()");
console.log(pad(padStr, 10, "_"));

開發者ID:kwpeters,項目名稱:node-sandbox,代碼行數:18,代碼來源:lodashTest.ts

示例4: checkForLeadingWhitespace

function checkForLeadingWhitespace(filePath: string, fileContents: string) {
  const fileHasLeadingWhitespace = trimStart(fileContents).length !== fileContents.length;
  const failures: Failure[] = fileHasLeadingWhitespace ? [{ filePath, message: 'File has leading whitespace.' }] : [];
  return failures;
}
開發者ID:kevinphelps,項目名稱:kevinphelps.me,代碼行數:5,代碼來源:prelint.ts

示例5: Promise

	return new Promise((resolve, reject) => {
		let params;
		const startTime = new Date().getTime();

		if (_.isEmpty(_self._config.target)) {
			return reject(new errors.TargetError(opts, 'Target not set'));
		}

		// Validate Opts
		_.forEach(_.pick(opts, ['startElement', 'numElements']), (value, opt) => {
			if (_hasValue(value) && !_isInteger(value)) {
				return reject(new errors.ArgumentError(opts, 'Invalid ' + opt));
			}
			return null;
		});

		// Configure Options
		let reqOpts: IRequestOptionsInternal = {
			method: (opts.method || Method.GET).toUpperCase(),
			uri: urlJoin(_self._config.target, _.trimStart(opts.uri, '/')),
			timeout: opts.timeout || _self._config.timeout,
			rejectUnauthorized: false,
			headers: { ..._self._config.headers },
			params: { ...opts.params },
			body: opts.body,
			encodeParams: _.get(opts, 'encodeParams', false),
		};

		if (_self._config.userAgent) {
			reqOpts.headers['User-Agent'] = _self._config.userAgent;
		}

		if (!opts.noAuth && !opts.auth && _self._config.token) {
			reqOpts.headers.Authorization = _self._config.token;
		}

		if (opts.mimeType) {
			reqOpts.headers.Accept = opts.mimeType;
			if (opts.method === Method.POST || opts.method === Method.PUT) {
				reqOpts.headers['Content-Type'] = opts.mimeType;
			}
		} else {
			// Default Accept to application/json
			reqOpts.headers.Accept = _.get(opts, 'headers.Accept', 'application/json');

			// Default Content-Type to application/json for POSTs and PUTs
			if (reqOpts.method === Method.POST || reqOpts.method === Method.PUT) {
				reqOpts.headers['Content-Type'] = _.get(opts, 'headers.Content-Type', 'application/json');
			}
		}

		reqOpts.headers = _.assign({}, reqOpts.headers, opts.headers);

		// Configure Parameters
		if (_hasValue(opts.startElement)) {
			reqOpts.params.start_element = (+opts.startElement).toString();
		}
		if (_hasValue(opts.numElements)) {
			reqOpts.params.num_elements = (+opts.numElements).toString();
			reqOpts.params.start_element = (+opts.startElement || reqOpts.params.start_element || 0).toString(); // startElement is required if numElements is set
		}

		params = query.stringify(reqOpts.params, {encode: reqOpts.encodeParams});

		if (params !== '') {
			reqOpts.uri += (opts.uri.indexOf('?') === -1) ? '?' : '&';
			reqOpts.uri += params;
		}

		if (_self._config.beforeRequest) {
			const beforeRequestOpts = _self._config.beforeRequest(reqOpts);
			if (beforeRequestOpts) {
				reqOpts = _.assign({}, reqOpts, beforeRequestOpts);
			}
		}

		return _self._config.request(reqOpts).then((res) => {
			const totalTime = new Date().getTime() - startTime;

			let newRes: IResponse = _.assign({
				requestTime: res.requestTime || totalTime,
				totalTime: new Date().getTime() - startTime,
			}, res);

			if (_self._config.afterRequest) {
				const afterRequestRes = _self._config.afterRequest(newRes);
				if (afterRequestRes) {
					newRes = _.assign({}, newRes, afterRequestRes);
				}
			}

			if (newRes.statusCode >= 400) {
				return reject(errors.buildError(reqOpts, newRes));
			}

			// Temporary fix
			let errorId;
			let errorCode;
			if (newRes.body && newRes.body.response && newRes.body.response) {
				errorId = newRes.body.response.error_id;
//.........這裏部分代碼省略.........
開發者ID:appnexus,項目名稱:anx-api,代碼行數:101,代碼來源:api.ts


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