diff --git a/src/Shared/MorningstarSearchParams.ts b/src/Shared/MorningstarSearchParams.ts index 86c3894..3c53369 100644 --- a/src/Shared/MorningstarSearchParams.ts +++ b/src/Shared/MorningstarSearchParams.ts @@ -44,33 +44,33 @@ export class MorningstarSearchParams extends URLSearchParams { /** - * Sets `id` and `idType` based on given security options. + * Sets the parameter with the given date. * - * @param options - * Security options to set. + * @param name + * Parameter name to set. + * + * @param date + * JavaScript timestamp or date string. * * @return * The modified search parameters as reference. */ - public setSecurityOptions( - options: Array + public setDate( + name: ('endDate'|'startDate'), + date: (number|string) ): MorningstarSearchParams { - let id: string = this.get('id') || ''; - let idType: string = this.get('idType') || ''; - - options = (options instanceof Array ? options : [options]); - - for (const security of options) { - id = (id ? `${id}|${security.id}` : id); - idType = (idType ? `${idType}|${security.idType}` : idType); - } + const dateTime = ( + typeof date === 'number' ? + new Date(date) : + new Date(Date.parse(date)) + ); - this.set('id', id); - this.set('idType', idType); + this.set(name, dateTime.toISOString().substring(0, 10)); return this; } + /** * Sets `languageId` based on given localization options. * @@ -84,13 +84,40 @@ export class MorningstarSearchParams extends URLSearchParams { options: LocalizationOptions ): MorningstarSearchParams { - const { - country, - language - } = options; + this.set( + 'languageId', ( + options.language.toLowerCase() + + '-' + + options.country.toUpperCase() + ) + ); - const languageCultureCode = `${language.toLowerCase()}-${country.toUpperCase()}`; - this.set('languageId', languageCultureCode); + return this; + } + + + /** + * Sets `id` and `idType` based on given security options. + * + * @param options + * Security options to set. + * + * @return + * The modified search parameters as reference. + */ + public setSecurityOptions( + options: Array + ): MorningstarSearchParams { + let id: string = this.get('id') || ''; + let idType: string = this.get('idType') || ''; + + for (const security of options) { + id = (id ? `${id}|${security.id}` : security.id); + idType = (idType ? `${idType}|${security.idType}` : security.idType); + } + + this.set('id', id); + this.set('idType', idType); return this; } diff --git a/src/Shared/MorningstarURL.ts b/src/Shared/MorningstarURL.ts index 940cb72..0a58e0c 100644 --- a/src/Shared/MorningstarURL.ts +++ b/src/Shared/MorningstarURL.ts @@ -53,7 +53,7 @@ export class MorningstarURL extends URL { super(superURL); - this.searchParams = new MorningstarSearchParams(superURL.searchParams); + this._searchParams = new MorningstarSearchParams(superURL.searchParams); } @@ -64,7 +64,12 @@ export class MorningstarURL extends URL { * */ - public override searchParams: MorningstarSearchParams; + public _searchParams: MorningstarSearchParams; + + + public override get searchParams(): MorningstarSearchParams { + return this._searchParams; + } } diff --git a/src/Shared/index.ts b/src/Shared/index.ts index 2a75ba8..66a2f13 100644 --- a/src/Shared/index.ts +++ b/src/Shared/index.ts @@ -23,7 +23,9 @@ import MorningstarAPI from './MorningstarAPI'; -import MorningstarOAuth2 from './MorningstarAccess'; +import MorningstarError from './MorningstarError'; +import MorningstarAccess from './MorningstarAccess'; +import MorningstarRegion from './MorningstarRegion'; /* * @@ -48,5 +50,7 @@ export * from './MorningstarOptions'; export default { MorningstarAPI, - MorningstarOAuth2 + MorningstarError, + MorningstarAccess, + MorningstarRegion };