source: node_modules/@swagger-api/apidom-reference/es/util/File.mjs@ d24f17c

main
Last change on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.1 KB
Line 
1import stampit from 'stampit';
2import { type } from 'ramda';
3import { isString } from 'ramda-adjunct';
4import * as url from "./url.mjs";
5/**
6 * This stamp represents a File object with url and data.
7 */
8
9const File = stampit({
10 props: {
11 uri: null,
12 mediaType: 'text/plain',
13 data: null,
14 parseResult: null
15 },
16 init({
17 uri = this.uri,
18 mediaType = this.mediaType,
19 data = this.data,
20 parseResult = this.parseResult
21 } = {}) {
22 this.uri = uri;
23 this.mediaType = mediaType;
24 this.data = data;
25 this.parseResult = parseResult;
26 },
27 methods: {
28 get extension() {
29 if (isString(this.uri)) {
30 return url.getExtension(this.uri);
31 }
32 return '';
33 },
34 toString() {
35 if (typeof this.data === 'string') {
36 return this.data;
37 }
38 if (this.data instanceof ArrayBuffer || ['ArrayBuffer'].includes(type(this.data)) || ArrayBuffer.isView(this.data)) {
39 const textDecoder = new TextDecoder('utf-8');
40 return textDecoder.decode(this.data);
41 }
42 return String(this.data);
43 }
44 }
45});
46export default File;
Note: See TracBrowser for help on using the repository browser.