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


TypeScript punycode.toASCII函数代码示例

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


在下文中一共展示了toASCII函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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

	parse : function (components:URIComponents, options:URIOptions):MailtoComponents {
		const mailtoComponents = components as MailtoComponents;
		const to = mailtoComponents.to = (mailtoComponents.path ? mailtoComponents.path.split(",") : []);
		mailtoComponents.path = undefined;

		if (mailtoComponents.query) {
			let unknownHeaders = false
			const headers:MailtoHeaders = {};
			const hfields = mailtoComponents.query.split("&");

			for (let x = 0, xl = hfields.length; x < xl; ++x) {
				const hfield = hfields[x].split("=");

				switch (hfield[0]) {
					case "to":
						const toAddrs = hfield[1].split(",");
						for (let x = 0, xl = toAddrs.length; x < xl; ++x) {
							to.push(toAddrs[x]);
						}
						break;
					case "subject":
						mailtoComponents.subject = unescapeComponent(hfield[1], options);
						break;
					case "body":
						mailtoComponents.body = unescapeComponent(hfield[1], options);
						break;
					default:
						unknownHeaders = true;
						headers[unescapeComponent(hfield[0], options)] = unescapeComponent(hfield[1], options);
						break;
				}
			}

			if (unknownHeaders) mailtoComponents.headers = headers;
		}

		mailtoComponents.query = undefined;

		for (let x = 0, xl = to.length; x < xl; ++x) {
			const addr = to[x].split("@");

			addr[0] = unescapeComponent(addr[0]);

			if (!options.unicodeSupport) {
				//convert Unicode IDN -> ASCII IDN
				try {
					addr[1] = punycode.toASCII(unescapeComponent(addr[1], options).toLowerCase());
				} catch (e) {
					mailtoComponents.error = mailtoComponents.error || "Email address's domain name can not be converted to ASCII via punycode: " + e;
				}
			} else {
				addr[1] = unescapeComponent(addr[1], options).toLowerCase();
			}

			to[x] = addr.join("@");
		}

		return mailtoComponents;
	},
开发者ID:2018-B-GR1-AplicacionesWeb,项目名称:Beltran-Venegas-Daniel-Alexander,代码行数:59,代码来源:mailto.ts


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