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


TypeScript replaceall類代碼示例

本文整理匯總了TypeScript中replaceall的典型用法代碼示例。如果您正苦於以下問題:TypeScript replaceall類的具體用法?TypeScript replaceall怎麽用?TypeScript replaceall使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了replaceall類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: removeSpaces

export function removeSpaces(str: string): string {
  str = str.replace(/[\u200B-\u200D\uFEFF]/g, ''); // replace zero width space to space
  str = replaceall(String.fromCharCode(160), '', str); // Convert NO-BREAK SPACE to SPACE
  str = replaceall(String.fromCharCode(8201), '', str); // Convert THIN SPACE to SPACE
  str = replaceall(String.fromCharCode(8203), '', str); // Zero Width Space
  str = replaceall(' ', '', str); // Zero Width Space

  return str;
}
開發者ID:pierophp,項目名稱:pinyin,代碼行數:9,代碼來源:remove.spaces.ts

示例2: replaceall

    .filter(item => {
      item = replaceall(String.fromCharCode(160), '', item); // Convert NO-BREAK SPACE to SPACE
      item = replaceall(String.fromCharCode(8201), '', item); // Convert THIN SPACE to SPACE
      item = replaceall(String.fromCharCode(8203), '', item); // Zero Width Space
      item = replaceall(String.fromCharCode(8206), '', item); // Left-To-Right Mark
      item = replaceall(String.fromCharCode(8234), '', item); // Left-To-Right Embedding

      return item.trim();
    });
開發者ID:pierophp,項目名稱:pinyin,代碼行數:9,代碼來源:separate.words.ts

示例3: replaceall

 replaceIdeogramsToSpace.forEach(item => {
   audioTitleWithoutSpaces = replaceall(
     item,
     '',
     audioTitleWithoutSpaces,
   );
 });
開發者ID:pierophp,項目名稱:pinyin,代碼行數:7,代碼來源:audio.parser.ts

示例4: async

    await bluebird.mapSeries(items, async (item: any) => {
      let ideograms = ideogramsConverter.convertUtf16ToIdeograms(item.ideogram);
      ideograms = replaceall('%', '', ideograms);
      if (!ideograms) {
        return;
      }

      i += 1;

      profiler(`${i} - ${ideograms}`);

      const phrases = await PhraseRepository.findByLanguageAndRlike(
        language,
        ideograms,
      );
      if (phrases.length === 0) {
        return;
      }

      await bluebird.mapSeries(phrases, async (phrase: any) => {
        await knex('cjk_has_phrase').insert({
          cjk_id: item.id,
          phrase_id: phrase.id,
        });
      });
    });
開發者ID:pierophp,項目名稱:pinyin,代碼行數:26,代碼來源:cjk.repository.ts

示例5: saveFile

 public async saveFile(
   userId: number,
   filename: string,
   content: string,
 ): Promise<any> {
   const adapter = this.getAdapter();
   filename = replaceall('../', '', filename);
   await adapter.write(`files/${userId}/${filename}`, content, {});
 }
開發者ID:pierophp,項目名稱:pinyin,代碼行數:9,代碼來源:file.manager.ts

示例6: parse

  public async parse(
    item: ParseItemInterface,
    pdfParsedObjectPromise: Promise<any>,
  ): Promise<BlockInterface[] | undefined> {
    const text: string = item.chinese.text || '';
    const textSimplified: string = item.simplified
      ? item.simplified.text || ''
      : '';

    /**
     * If simplified and traditional paragraph does'n have the same size
     * don't use PDF for traditional
     */

    if (textSimplified) {
      const textSimplifiedVerification = replaceall(' ', '', textSimplified);
      const textVerification = replaceall(' ', '', text);

      if (textSimplifiedVerification.length !== textVerification.length) {
        return;
      }
    }

    const line = textSimplified ? textSimplified : text;

    const parsedResult = await this.pdfPinyin(
      pdfParsedObjectPromise!,
      [line],
      item,
    );

    if (!parsedResult) {
      return;
    }

    if (!textSimplified) {
      return parsedResult;
    }

    return restoreTraditional(text, parsedResult);
  }
開發者ID:pierophp,項目名稱:pinyin,代碼行數:41,代碼來源:with.pdf.parser.ts

示例7: segmentText

export function segmentText(line: string): string {
  let verifyText = line;

  replaceIdeogramsToSpace.forEach(item => {
    verifyText = replaceall(`${item} `, item, verifyText);
  });

  verifyText = verifyText.replace(/(\d+)/, '');
  verifyText = verifyText.trim();
  if (!verifyText) {
    verifyText = '';
  }

  const minimunWords = replaceall(' ', '', verifyText).length / 2.5;

  if (verifyText.split(' ').length < minimunWords) {
    return separateWords(line).join(' ');
  }

  return line;
}
開發者ID:pierophp,項目名稱:pinyin,代碼行數:21,代碼來源:segment.text.ts

示例8: parse

  public async parse(
    item: ParseItemInterface,
    parseSimplified: boolean,
  ): Promise<BlockInterface[] | undefined> {
    let text = item.chinese.text!;
    if (parseSimplified) {
      text = item.simplified!.text!;
    }

    if (parseSimplified) {
      let traditionalToCompare = item.chinese.text!;
      let simplifiedToCompare = item.simplified!.text!;

      traditionalToCompare = striptags(traditionalToCompare).replace(/ /g, '');

      simplifiedToCompare = striptags(
        simplifiedToCompare
          .replace(/<rt>(.*?)<\/rt>/g, '')
          .replace(/<ruby>/g, '')
          .replace(/<\/ruby>/g, ''),
      ).replace(/ /g, '');

      if (traditionalToCompare.length !== simplifiedToCompare.length) {
        console.info('RUBY - SIMPLIFIED AND TRADITIONAL NOT EQUALS');
        console.info('TRADITIONAL', traditionalToCompare);
        console.info('SIMPLIFIED', simplifiedToCompare);
        return;
      }
    }

    const blocks = text.split(/<ruby>|<\/ruby>/).filter(item => item.trim());

    let items: any[] = [];

    for (let block of blocks) {
      const rtMatch = block.match(/<rt>(.*)<\/rt>/);

      let pinyin = [];
      if (rtMatch) {
        block = replaceall(rtMatch[0], '', block);
        pinyin = separatePinyinInSyllables(striptags(rtMatch[1]));
      }

      block = removeSpaces(striptags(block));

      if (!block) {
        continue;
      }

      items.push({
        c: block.split(''),
        p: pinyin,
      });
    }

    items = backHtmlTags(items, text);

    items = fillBoldItalic(text, items);

    if (items.length > 0) {
      items[0].line = {
        type: item.chinese.type,
        pinyinSpaced: 1,
        pinyin_source: 'ruby',
      };
    }

    let bible;
    let response: any[] = [];
    for (let item of items) {
      item.c = item.c.join('').trim();
      item.p = item.p.join(String.fromCharCode(160));

      if (!item.c) {
        continue;
      }

      if (item.isBold) {
        item.isBold = 1;
      }

      if (item.isItalic) {
        item.isItalic = 1;
      }

      // @ts-ignore
      const tempBible = parseBible(item.tagsStart);
      if (tempBible) {
        bible = tempBible;
      }

      if (bible && !isChinese(item.c, true)) {
        item.b = bible;
        bible = null;
      }

      let indexOfFootnote = -1;

      if (item.tagsStart) {
        indexOfFootnote = item.tagsStart.indexOf('<footnote');
//.........這裏部分代碼省略.........
開發者ID:pierophp,項目名稱:pinyin,代碼行數:101,代碼來源:ruby.parser.ts


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