@seismo/core
Version:
This is the package for the core library of Seismo, a JavaScript library for seismic data processing and visualization. It provides utilities for handling seismic data, including FDSN web services, waveform processing, and event handling. The library is d
241 lines (240 loc) • 10.6 kB
TypeScript
import { DateTime, Duration, Interval, FixedOffsetZone } from "luxon";
export declare const XML_MIME = "application/xml";
export declare const JSON_MIME = "application/json";
export declare const JSONAPI_MIME = "application/vnd.api+json";
export declare const SVG_MIME = "image/svg+xml";
export declare const TEXT_MIME = "text/plain";
export declare const BINARY_MIME = "application/octet-stream";
export declare const UTC_OPTIONS: {
zone: FixedOffsetZone;
};
export declare function hasArgs(value: unknown): boolean;
export declare function hasNoArgs(value: unknown): boolean;
export declare function isStringArg(value: unknown): value is string;
export declare function isNumArg(value: unknown): value is number;
export declare function isNonEmptyStringArg(value: unknown): value is string;
export declare function isObject(obj: unknown): obj is object;
export declare function isDef<Value>(value: Value | undefined | null): value is Value;
export declare function reErrorWithMessage(err: unknown, message: string): Error;
export interface StringDictionary {
[index: string]: unknown;
}
export declare function asStringDictionary(inobj: unknown): StringDictionary;
export declare function doStringGetterSetter(inobj: unknown, field: string, value?: string): unknown;
export declare function doBoolGetterSetter(inobj: unknown, field: string, value?: boolean): unknown;
export declare function doIntGetterSetter(inobj: unknown, field: string, value?: number): unknown;
export declare function doFloatGetterSetter(inobj: unknown, field: string, value?: number): StringDictionary;
export declare function doMomentGetterSetter(inobj: unknown, field: string, value?: DateTime | string): StringDictionary;
/**
* Converts entire DataView to a string as utf-8.
*
* @param dataView bytes to convert
* @returns the string
*/
export declare function dataViewToString(dataView: DataView): string;
/**
* Log a message to the console. Put here to limit lint console errors
* for the times we really do want to use console.log. Will also append a
* p tag to a div#debug if it exists.
*
* @param msg the message to log
*/
export declare function log(msg: string): void;
/**
* typescript-y check if Error.
*
* @param error object that might be an Error
* @returns true if Error object
*/
export declare function isError(error: unknown): error is Error;
/**
* typescript-y convert errors.
*
* @param maybeError obejct that might be an Error object
* @returns an Error object
*/
export declare function toError(maybeError: unknown): Error;
/**
* Log a warning message to the console. Put here to limit lint console errors
* for the times we really do want to use console.log. Will also append a
* p tag to a div#debug if it exists.
*
* @param msg the message to log
*/
export declare function warn(msg: string): void;
/**
* String representation of input. This is kind of dumb but makes
* flow happier.
*
* @param value any kind of thing that can be turned into a string
* @returns a string
*/
export declare function stringify(value: unknown): string;
export declare function isoToDateTime(val: string): DateTime;
/**
* Create a luxon Interval from a start and end.
*
* @param start start of the interval as iso string or DateTime
* @param end end of the interval as string or DateTime
* @returns the interval
*/
export declare function startEnd(start: string | DateTime, end: string | DateTime): Interval;
/**
* Create a luxon Interval from a start and a duration. If the duration is negative, the
* start time will become the end time. This differs from luxon Interval.after which
* will return an invalid Interval instead.
*
* @param start start of the interval as iso string or DateTime
* @param duration duration of the interval as iso string, number of seconds, or Duration
* @returns the interval
*/
export declare function startDuration(start: string | DateTime, duration: string | Duration | number): Interval;
/**
* Create a luxon Interval from a duration and a end. If the duration is negative, the
* end time will become the start time. This differs from luxon Interval.before which
* will return an invalid Interval instead.
*
* @param duration duration of the interval as iso string, number of seconds, or Duration
* @param end end of the interval as string or DateTime
* @returns the interval
*/
export declare function durationEnd(duration: string | Duration | number, end: string | DateTime): Interval;
/**
* Calculates offset of remote server versus local time. It is assumed that the
* argument was acquired as close in time to calling this as possible.
*
* @param serverTimeUTC now as reported by remote server
* @returns offset in seconds to now on local machine
*/
export declare function calcClockOffset(serverTimeUTC: DateTime): number;
export declare const WAY_FUTURE: DateTime;
/**
* converts the input value is a DateTime, throws Error if not
* a string, Date or DateTime. Zero length string or "now" return
* current time.
*
* @param d 'now', string time, Date, number of milliseconds since epoch, or DateTime
* @returns DateTime created from argument
*/
export declare function checkStringOrDate(d: string | Date | DateTime): DateTime;
/**
* Converts name and value into a html query parameter, with appending ampersand.
*
* @param name parameter name
* @param val parameter value
* @returns formated query parameter
*/
export declare function makeParam(name: string, val: unknown): string;
/**
* Converts name and value into a parameter line, with appending newline,
* for including in POST body.
*
* @param name parameter name
* @param val parameter value
* @returns formated query parameter
*/
export declare function makePostParam(name: string, val: unknown): string;
/**
* converts to ISO8601 but removes the trailing Z as FDSN web services
* do not allow that.
*
* @param date DateTime to convert to string
* @returns ISO8601 without timezone Z
*/
export declare function toIsoWoZ(date: DateTime): string;
/**
* Extracts a valid starting DateTime from interval.
* Throws Error if interval is not valid.
* @param interval luxon Interval
* @returns start DateTime
*/
export declare function validStartTime(interval: Interval): DateTime;
/**
* Extracts a valid ending DateTime from interval.
* Throws Error if interval is not valid.
* @param interval luxon Interval
* @returns end DateTime
*/
export declare function validEndTime(interval: Interval): DateTime;
/**
* Converts a luxon DateTime to a Javascript Date, checking for null,
* undefined and isValid first. Throws Error in that case.
*
* @param d luxon DateTime
* @returns Javascript Date
*/
export declare function toJSDate(d: DateTime | null | undefined): Date;
/**
* Check a Luxon DateTime, Interval or Duration for valid.
* Throws Error if not. THis is to avoid globally setting
* luxon's Settings.throwOnInvalid = true;
* but still throw/catch on invalid dates.
* @param d luxon object
* @param msg optional message to add to error
* @returns passed in object if valid
*/
export declare function checkLuxonValid(d: null | DateTime | Interval | Duration, msg?: string): DateTime<boolean> | Duration<boolean> | Interval<boolean>;
/**
* @returns the protocol, http: or https: for the document if possible.
* Note this includes the colon.
*/
export declare function checkProtocol(): string;
export interface FetchInitObject {
cache: string;
redirect: string;
mode: string;
referrer: string;
headers: Record<string, string>;
signal?: AbortSignal;
}
/**
* Create default fetch init object with the given mimeType. Sets
* no-cache, follow redirects, cors mode, referrer as seisplotjs and
* mimetype as a header. Note that redirect with POST may fail due to
* POST being changed to GET on a 301. Fetching with POST may wish
* to use redirect: "manual" to handle the 301 correctly by POSTing to
* the new URL.
*
*
* @param mimeType requested mime type
* @returns object with fetch configuration parameters
*/
export declare function defaultFetchInitObj(mimeType?: string): RequestInit;
export declare function cloneFetchInitObj(fetchInit: RequestInit): RequestInit;
export declare function errorFetch(_url: URL | RequestInfo, _init?: RequestInit | undefined): Promise<Response>;
export declare let default_fetch: null | ((url: URL | RequestInfo, init?: RequestInit | undefined) => Promise<Response>);
export declare function setDefaultFetch(fetcher: (url: URL | RequestInfo, init?: RequestInit | undefined) => Promise<Response>): void;
export declare function getFetch(): (url: URL | RequestInfo, init?: RequestInit | undefined) => Promise<Response>;
/**
* Does a fetch, but times out if it takes too long.
*
* @param url url to retrieve
* @param fetchInit fetch configuration, initialization
* @param timeoutSec maximum time to wait in seconds
* @param fetcher optional fetch to use instead of global fetch
* @returns promise to the result
* @throws Error if time out or other failure
*/
export declare function doFetchWithTimeout(url: string | URL, fetchInit?: RequestInit, timeoutSec?: number, fetcher?: (url: URL | RequestInfo, init?: RequestInit | undefined) => Promise<Response>): Promise<Response>;
/**
* Allows downloading of in memory data, as ArrayBuffer, to file as if
* the user clicked a download link.
*
* @param data ArrayBuffer to download
* @param filename default filename
* @param mimeType mimeType, default application/octet-stream
*/
export declare function downloadBlobAsFile(data: ArrayBuffer, filename: string, mimeType?: string): void;
/**
* Recursively calculates the mean of a slice of an array. This helps with
* very long seismograms to equally weight each sample point without overflowing.
*
* @param dataSlice slice of a seismogram
* @param totalPts number of points in the original seismogram
* @returns sum of slice data points divided by totalPts
*/
export declare function meanOfSlice(dataSlice: Int32Array | Float32Array | Float64Array, totalPts: number): number;
export declare const SVG_NS = "http://www.w3.org/2000/svg";
export declare const XHTML_NS = "http://www.w3.org/1999/xhtml";
export declare function createSVGElement(name: string): SVGElement;
export declare function updateVersionText(selector?: string): void;