當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。