• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript punycode.toUnicode函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中punycode.toUnicode函数的典型用法代码示例。如果您正苦于以下问题:TypeScript toUnicode函数的具体用法?TypeScript toUnicode怎么用?TypeScript toUnicode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: async

export default async (username: string, _host: string, option?: any): Promise<IUser> => {
	const usernameLower = username.toLowerCase();

	if (_host == null) {
		return await User.findOne({ usernameLower });
	}

	const hostAscii = toASCII(_host).toLowerCase();
	const host = toUnicode(hostAscii);

	if (config.host == host) {
		return await User.findOne({ usernameLower });
	}

	let user = await User.findOne({ usernameLower, host }, option);

	if (user === null) {
		const acctLower = `${usernameLower}@${hostAscii}`;

		const finger = await webFinger(acctLower);
		const self = finger.links.find(link => link.rel && link.rel.toLowerCase() === 'self');
		if (!self) {
			throw new Error('self link not found');
		}

		user = await createPerson(self.href);
	}

	return user;
};
开发者ID:ha-dai,项目名称:Misskey,代码行数:30,代码来源:resolve-user.ts


示例2: function

	serialize : function (components:MailtoComponents, options:URIOptions):URIComponents {
		const to = toArray(components.to);
		if (to) {
			for (let x = 0, xl = to.length; x < xl; ++x) {
				const toAddr = String(to[x]);
				const atIdx = toAddr.lastIndexOf("@");
				const localPart = (toAddr.slice(0, atIdx)).replace(PCT_ENCODED, decodeUnreserved).replace(PCT_ENCODED, toUpperCase).replace(NOT_LOCAL_PART, pctEncChar);
				let domain = toAddr.slice(atIdx + 1);

				//convert IDN via punycode
				try {
					domain = (!options.iri ? punycode.toASCII(unescapeComponent(domain, options).toLowerCase()) : punycode.toUnicode(domain));
				} catch (e) {
					components.error = components.error || "Email address's domain name can not be converted to " + (!options.iri ? "ASCII" : "Unicode") + " via punycode: " + e;
				}

				to[x] = localPart + "@" + domain;
			}

			components.path = to.join(",");
		}

		const headers = components.headers = components.headers || {};

		if (components.subject) headers["subject"] = components.subject;
		if (components.body) headers["body"] = components.body;

		const fields = [];
		for (const name in headers) {
			if (headers[name] !== O[name]) {
				fields.push(
					name.replace(PCT_ENCODED, decodeUnreserved).replace(PCT_ENCODED, toUpperCase).replace(NOT_HFNAME, pctEncChar) +
					"=" +
					headers[name].replace(PCT_ENCODED, decodeUnreserved).replace(PCT_ENCODED, toUpperCase).replace(NOT_HFVALUE, pctEncChar)
				);
			}
		}
		if (fields.length) {
			components.query = fields.join("&");
		}

		return components;
	}
开发者ID:Leo-G,项目名称:Flask-Scaffold,代码行数:43,代码来源:mailto.ts


示例3: createPerson

export async function createPerson(value: any, resolver?: Resolver): Promise<IUser> {
	if (resolver == null) resolver = new Resolver();

	const object = await resolver.resolve(value) as any;

	const err = validatePerson(object);

	if (err) {
		throw err;
	}

	const person: IPerson = object;

	log(`Creating the Person: ${person.id}`);

	const [followersCount = 0, followingCount = 0, notesCount = 0, finger] = await Promise.all([
		resolver.resolve(person.followers).then(
			resolved => isCollectionOrOrderedCollection(resolved) ? resolved.totalItems : undefined,
			() => undefined
		),
		resolver.resolve(person.following).then(
			resolved => isCollectionOrOrderedCollection(resolved) ? resolved.totalItems : undefined,
			() => undefined
		),
		resolver.resolve(person.outbox).then(
			resolved => isCollectionOrOrderedCollection(resolved) ? resolved.totalItems : undefined,
			() => undefined
		),
		webFinger(person.id)
	]);

	const host = toUnicode(finger.subject.replace(/^.*?@/, '')).toLowerCase();

	const isBot = object.type == 'Service';

	// Create user
	let user: IRemoteUser;
	try {
		user = await User.insert({
			avatarId: null,
			bannerId: null,
			createdAt: Date.parse(person.published) || null,
			description: htmlToMFM(person.summary),
			followersCount,
			followingCount,
			notesCount,
			name: person.name,
			isLocked: person.manuallyApprovesFollowers,
			username: person.preferredUsername,
			usernameLower: person.preferredUsername.toLowerCase(),
			host,
			publicKey: {
				id: person.publicKey.id,
				publicKeyPem: person.publicKey.publicKeyPem
			},
			inbox: person.inbox,
			sharedInbox: person.sharedInbox,
			endpoints: person.endpoints,
			uri: person.id,
			url: person.url,
			isBot
		}) as IRemoteUser;
	} catch (e) {
		// duplicate key error
		if (e.code === 11000) {
			throw new Error('already registered');
		}

		console.error(e);
		throw e;
	}

	//#region Increment users count
	Meta.update({}, {
		$inc: {
			'stats.usersCount': 1
		}
	}, { upsert: true });
	//#endregion

	//#region アイコンとヘッダー画像をフェッチ
	const [avatar, banner] = (await Promise.all<IDriveFile>([
		person.icon,
		person.image
	].map(img =>
		img == null
			? Promise.resolve(null)
			: resolveImage(user, img)
	)));

	const avatarId = avatar ? avatar._id : null;
	const bannerId = banner ? banner._id : null;
	const avatarUrl = avatar && avatar.metadata.url ? avatar.metadata.url : null;
	const bannerUrl = banner && banner.metadata.url ? banner.metadata.url : null;

	await User.update({ _id: user._id }, {
		$set: {
			avatarId,
			bannerId,
			avatarUrl,
//.........这里部分代码省略.........
开发者ID:ha-dai,项目名称:Misskey,代码行数:101,代码来源:person.ts


示例4: default

export default (host: string) => {
	return toUnicode(host).toLowerCase();
};
开发者ID:ha-dai,项目名称:Misskey,代码行数:3,代码来源:get-host-lower.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript puppeteer.launch函数代码示例发布时间:2022-05-25
下一篇:
TypeScript punycode.toASCII函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap