本文整理汇总了TypeScript中pluralize.singular函数的典型用法代码示例。如果您正苦于以下问题:TypeScript singular函数的具体用法?TypeScript singular怎么用?TypeScript singular使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了singular函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: singularizeLastWord
export function singularizeLastWord(name:string) {
const parts = getWords(name);
if (parts.length == 0) {
return name;
}
const lastWord = parts.pop();
const lastPos = name.lastIndexOf(lastWord);
return name.substr(0, lastPos) + plural.singular(lastWord) + name.substr(lastPos + lastWord.length);
}
示例2: singular
export const storeReference = (scope: string, identifier: string, store?: Store | string) => {
if (!store) {
return singular(identifier);
}
else if (typeof(store) === 'string') {
return store;
}
else {
invariant(store instanceof Store,
`${scope} - A valid store reference of either a \`String\` or \`Store\` type must be passed, ` +
`but found type \`${typeof(store)}\`.`
);
}
return store;
};
示例3: invariant
export const createSchemaCollection = (path: string, options: IKeyValue = {}): SchemaPath => {
let collectionPath: SchemaPath;
let memberIdentifier: string;
let memberId: string;
let identifier: string;
invariant(typeof(path) === 'string', `createSchemaCollection: expected string path identifier but found \`${path}\``);
// tslint:disable-next-line:max-line-length
invariant(isPlainObject(options), `createSchemaCollection: expected object options identifier but found \`${options}\``);
path = validatePath('schema/createSchemaCollection', path);
identifier = options.identifier || cleanIdentifier(path);
// Collection Node
collectionPath = createSchemaPath(
new SchemaNode(IClassification.collection, identifier, extend({
store: storeReference('schema/createSchemaCollection', identifier, options.store),
path
}, options.collection))
);
// Member Node
memberIdentifier = singular(identifier);
if (memberIdentifier === identifier) {
memberIdentifier = 'member';
memberId = identifier + 'Id';
}
else {
memberId = memberIdentifier + 'Id';
}
collectionPath.addLeaf(
new SchemaNode(IClassification.item, memberIdentifier, extend({
paramId: memberId
}, options.member))
);
return collectionPath;
};
示例4: singular
export function singular(plural?: string | null) {
return plural ? pluralize.singular(plural) : plural;
}
示例5:
...(_.differenceWith(relationFields, relationTableFields, (a, b) => {
// TODO: Manage this ugly hack if finding relation field in
// directive of relation table field
// there is also plural to singular hack in this
return b.directives.join('').indexOf(pluralize.singular(a.name)) > -1
})),