當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript interweave.Parser類代碼示例

本文整理匯總了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));
          }
        });
      });
    });
  });
開發者ID:milesj,項目名稱:interweave,代碼行數:26,代碼來源:HashtagMatcher.test.ts

示例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));
          }
        });
      });
    });
  });
開發者ID:milesj,項目名稱:interweave,代碼行數:32,代碼來源:EmailMatcher.test.ts

示例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));
          }
        });
      });
    });
  });
開發者ID:milesj,項目名稱:interweave,代碼行數:38,代碼來源:UrlMatcher.test.ts

示例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));
          }
        });
開發者ID:milesj,項目名稱:interweave,代碼行數:12,代碼來源:HashtagMatcher.test.ts


注:本文中的interweave.Parser類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。