当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript str.range方法代码示例

本文整理汇总了TypeScript中cafy.str.range方法的典型用法代码示例。如果您正苦于以下问题:TypeScript str.range方法的具体用法?TypeScript str.range怎么用?TypeScript str.range使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cafy.str的用法示例。


在下文中一共展示了str.range方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: async

export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
	// Get 'title' parameter
	const [title, titleErr] = $.str.range(1, 100).get(params.title);
	if (titleErr) return rej('invalid title param');

	// insert
	const userList = await UserList.insert({
		createdAt: new Date(),
		userId: user._id,
		title: title,
		userIds: []
	});

	// Response
	res(await pack(userList));
});
开发者ID:ha-dai,项目名称:Misskey,代码行数:16,代码来源:create.ts

示例2: define

import $ from 'cafy';
import { define, AuthScopes, ApiErrorSources } from '../../modules/endpoint';
import { ObjectIdContext } from '../../modules/cafyValidators';
import { PostingResponseObject } from '../../modules/apiResponse/responseObjects';
import { ChatPostingDocument } from '../../modules/documents';

export default define({
	params: {
		text: $.str.range(1, 256).notMatch(/^\s*$/),
		attachmentIds: $.array($.type(ObjectIdContext)).optional,
	},
	scopes: [AuthScopes.postingWrite]
}, async (manager) => {

	const account = manager.authInfo!.user;

	// params
	const text: string = manager.params.text;
	const attachmentIds: string[] | undefined = manager.params.attachmentIds;

	let chatPostingDoc: ChatPostingDocument;
	try {
		chatPostingDoc = await manager.postingService.createChatPosting(account._id, text, attachmentIds);
	}
	catch (err) {
		console.error(err);
		manager.error(ApiErrorSources.serverError, { message: 'failed to create an chat posting' });
		return;
	}

	await chatPostingDoc.populate(manager.db);
开发者ID:Frost-Dev,项目名称:Frost,代码行数:31,代码来源:create-chat.ts

示例3: define

import $ from 'cafy';
import { define, AuthScopes, ApiErrorSources } from '../../../modules/endpoint';
import { CredentialValidationResponseObject } from '../../../modules/apiResponse/responseObjects';

export default define({
	params: {
		screenName: $.str.range(4, 15).match(/^[a-zA-Z0-9_-]+$/),
		password: $.str.min(8)
	},
	scopes: [AuthScopes.authHost]
}, async (manager) => {

	// params
	const screenName: string = manager.params.screenName;
	const password: string = manager.params.password;

	const userDoc = await manager.userService.findByScreenName(screenName);
	if (!userDoc) {
		manager.ok(new CredentialValidationResponseObject({
			isValid: false
		}));
		return;
	}

	const isValid = userDoc.validatePassword(password);
	if (!isValid) {
		manager.ok(new CredentialValidationResponseObject({
			isValid: false
		}));
		return;
	}
开发者ID:Frost-Dev,项目名称:Frost,代码行数:31,代码来源:validate.ts

示例4: isAvailableScope

import $ from 'cafy';
import { define, AuthScopes, ApiErrorSources } from '../../modules/endpoint';
import { AppResponseObject } from '../../modules/apiResponse/responseObjects';
import { AppDocument } from '../../modules/documents';

function isAvailableScope(scopeId: string): boolean {
	const scope = AuthScopes.toArray().find(s => s.id == scopeId);

	return scope != null && scope.grantable;
}

export default define({
	params: {
		name: $.str.range(1, 32),
		description: $.str.optional.max(256),
		scopes: $.array($.str.pipe(scope => isAvailableScope(scope))).optional.unique()
	},
	scopes: [AuthScopes.appCreate]
}, async (manager) => {

	const account = manager.authInfo!.user;

	// params
	const name: string = manager.params.name;
	const description: string = manager.params.description || '';
	const scopes: string[] = manager.params.scopes || [];

	// if app name is duplicated
	const tempApp = await manager.db.find('api.apps', { name: name });
	if (tempApp) {
		manager.error(ApiErrorSources.duplicatedAppName);
开发者ID:Frost-Dev,项目名称:Frost,代码行数:31,代码来源:create.ts


注:本文中的cafy.str.range方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。