Détail du package

@pexxi/fold-to-ascii-ts

pexxi17.6kApache-2.05.1.1

A JavaScript port of the Apache Lucene ASCII Folding Filter that converts alphabetic, numeric, and symbolic Unicode characters which are not in the first 127 ASCII characters (the "Basic Latin" Unicode block) into a ASCII equivalents, if they exist.

ascii, sanitize, diacritics, unicode

readme

fold-to-ascii-ts

Build Status

A JavaScript port of the Apache Lucene ASCII Folding Filter that converts alphabetic, numeric, and symbolic Unicode characters which are not in the first 127 ASCII characters (the "Basic Latin" Unicode block) into their ASCII equivalents.

Documentation

Installation

Using npm: npm install --save @pexxi/fold-to-ascii-ts

Using yarn: yarn add @pexxi/fold-to-ascii-ts

Usage

There are two different modes of operation:

  1. Replace all known non-ASCII characters with appropriate replacements, replace the unknown ones with a fallback (foldReplacing).
  2. Replace all known non-ASCII characters with appropriate replacements, maintain the unknown ones (foldMaintaining).

The difference in output only manifests if the inputs contain characters without known replacements:

import ASCIIFolder from "fold-to-ascii-ts");

// Some Characters have no defined replacement.
// Specify a fixed replacement character (defaults to the empty string).
ASCIIFolder.foldReplacing("Lörem 🤧 ëripuît") === "Lorem  eripuit";
ASCIIFolder.foldReplacing("Lörem 🤧 ëripuît", "X") === "Lorem XX eripuit";

ASCIIFolder.foldMaintaining("Lörem 🤧 ëripuît") === "Lorem 🤧 eripuit";

Tests

npm test

Sources

This is a fork for adding TypeScript types, originally from https://github.com/mplatt/fold-to-ascii .

This is a straightforward port of the extensive switch/case statement found in http://svn.apache.org/repos/asf/lucene/java/tags/lucene_solr_4_5_1/lucene/analysis/common/src/java/org/apache/lucene/analysis/miscellaneous/ASCIIFoldingFilter.java

changelog

Changelog

All notable changes to this project will be documented in this file. Dates are displayed in UTC.

Generated by auto-changelog.

v5.1.1

27 May 2020

v5.1.0

27 May 2020

5.0.0

14 May 2019

  • removed deprecated method 47fc048

4.1.2

14 May 2019

  • re-introduced fold(str, replacement) for backwards compatibility 66968b7
  • when maintaining, no secondary parameter needs to be passed c5e009e

4.1.1

12 May 2019

4.1.0

12 May 2019

  • refactored folding functionality into two different functions 4cf57c7
  • upgrade to a modern version of QUnit 562ec81
  • removed overly verbose test description 292f565

4.0.0

28 July 2016

  • static access to the folding function 3f7f366
  • bump major version due to api update a313dbc
  • clarified es5 usage 7a94bda

3.0.0

7 May 2016

  • use native ES6 features #4
  • deleted bogus ide file 5868e92
  • removed benchmarking dev dependencies 7197f3e

2.0.2

26 April 2015

2.0.1

27 February 2015

  • changed default behaviour to ommit unmapped characters cfe0fcd
  • information on npm/bower availability 248284f
  • information on npm/bower availability 9504b1a

2.0.0

27 February 2015

  • refactored code to use module.exports to make it work with with npm b2f9c5f
  • first draft 3121079
  • complete tests 6d36c7d