Skip to content

Commit

Permalink
rename fillerWords to preprocessors
Browse files Browse the repository at this point in the history
  • Loading branch information
kensnyder committed Sep 27, 2024
1 parent 7a65c26 commit f2f6d6e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/Format/Format.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import LocaleHelper from '../LocaleHelper/LocaleHelper';
import Parser from '../Parser/Parser';
import defaultLocale from '../data/defaultLocale';
import removeFillerWords from '../removeFillerWords/removeFillerWords';
import runPreprocessors from '../runPreprocessors/runPreprocessors';

export type HandlerResult = {
year?: number;
Expand Down Expand Up @@ -140,7 +140,7 @@ export default class Format {
* @returns {Object|null} Null if format can't handle this string, Object for result or error
*/
attempt(strDate: string, locale = defaultLocale): HandlerResult {
strDate = removeFillerWords(String(strDate), locale).trim();
strDate = runPreprocessors(String(strDate), locale).trim();
const matches = this.getMatches(strDate, locale);
if (matches) {
const dt = this.toDateTime(matches, locale);
Expand Down
4 changes: 2 additions & 2 deletions src/data/fillerWords.ts → src/data/preprocessors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const periodsInsteadOfColons = [
[/(\d{1,2})\.(\d{2})(\D|$)/, '$1:$2$3'],
];

const fillerWords = {
const preprocessors = {
zh: [
// in Chinese, "PM" comes before the digits
[/下午([\d:]+)/, '$1下午'],
Expand Down Expand Up @@ -57,4 +57,4 @@ const fillerWords = {
da: periodsInsteadOfColons,
};

export default fillerWords;
export default preprocessors;
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import fillerWords from '../data/fillerWords';
import preprocessors from '../data/preprocessors';

export default function removeFillerWords(dateString: string, locale: string) {
export default function runPreprocessors(dateString: string, locale: string) {
// dateString = dateString.replace(/\. /g, ' ');
const twoLetterLocale = locale.slice(0, 2).toLowerCase();
const replacers = fillerWords[twoLetterLocale];
const replacers = preprocessors[twoLetterLocale];
if (!replacers) {
return dateString;
}
Expand Down

0 comments on commit f2f6d6e

Please sign in to comment.