File

src/api/webApi/data/distributionFormatType.ts

Index

Properties
Methods

Properties

Static Readonly APP_COV_JSON
Type : string
Default value : 'covjson'
Static Readonly APP_EPOS_COV_JSON
Type : string
Default value : 'application/epos.covjson'
Static Readonly APP_EPOS_GEOJSON
Type : string
Default value : 'application/epos.geo+json'
Static Readonly APP_EPOS_GRAPH_COV_JSON
Type : string
Default value : 'application/epos.graph.covjson'
Static Readonly APP_EPOS_MAP_GEOJSON
Type : string
Default value : 'application/epos.map.geo+json'
Static Readonly APP_EPOS_TABLE_GEOJSON
Type : string
Default value : 'application/epos.table.geo+json'
Static Readonly APP_GEOJSON
Type : string
Default value : 'application/geo+json'
Static Readonly APP_OGC_WMS
Type : string
Default value : 'application/vnd.ogc.wms_xml'
Static Readonly APP_OGC_WMTS
Type : string
Default value : 'application/vnd.ogc.wmts_xml'
Private Static formats
Default value : new Map<string, unknown>()
Private Static graphableFormats
Type : []
Default value : [ DistributionFormatType.APP_COV_JSON, DistributionFormatType.APP_EPOS_GRAPH_COV_JSON, DistributionFormatType.APP_EPOS_COV_JSON, // ... ]
Private Static mappableFormats
Type : []
Default value : [ DistributionFormatType.APP_GEOJSON, DistributionFormatType.APP_EPOS_GEOJSON, DistributionFormatType.APP_OGC_WMS, DistributionFormatType.APP_OGC_WMTS, DistributionFormatType.APP_EPOS_MAP_GEOJSON, DistributionFormatType.APP_COV_JSON, DistributionFormatType.APP_EPOS_COV_JSON, // ... ]
Private Static nonDownloadableFormats
Type : []
Default value : [ DistributionFormatType.APP_OGC_WMS, DistributionFormatType.APP_OGC_WMTS ]
Private Static tabularableFormats
Type : []
Default value : [ DistributionFormatType.APP_EPOS_GEOJSON, DistributionFormatType.APP_EPOS_TABLE_GEOJSON, ]

Methods

Static getEposMime
getEposMime()
Returns : Mime
Static in
in(test: string, source: Array)
Parameters :
Name Type Optional
test string No
source Array<string> No
Returns : boolean
Static is
is(test: string, item: string)
Parameters :
Name Type Optional
test string No
item string No
Returns : boolean
Static isDownloadable
isDownloadable(format: string)
Parameters :
Name Type Optional
format string No
Returns : boolean
Static isGraphable
isGraphable(format: string)
Parameters :
Name Type Optional
format string No
Returns : boolean
Static isMappable
isMappable(format: string)
Parameters :
Name Type Optional
format string No
Returns : boolean
Static isTabularable
isTabularable(format: string)
Parameters :
Name Type Optional
format string No
Returns : boolean
import Mime from 'mime/Mime';

export class DistributionFormatType {

  // type WEB_SERVICE
  public static readonly APP_GEOJSON = 'application/geo+json';
  public static readonly APP_EPOS_GEOJSON = 'application/epos.geo+json';
  public static readonly APP_EPOS_TABLE_GEOJSON = 'application/epos.table.geo+json';
  public static readonly APP_EPOS_MAP_GEOJSON = 'application/epos.map.geo+json';
  public static readonly APP_OGC_WMS = 'application/vnd.ogc.wms_xml';
  public static readonly APP_OGC_WMTS = 'application/vnd.ogc.wmts_xml';
  public static readonly APP_COV_JSON = 'covjson';
  public static readonly APP_EPOS_COV_JSON = 'application/epos.covjson';
  public static readonly APP_EPOS_GRAPH_COV_JSON = 'application/epos.graph.covjson';

  // download formats so already data-search downloadable by way of type DOWNLOADABLE_FILE
  // public static readonly ZIP = 'zip';

  private static formats = new Map<string, unknown>();

  private static mappableFormats = [
    DistributionFormatType.APP_GEOJSON,
    DistributionFormatType.APP_EPOS_GEOJSON,
    DistributionFormatType.APP_OGC_WMS,
    DistributionFormatType.APP_OGC_WMTS,
    DistributionFormatType.APP_EPOS_MAP_GEOJSON,
    DistributionFormatType.APP_COV_JSON,
    DistributionFormatType.APP_EPOS_COV_JSON,
    // ...
  ];
  private static graphableFormats = [
    DistributionFormatType.APP_COV_JSON,
    DistributionFormatType.APP_EPOS_GRAPH_COV_JSON,
    DistributionFormatType.APP_EPOS_COV_JSON,
    // ...
  ];

  private static tabularableFormats = [
    DistributionFormatType.APP_EPOS_GEOJSON,
    DistributionFormatType.APP_EPOS_TABLE_GEOJSON,
  ];

  private static nonDownloadableFormats = [
    DistributionFormatType.APP_OGC_WMS,
    DistributionFormatType.APP_OGC_WMTS
  ];

  public static isMappable(format: string): boolean {
    return this.in(format, this.mappableFormats);
  }

  public static isGraphable(format: string): boolean {
    return this.in(format, this.graphableFormats);
  }

  public static isDownloadable(format: string): boolean {
    return !this.in(format, this.nonDownloadableFormats);
  }

  public static isTabularable(format: string): boolean {
    return this.in(format, this.tabularableFormats);
  }

  public static in(test: string, source: Array<string>): boolean {
    return (source.findIndex((item: string) => this.is(test, item)) > -1);
  }
  public static is(test: string, item: string): boolean {
    test = (test == null) ? '' : test;
    item = (item == null) ? '' : item;
    // starts with item string
    // escape regex special and / chars
    // TODO: review regex as eslint suggests a backslash isn't needed.  This may be correct, or may point to a different failure
    // eslint-disable-next-line no-useless-escape
    const regex = item.replace(/[.*+?^${}()|[\]\\\/]/g, '\\$&');
    return RegExp(`^${regex}`, 'i').test(test);
  }

  public static getEposMime(): Mime {
    const mimeMap = new Map<string, [string]>();
    // add types to file ext mappings here
    mimeMap.set(DistributionFormatType.APP_EPOS_GEOJSON, ['json']);

    // convert to mime objects
    const mimeObj = {};
    mimeMap.forEach((values, key) => {
      mimeObj[key] = values;
    });
    // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call
    return new Mime(mimeObj);
  }

}

results matching ""

    No results matching ""