本文整理汇总了TypeScript中ramda.partial函数的典型用法代码示例。如果您正苦于以下问题:TypeScript partial函数的具体用法?TypeScript partial怎么用?TypeScript partial使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了partial函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: listMigrations
export function listMigrations(directory: string): Promise<Migration[]> {
return fs.readdirAsync(directory)
.map(R.match(MIGRATION_FILE_REGEXP))
.filter(R.identity)
.then(R.groupBy(R.nth<string>(1)))
.then(R.mapObj(R.partial(matchesToMigration, directory)))
.then(R.values)
.then(R.sortBy((migration: Migration) => migration.id));
}
示例2: readDownSQL
export function readDownSQL(migration: Migration): Promise<string> {
if (migration.split) {
return fs.readFileAsync(migration.downPath, {encoding: 'utf8'})
.then(R.trim);
}
return fs.readFileAsync(migration.path, {encoding: 'utf8'})
.then(R.split(MIGRATION_SQL_SPLIT_REGEXP))
.tap(R.partial(assertSQLSections, migration))
.then(R.nth(1))
.then(R.trim);
}
示例3: merge
//.........这里部分代码省略.........
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)
}
/**
* Fires after we convert from axios' response into our response. Exceptions
* raised for each monitor will be ignored.
*/
const runMonitors = ourResponse => {
monitors.forEach(monitor => {
try {
monitor(ourResponse)
} catch (error) {
// all monitor complaints will be ignored
}
})
return ourResponse
}
/**
* Converts an axios response/error into our response.
*/
const convertResponse = curry((startedAt: number, axiosResult: AxiosResponse | AxiosError) => {
const end: number = toNumber(new Date())
const duration: number = end - startedAt
// new in Axios 0.13 -- some data could be buried 1 level now
const isError = axiosResult instanceof Error || axios.isCancel(axiosResult)
const axiosResponse = axiosResult as AxiosResponse
const axiosError = axiosResult as AxiosError
const response = isError ? axiosError.response : axiosResponse
const status = (response && response.status) || null
const problem = isError ? getProblemFromError(axiosResult) : getProblemFromStatus(status)
const originalError = isError ? axiosError : null
const ok = in200s(status)
const config = axiosResult.config || null
const headers = (response && response.headers) || null
let data = (response && response.data) || null
// give an opportunity for anything to the response transforms to change stuff along the way
let transformedResponse = {
duration,
problem,
originalError,
ok,
status,
headers,
config,
data,
}
if (responseTransforms.length > 0) {
forEach(transform => transform(transformedResponse), responseTransforms)
}
return transformedResponse
})
// create the base object
const sauce = {
axiosInstance: instance,
monitors,
addMonitor,
requestTransforms,
asyncRequestTransforms,
responseTransforms,
addRequestTransform,
addAsyncRequestTransform,
addResponseTransform,
setHeader,
setHeaders,
deleteHeader,
headers,
setBaseURL,
getBaseURL,
get: partial(doRequestWithoutBody, ['get']),
delete: partial(doRequestWithoutBody, ['delete']),
head: partial(doRequestWithoutBody, ['head']),
post: partial(doRequestWithBody, ['post']),
put: partial(doRequestWithBody, ['put']),
patch: partial(doRequestWithBody, ['patch']),
link: partial(doRequestWithoutBody, ['link']),
unlink: partial(doRequestWithoutBody, ['unlink']),
}
// send back the sauce
return sauce
}
示例4: partial
import { findApp } from './util'
import { FoundBrowser, Browser } from '../types'
import * as linuxHelper from '../linux'
import { log } from '../log'
import { merge, partial } from 'ramda'
const detectCanary = partial(findApp, [
'Contents/MacOS/Google Chrome Canary',
'com.google.Chrome.canary',
'KSVersion'
])
const detectChrome = partial(findApp, [
'Contents/MacOS/Google Chrome',
'com.google.Chrome',
'KSVersion'
])
const detectChromium = partial(findApp, [
'Contents/MacOS/Chromium',
'org.chromium.Chromium',
'CFBundleShortVersionString'
])
type Detectors = {
[index: string]: Function
}
const browsers: Detectors = {
chrome: detectChrome,
canary: detectCanary,
chromium: detectChromium
}
示例5: dissoc
* @param secure - True if sanitization is required
* @param data - Object representing a user model
*/
const respond = (secure: boolean, data: User.UserData): User.UserData =>
secure ? dissoc('password', data) : data;
/**
* Prepares a user object for database insertion
*/
export const cleanUserData = formatter(format);
/**
* Returns a sanitised object representing a user, removing private properties
* @param data - A database record representing a user
*/
export const sanitizedResponse = partial(respond, [true]);
/**
* Returns a clone of an object representing a user
* @param data - A database record representing a user
*/
export const unsanitizedResponse = partial(respond, [false]);
/**
* Get a list of active users
* @param limit - The number of records to fetch
* @param offset - The number of records to skip
*/
export const get = async (limit: number = 10, offset: number = 0): Promise<User.UserData[]> => {
const users = await db.getActiveUsers(limit, offset);
return users.map(sanitizedResponse);