当前位置: 首页>>代码示例>>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;未经允许,请勿转载。