mirror of
				https://github.com/gristlabs/grist-core.git
				synced 2025-06-13 20:53:59 +00:00 
			
		
		
		
	Use lodash to remove accents and ther diacritics
https://lodash.com/docs/4.17.15#deburr
This commit is contained in:
		
							parent
							
								
									0249b3d31b
								
							
						
					
					
						commit
						4003d2d7c6
					
				@ -7,9 +7,10 @@
 | 
			
		||||
 * "lush" would only match the "L" in "Lavender".
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
import {localeCompare, nativeCompare, removeDiacritics, sortedIndex} from 'app/common/gutil';
 | 
			
		||||
import {localeCompare, nativeCompare, sortedIndex} from 'app/common/gutil';
 | 
			
		||||
import {DomContents} from 'grainjs';
 | 
			
		||||
import escapeRegExp = require("lodash/escapeRegExp");
 | 
			
		||||
import deburr = require("lodash/deburr");
 | 
			
		||||
 | 
			
		||||
export interface ACItem {
 | 
			
		||||
  // This should be a trimmed lowercase version of the item's text. It may be an accessor.
 | 
			
		||||
@ -17,10 +18,11 @@ export interface ACItem {
 | 
			
		||||
  cleanText: string;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Returns a normalized, trimmed, lowercase version of a string, so that autocomplete is case-
 | 
			
		||||
// and accent-insensitive.
 | 
			
		||||
// Returns a trimmed, lowercase version of a string,
 | 
			
		||||
// from which accents and other diacritics have been removed,
 | 
			
		||||
// so that autocomplete is case- and accent-insensitive.
 | 
			
		||||
export function cleanText(text: string): string {
 | 
			
		||||
  return removeDiacritics(text).trim().toLowerCase();
 | 
			
		||||
  return deburr(text).trim().toLowerCase();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Regexp used to split text into words; includes nearly all punctuation. This means that
 | 
			
		||||
 | 
			
		||||
@ -55,11 +55,6 @@ export function capitalizeFirstWord(str: string): string {
 | 
			
		||||
  return str.replace(/\b[a-z]/i, c => c.toUpperCase());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Remove diacritics (accents and other signs).
 | 
			
		||||
export function removeDiacritics(text: string): string {
 | 
			
		||||
  return text.normalize("NFKD").replace(/[\u0300-\u036f]/g, "")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Returns whether the string n represents a valid number.
 | 
			
		||||
// http://stackoverflow.com/questions/18082/validate-numbers-in-javascript-isnumeric
 | 
			
		||||
export function isNumber(n: string): boolean {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user