本文整理汇总了TypeScript中ramda.pipe函数的典型用法代码示例。如果您正苦于以下问题:TypeScript pipe函数的具体用法?TypeScript pipe怎么用?TypeScript pipe使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pipe函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
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
}
示例2: splitBySelector
const extractDefinition = (senseMarkup: string) => {
const definitionNodeMarkup = splitBySelector({
selector: '.DEF',
onlyChildren: true
})(senseMarkup)[0]
if (!definitionNodeMarkup) {
return ''
}
const definition = R.pipe(
domify,
getTrimmedTextContent
)(definitionNodeMarkup)
return definition
}
示例3: extractHeadword
const composeWordData = (pageMarkup: string) => {
const headword = extractHeadword(pageMarkup)
const pronunciation = extractPronunciation(pageMarkup)
const frequency = extractFrequency(pageMarkup)
const entries = R.pipe(
splitBySelector({ selector: '.ldoceEntry' }),
R.map(composeEntryData)
)(pageMarkup)
const wordData = {
headword,
pronunciation,
frequency,
entries
}
return wordData
}
示例4: clean
static clean(required, strings, floats, data) {
const rejectEmpty = R.reject(n => R.isEmpty(n[required]));
const cleanStrings = R.map(n => {
n[strings] = R.trim(n[strings]);
return n;
});
const cleanFloats = R.map(n => {
n[floats] = parseFloat(n[floats]);
return n;
});
const clean = R.pipe(rejectEmpty,
cleanStrings,
cleanFloats
);
return clean(data);
}
示例5: forEach
const doRequest = async axiosRequestConfig => {
axiosRequestConfig.headers = {
...headers,
...axiosRequestConfig.headers,
}
// add the request transforms
if (requestTransforms.length > 0) {
// overwrite our axios request with whatever our object looks like now
// axiosRequestConfig = doRequestTransforms(requestTransforms, axiosRequestConfig)
forEach(transform => transform(axiosRequestConfig), requestTransforms)
}
// add the async request transforms
if (asyncRequestTransforms.length > 0) {
for (let index = 0; index < asyncRequestTransforms.length; index++) {
const transform = asyncRequestTransforms[index](axiosRequestConfig)
if (isPromise(transform)) {
await transform
} else {
await transform(axiosRequestConfig)
}
}
}
// after the call, convert the axios response, then execute our monitors
const chain = pipe(
convertResponse(toNumber(new Date())),
// partial(convertResponse, [toNumber(new Date())]),
runMonitors,
)
return instance
.request(axiosRequestConfig)
.then(chain)
.catch(chain)
}
示例6: normalize
}
const replaceBrackets = (str: string) => str.replace(/[{[<]/g, '(').replace(/[}\]>]/g, ')');
const replaceOperators = (str: string) =>
str
.replace(/[|/]/g, OPERATORS.or)
.replace(/[;&]/g, OPERATORS.and)
.replace(/ plus /g, OPERATORS.and)
.replace(OPERATORS_REGEX, R.toLower);
export const normalize = R.pipe(
removeSpaceFromModule,
fixOperatorTypos,
insertPostFixAsStandalone,
convertCommas,
R.curry(convertToNumerals)(1),
replaceBrackets,
fixBrackets,
replaceOperators,
removeModuleTitles,
);
export default function normalizeString(string: string, moduleCode: ModuleCode): string {
// remove own module code from string (e.g. `CS1000R` would remove `CS1000R`, `CS1000`)
// @ts-ignore Strings are lists, damn it
const moduleWithoutPostfix = moduleCode.slice(0, R.findLastIndex(R.test(/\d/), moduleCode) + 1);
const moduleRegex = new RegExp(`\\b${moduleWithoutPostfix}(?:[A-Z]|[A-Z]R)?\\b`, 'g');
const preprocessed = string.replace(moduleRegex, '');
return normalize(preprocessed);
}
示例7:
const updateFromBootsrapMessage = (data: BootstrapMessage) =>
R.pipe<State, State, State>(
R.assoc('boards', data.boards),
R.assoc('notes', data.notes)
)
示例8: pipe
import { pipe, curry } from 'ramda'
export const getRandom = (start, end) => start + Math.round(Math.random() * end)
export const jsonClone = pipe(
JSON.stringify,
JSON.parse
)
export const mutableAppend = curry((array, target) => {
target.splice(target.length, 0, ...array)
return target
})
示例9: 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;
};
示例10: fn
);
const summaryFile = fs.createWriteStream(path.resolve(projectPath, 'SUMMARY.md'));
type ContentConverter = (c: string) => string;
const convertContentWith = R.curry(
(fn: ContentConverter, page: MarkdownPage) => R.merge(page, { content: fn(page.content) })
);
// string -> string
const convertionPineline = R.pipe(
addToSummary(summaryFile),
convertContentWith(decreaseHeaderLevel),
convertContentWith(convertImgTag),
convertContentWith(convertPlantUmlTag),
convertContentWith(removeToc),
convertContentWith(convertGist),
convertContentWith(convertSwagger),
addTitleAuthor,
);
// file -> void
// @ts-ignore waiting for @types/ramda update
const processMarkdown = R.pipeWith(R.then)([
(file: string) => inName(['README', 'SUMMARY'], file)
? Promise.resolve(file) : moveToIndex(file),
log('Convert'),
convert(convertionPineline)
]);
// dir -> void