All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.es.File.mjs Maven / Gradle / Ivy

Go to download

Advanced algorithms for semantic ApiDOM manipulations like dereferencing or resolution.

There is a newer version: 1.0.0-alpha.9
Show newest version
import { type } from 'ramda';
import { isString } from 'ramda-adjunct';
import * as url from "./util/url.mjs";
/**
 * This class represents a File object with url and data.
 */
class File {
  uri;
  mediaType;
  data;
  parseResult;
  constructor({
    uri,
    mediaType = 'text/plain',
    data,
    parseResult
  }) {
    this.uri = uri;
    this.mediaType = mediaType;
    this.data = data;
    this.parseResult = parseResult;
  }
  get extension() {
    if (isString(this.uri)) {
      return url.getExtension(this.uri);
    }
    return '';
  }
  toString() {
    if (typeof this.data === 'string') {
      return this.data;
    }
    if (this.data instanceof ArrayBuffer || ['ArrayBuffer'].includes(type(this.data)) || ArrayBuffer.isView(this.data)) {
      const textDecoder = new TextDecoder('utf-8');
      return textDecoder.decode(this.data);
    }
    return String(this.data);
  }
}
export default File;




© 2015 - 2025 Weber Informatics LLC | Privacy Policy