main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Line | |
---|
1 | import stampit from 'stampit';
|
---|
2 | import { type } from 'ramda';
|
---|
3 | import { isString } from 'ramda-adjunct';
|
---|
4 | import * as url from "./url.mjs";
|
---|
5 | /**
|
---|
6 | * This stamp represents a File object with url and data.
|
---|
7 | */
|
---|
8 |
|
---|
9 | const 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 | });
|
---|
46 | export default File; |
---|
Note:
See
TracBrowser
for help on using the repository browser.