Skip to content

Commit

Permalink
Using Frequency directly and getting rid of the getnlp hack
Browse files Browse the repository at this point in the history
This prevents problems with circular imports. I still get 14 warnings about circular imports in rollup (regardless of using the main commonjs plugin or the alternate one), but at least the emitted code seems to work fine in both now.
  • Loading branch information
Ole Martin Handeland committed Dec 14, 2020
1 parent d37d88a commit 0f19f34
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
13 changes: 7 additions & 6 deletions src/nlp/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ToText, { DateFormatter, GetText } from './totext'
import parseText from './parsetext'
import RRule from '../index'
import { Frequency } from '../types'
import ENGLISH, { Language } from './i18n'

/*!
Expand Down Expand Up @@ -108,12 +109,12 @@ const common = [
]

ToText.IMPLEMENTED = []
ToText.IMPLEMENTED[RRule.HOURLY] = common
ToText.IMPLEMENTED[RRule.MINUTELY] = common
ToText.IMPLEMENTED[RRule.DAILY] = ['byhour'].concat(common)
ToText.IMPLEMENTED[RRule.WEEKLY] = common
ToText.IMPLEMENTED[RRule.MONTHLY] = common
ToText.IMPLEMENTED[RRule.YEARLY] = ['byweekno', 'byyearday'].concat(common)
ToText.IMPLEMENTED[Frequency.HOURLY] = common
ToText.IMPLEMENTED[Frequency.MINUTELY] = common
ToText.IMPLEMENTED[Frequency.DAILY] = ['byhour'].concat(common)
ToText.IMPLEMENTED[Frequency.WEEKLY] = common
ToText.IMPLEMENTED[Frequency.MONTHLY] = common
ToText.IMPLEMENTED[Frequency.YEARLY] = ['byweekno', 'byyearday'].concat(common)

// =============================================================================
// Export
Expand Down
23 changes: 5 additions & 18 deletions src/rrule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import dateutil from './dateutil'
import IterResult, { IterArgs } from './iterresult'
import CallbackIterResult from './callbackiterresult'
import { Language } from './nlp/i18n'
import { Nlp } from './nlp/index'
import { fromText, parseText, toText, isFullyConvertible } from './nlp/index'
import { DateFormatter, GetText } from './nlp/totext'
import { ParsedOptions, Options, Frequency, QueryMethods, QueryMethodTypes, IterResultType } from './types'
import { parseOptions, initializeOptions } from './parseoptions'
Expand All @@ -13,19 +13,6 @@ import { Cache, CacheKeys } from './cache'
import { Weekday } from './weekday'
import { iter } from './iter/index'

interface GetNlp {
_nlp: Nlp
(): Nlp
}

const getnlp: GetNlp = function () {
// Lazy, runtime import to avoid circular refs.
if (!getnlp._nlp) {
getnlp._nlp = require('./nlp')
}
return getnlp._nlp
} as GetNlp

// =============================================================================
// RRule
// =============================================================================
Expand Down Expand Up @@ -114,11 +101,11 @@ export default class RRule implements QueryMethods {
}

static parseText (text: string, language?: Language) {
return getnlp().parseText(text, language)
return parseText(text, language)
}

static fromText (text: string, language?: Language) {
return getnlp().fromText(text, language)
return fromText(text, language)
}

static parseString = parseString
Expand Down Expand Up @@ -256,11 +243,11 @@ export default class RRule implements QueryMethods {
* to text.
*/
toText (gettext?: GetText, language?: Language, dateFormatter?: DateFormatter) {
return getnlp().toText(this, gettext, language, dateFormatter)
return toText(this, gettext, language, dateFormatter)
}

isFullyConvertibleToText () {
return getnlp().isFullyConvertible(this)
return isFullyConvertible(this)
}

/**
Expand Down

0 comments on commit 0f19f34

Please sign in to comment.