本文整理汇总了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);
}
示例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
})
示例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));
});
});
示例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
示例5:
const replaceLastSpace = s => R.reverse(R.replace(SPACE, NEW_LINE, R.reverse(s)));
示例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;
};
示例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',
示例8: removeSpaceFromModule
function removeSpaceFromModule(string: string) {
return string.replace(moduleWithDelimiterRegex, R.replace(/\W/, ''));
}
示例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)
示例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));
}