本文整理汇总了TypeScript中interweave.Parser类的典型用法代码示例。如果您正苦于以下问题:TypeScript Parser类的具体用法?TypeScript Parser怎么用?TypeScript Parser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Parser类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: describe
describe('matches all hashtags in a string', () => {
const parser = new Parser('', {}, [matcher]);
const createHashtag = (hashtag: string, key: number) =>
matcher.replaceWith(hashtag, {
children: hashtag,
hashtagName: hashtag.slice(1),
key,
});
VALID_HASHTAGS.forEach(hashtag => {
TOKEN_LOCATIONS.forEach((location, i) => {
it(`for: ${hashtag} - ${location}`, () => {
parser.keyIndex = -1; // Reset for easier testing
const tokenString = location.replace(/\{token\}/g, hashtag);
const actual = parser.applyMatchers(tokenString, parentConfig);
if (i === 0) {
expect(actual).toBe(createExpectedToken(hashtag, createHashtag, 0));
} else {
expect(actual).toEqual(createExpectedToken(hashtag, createHashtag, i));
}
});
});
});
});
示例2: describe
describe('matches all emails in a string', () => {
const parser = new Parser('', {}, [matcher]);
const createEmail = (email: string, key: number) => {
const parts = email.split('@');
return matcher.replaceWith(email, {
children: email,
emailParts: {
username: parts[0],
host: parts[1],
},
key,
});
};
VALID_EMAILS.forEach(email => {
TOKEN_LOCATIONS.forEach((location, i) => {
it(`for: ${email} - ${location}`, () => {
parser.keyIndex = -1; // Reset for easier testing
const tokenString = location.replace(/\{token\}/g, email);
const actual = parser.applyMatchers(tokenString, parentConfig);
if (i === 0) {
expect(actual).toBe(createExpectedToken(email, createEmail, 0));
} else {
expect(actual).toEqual(createExpectedToken(email, createEmail, i));
}
});
});
});
});
示例3: describe
describe('matches all urls in a string', () => {
const parser = new Parser('', {}, [matcher]);
const createUrl = (urlParams: URLParams, key: number) => {
const { url, ...params } = urlParams;
return matcher.replaceWith(url, {
children: url,
urlParts: {
host: 'example.com',
path: '',
query: '',
fragment: '',
...params,
scheme: params.scheme ? params.scheme.replace('://', '') : 'http',
auth: params.auth ? params.auth.slice(0, -1) : '',
port: params.port || '',
},
key,
});
};
VALID_URLS.forEach(urlParams => {
TOKEN_LOCATIONS.forEach((location, i) => {
it(`for: ${urlParams.url} - ${location}`, () => {
parser.keyIndex = -1; // Reset for easier testing
const tokenString = location.replace(/\{token\}/g, urlParams.url);
const actual = parser.applyMatchers(tokenString, parentConfig);
if (i === 0) {
expect(actual).toBe(createExpectedToken(urlParams, createUrl, 0));
} else {
expect(actual).toEqual(createExpectedToken(urlParams, createUrl, i));
}
});
});
});
});
示例4: it
it(`for: ${hashtag} - ${location}`, () => {
parser.keyIndex = -1; // Reset for easier testing
const tokenString = location.replace(/\{token\}/g, hashtag);
const actual = parser.applyMatchers(tokenString, parentConfig);
if (i === 0) {
expect(actual).toBe(createExpectedToken(hashtag, createHashtag, 0));
} else {
expect(actual).toEqual(createExpectedToken(hashtag, createHashtag, i));
}
});