本文整理汇总了TypeScript中decentraland-commons.utils类的典型用法代码示例。如果您正苦于以下问题:TypeScript utils类的具体用法?TypeScript utils怎么用?TypeScript utils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了utils类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: writeTranslations
async function writeTranslations(
flatMissingTranslations: TranslationCache,
basePath: string = '../src/Translation/locales'
) {
const mainTranslations = await new Translation().fetch(DEFAULT_LOCALE)
const availableLocales = await getAvailableLocales()
const flatMainTranslations = flat.flatten<TranslationData, TranslationData>(
mainTranslations
)
for (const locale of availableLocales) {
const localePath = path.resolve(__dirname, `${basePath}/${locale}.json`)
const flatCurrentTranslations = flatAndRemoveObsoleteKeys(
require(localePath),
flatMainTranslations
)
let updatedTranslations = Object.assign(
{},
flatCurrentTranslations,
flatMissingTranslations[locale]
)
updatedTranslations = flat.unflatten(updatedTranslations)
await utils.promisify(fs.writeFile)(
localePath,
JSON.stringify(updatedTranslations, null, 2),
'utf8'
)
}
}
示例2: omitProps
export function omitProps(obj: any, omittedProps: string[]): any {
const newObj = utils.omit(obj, omittedProps)
for (const prop in newObj) {
const value = newObj[prop]
if (value !== null && typeof value === 'object') {
if (Array.isArray(value)) {
newObj[prop] = value.map(v => omitProps(v, omittedProps))
} else {
newObj[prop] = omitProps(value, omittedProps)
}
}
}
return newObj
}
示例3:
(result, pollId) => {
const poll = polls[pollId]
const fullPoll: PollWithAssociations = {
...utils.omit<Poll>(poll, ['option_ids', 'vote_ids']),
token: tokens[poll.token_address],
votes: poll.vote_ids
.map(voteId => votes[voteId])
.filter(vote => !!vote),
options: poll.option_ids
.map(optionIds => options[optionIds])
.filter(option => !!option)
}
return {
...result,
[pollId]: fullPoll
}
},
示例4: getTokens
async getTokens(): Promise<TokenAttributes[]> {
const tokens = await Token.find<TokenAttributes>()
return utils.mapOmit(tokens, blacklist.token)
}
示例5: getPoll
async getPoll(req: express.Request) {
const id = server.extractFromReq(req, 'id')
const poll = await Poll.findByIdWithAssociations(id)
return utils.omit(poll, blacklist.poll)
}