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


TypeScript ramda.replace函數代碼示例

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


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

示例1: formatRemotes

export function formatRemotes(remotes: string[]) : string[] {
  const process = R.compose(
    R.uniq,
    R.map(R.replace(/\/$/, '')),
    R.reject(R.isEmpty),
    R.map(R.replace(/\n/, '')),
    R.map(R.trim),
    R.map(rem => rem.replace(/\/\/(.+)@github/, '//github')),
    R.map(rem =>
      rem.match(/github\.com/)
        ? rem.replace(/\.git(\b|$)/, '')
        : rem),
    R.reject(R.isNil),
    R.map(rem => {
      if (rem.match(/^https?:/)) {
        return rem.replace(/\.git(\b|$)/, '');
      } else if (rem.match(/@/)) {
        return 'https://' +
          rem
            .replace(/^.+@/, '')
            .replace(/\.git(\b|$)/, '')
            .replace(/:/g, '/');
      } else if (rem.match(/^ftps?:/)) {
        return rem.replace(/^ftp/, 'http');
      } else if (rem.match(/^ssh:/)) {
        return rem.replace(/^ssh/, 'https');
      } else if (rem.match(/^git:/)) {
        return rem.replace(/^git/, 'https');
      }
    })
  );

  return process(remotes);
}
開發者ID:d4rkr00t,項目名稱:vscode-open-in-github,代碼行數:34,代碼來源:common.ts

