本文整理匯總了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
})),