本文整理匯總了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));
}
});