示例2: addMiddleware

      addMiddleware(node, (call, next) => {
        // only actions for now
        const skip = call.type !== "action"

        // skip this middleware?
        if (skip) {
          return next(call)
        }

        // userland opt-out
        const shouldSend = mstFilter(call)
        if (!shouldSend) {
          return next(call)
        }

        // grab the arguments
        const args = convertUnsafeArguments(call.args)
        const path = getPath(call.context)

        // action related data
        const action = { args: args, name: call.name, path }

        // mst internal data
        const mstPayload = {
          id: call.id,
          parentId: call.parentId,
          rootId: call.rootId,
          type: call.type,
          modelType: getType(node),
          alive: isAlive(node),
          root: isRoot(node),
          protected: isProtected(node),
        }

        // start a timer
        const elapsed = reactotron.startTimer()

        // chain off to the next middleware
        const result = next(call)

        // measure the speed
        const ms = elapsed()

        // add nice display name
        const displayPath = replace(/^\./, "", replace(/\//g, ".", path))
        let name = replace(/^\./, "", `${nodeName ? nodeName : ""}${displayPath}.${call.name}()`)
        name = replace("/", ".", name)
        // fire this off to reactotron
        if (!restoring) {
          reactotron.send("state.action.complete", {
            name,
            action,
            mst: mstPayload,
            ms,
          })
        }

        // return the result of the next middlware
        return result
      })
開發者ID:TheIdhem,項目名稱:reactotron,代碼行數:60,代碼來源:reactotron-mst.ts

示例3: exec

    exec('git branch --no-color -a', options, (error, stdout, stderr) => {
      if (stderr || error) return reject(stderr || error);

      const getCurrentBranch = R.compose(
        R.trim,
        R.replace('*', ''),
        R.find(line => line.startsWith('*')),
        R.split('\n')
      );

      const processBranches = R.compose(
        R.filter(br => stdout.match(new RegExp(`remotes\/.*\/${br}`))),
        R.uniq
      );

      const currentBranch = getCurrentBranch(stdout);
      const branches = processBranches([currentBranch, defaultBranch]);

      return excludeCurrentRevision
        ? resolve(branches)
        : getCurrentRevision(exec, projectPath)
            .then((currentRevision) => {
              return resolve(branches.concat(currentRevision));
            });
    });
開發者ID:d4rkr00t,項目名稱:vscode-open-in-github,代碼行數:25,代碼來源:common.ts

示例4:

import * as R from 'ramda'

const someSymbolsDelete = R.replace(/[(!?.,)]/g, '')
const fixDoubleSpaces = R.replace(/ {2}/g, ' ')
const someSymbolsToHyphens = R.replace(/[/ ’]/g, '-')

const composeQuery = (word: string) => {
    const escapedWord = R.pipe(
        R.toLower,
        someSymbolsDelete,
        R.trim,
        fixDoubleSpaces,
        someSymbolsToHyphens
    )(word)

    const dictionaryUrl = `https://www.ldoceonline.com/dictionary/${escapedWord}`

    const queryUrl = `https://cors-anywhere.herokuapp.com/${dictionaryUrl}`

    return queryUrl
}

export default composeQuery
開發者ID:yakhinvadim,項目名稱:longman-to-anki,代碼行數:23,代碼來源:composeQuery.ts

示例5:

const replaceLastSpace = s => R.reverse(R.replace(SPACE, NEW_LINE, R.reverse(s)));
開發者ID:paucls,項目名稱:katas,代碼行數:1,代碼來源:wrapper.ts

示例6: pipe

import * as sauce from 'reduxsauce';
import { pipe, replace, toUpper } from 'ramda';

const RX_CAPS = /(?!^)([A-Z])/g;

const camelToScreamingSnake = pipe(
  replace(RX_CAPS, '_$1'),
  toUpper
);

export const createReducer = sauce.createReducer;

export const createActions = (actions) => {
  const { Creators: Actions } = sauce.createActions(actions);

  Object.keys(actions).forEach((key) => {
    Actions[key].toString = () => camelToScreamingSnake(key);
  });

  return Actions;
};
開發者ID:zanjs,項目名稱:wxapp-typescript,代碼行數:21,代碼來源:createActions.ts

示例7: any

const anyPrivate = (hints: CacheControlHintsFormat): boolean => compose<CacheControlHintsFormat, MaybeCacheScope[], boolean>(
  any(equals('PRIVATE')) as any,
  pluck('scope')
)(hints)

const anySegment = (hints: CacheControlHintsFormat): boolean => compose<CacheControlHintsFormat, MaybeCacheScope[], boolean>(
  any(equals('SEGMENT')) as any,
  pluck('scope')
)(hints)

const isPrivateRoute = ({request: {headers}}: GraphQLServiceContext) => test(/_v\/graphql\/private\/v*/, headers['x-forwarded-path'] || '')

const publicRegExp = compose(
  (exp: string) => new RegExp(exp),
  (exp: string) => `.*${exp}.*`,
  replace('.', '\\.')
)(VTEX_PUBLIC_ENDPOINT)

const isPublicEndpoint = ({request: {headers}}: GraphQLServiceContext) => headers.origin
  ? false
  : test(publicRegExp, headers['x-forwarded-host'] || '')

export const cacheControl = (response: GraphQLResponse, ctx: GraphQLServiceContext) => {
  const {vtex: {production}} = ctx
  const hints = response && pickCacheControlHints(response)
  const age = hints && minMaxAge(hints)
  const isPrivate = hints && anyPrivate(hints)
  const segment = hints && anySegment(hints)
  return {
    maxAge: (age === 0 || isPublicEndpoint(ctx) || !production) ? 'no-cache, no-store' : `max-age=${age}`,
    scope: (isPrivate || isPrivateRoute(ctx)) ? 'private' : 'public',
開發者ID:vtex,項目名稱:apps-client-node,代碼行數:31,代碼來源:cacheControl.ts

示例8: removeSpaceFromModule

function removeSpaceFromModule(string: string) {
  return string.replace(moduleWithDelimiterRegex, R.replace(/\W/, ''));
}
開發者ID:nusmodifications,項目名稱:nusmods,代碼行數:3,代碼來源:normalizeString.ts

示例9: extractHeadword

import * as R from 'ramda'
import composeQuery from '../composeQuery/composeQuery'
import composeWordData from '../../core/composeWordData/composeWordData'
import extractHeadword from '../../core/extractHeadword/extractHeadword'
import { WordFetchError } from '../../types.d'

const removeDoubleSpace = R.replace(/ {2}/gm, '')
const removeNewLines = R.replace(/\n/gm, '')
const normalizeMarkup = R.pipe(
    removeDoubleSpace,
    removeNewLines
)

const wordNotFound = (markup: string) => extractHeadword(markup) === ''

const wordToData = async (word: string) => {
    let escapedMarkup

    try {
        const query = composeQuery(word)
        escapedMarkup = await fetch(query).then(response => response.text())
    } catch (error) {
        return { status: WordFetchError.Offline }
    }

    const markup = normalizeMarkup(escapedMarkup)

    if (wordNotFound(markup)) {
        return { status: WordFetchError.NotFound }
    } else {
        const wordData = composeWordData(markup)
開發者ID:yakhinvadim,項目名稱:longman-to-anki,代碼行數:31,代碼來源:wordToData.ts

示例10: getCurrency

 /**
  * Return a string for currency
  * @param num The currency to format to string
  */
 static getCurrency(num: any): string {
   return R.replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,")(num.toFixed(2));
 }
開發者ID:simbiosis-group,項目名稱:ion2-helper,代碼行數:7,代碼來源:formatter.ts


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