UNPKG

2.69 kBJavaScriptView Raw
1/*
2The MIT License (MIT)
3
4Copyright (c) 2016 CoderPuppy
5
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in all
14copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE.
23
24*/
25var _endianness;
26export function endianness() {
27 if (typeof _endianness === 'undefined') {
28 var a = new ArrayBuffer(2);
29 var b = new Uint8Array(a);
30 var c = new Uint16Array(a);
31 b[0] = 1;
32 b[1] = 2;
33 if (c[0] === 258) {
34 _endianness = 'BE';
35 } else if (c[0] === 513){
36 _endianness = 'LE';
37 } else {
38 throw new Error('unable to figure out endianess');
39 }
40 }
41 return _endianness;
42}
43
44export function hostname() {
45 if (typeof global.location !== 'undefined') {
46 return global.location.hostname
47 } else return '';
48}
49
50export function loadavg() {
51 return [];
52}
53
54export function uptime() {
55 return 0;
56}
57
58export function freemem() {
59 return Number.MAX_VALUE;
60}
61
62export function totalmem() {
63 return Number.MAX_VALUE;
64}
65
66export function cpus() {
67 return [];
68}
69
70export function type() {
71 return 'Browser';
72}
73
74export function release () {
75 if (typeof global.navigator !== 'undefined') {
76 return global.navigator.appVersion;
77 }
78 return '';
79}
80
81export function networkInterfaces(){}
82export function getNetworkInterfaces(){}
83
84export function arch() {
85 return 'javascript';
86}
87
88export function platform() {
89 return 'browser';
90}
91
92export function tmpDir() {
93 return '/tmp';
94}
95export var tmpdir = tmpDir;
96
97export var EOL = '\n';
98export default {
99 EOL: EOL,
100 tmpdir: tmpdir,
101 tmpDir: tmpDir,
102 networkInterfaces:networkInterfaces,
103 getNetworkInterfaces: getNetworkInterfaces,
104 release: release,
105 type: type,
106 cpus: cpus,
107 totalmem: totalmem,
108 freemem: freemem,
109 uptime: uptime,
110 loadavg: loadavg,
111 hostname: hostname,
112 endianness: endianness,
113}