-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject.js
More file actions
185 lines (126 loc) · 3.48 KB
/
object.js
File metadata and controls
185 lines (126 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
==================================================================================
NOTE:
The use of global variables is not recommended, due to higher risk of errors.
The code below serves only demonstration purposes.
==================================================================================
*/
"use strict";
//============================
//Preparing class and instance
//============================
function Class()
{}
//This instance will be filled with new keys and values taken from the file keys.txt
var myInstance = new Class();
//=================
//A very bad Parser
//=================
function Parser(Content)
{
//Preparing array for parsing
var ContentArray = Content.split(";");
//MONITOR
//console.log(ContentArray);
//Parsing array and feeding myInstance and its prototype with keys and values
for(var key = 0; key < ContentArray.length; key++)
{
//Deleting new line sign and carriage return sign
ContentArray[key] = ContentArray[key].replace('\n','').replace('\r','');
/*
ContentArray[key] = identifier = first column
ContentArray[key+1] = key name = second column
ContentArray[key+2] = string value = third column
ContentArray[key+3] = true/false = fourth column (only active with instance)
*/
if(ContentArray[key] === "prototype")
{
//Key = Value
Class.prototype[ContentArray[key+1]] = ContentArray[key+2];
}
else if(ContentArray[key] === "instance")
{
//Key = Value
myInstance[ContentArray[key+1]] = ContentArray[key+2];
//Will not be accessible with Objec.keys()
if(ContentArray[key+3] === "false")
{
Object.defineProperty(myInstance,ContentArray[key+1],
{
enumerable: false
});
}
}
}
//MONITOR
//console.log(myInstance);
}
//========================
//Loading and reading file
//========================
function Read()
{
try
{
//From: <input id="input-file" type="file">
var myFile = document.getElementById('input-file').files[0];
//For Parsing loaded text content
var FileContent = "NONE";
//File Reader
const myReader = new FileReader();
myReader.readAsText(myFile);
//Handler for load event.It will be fired when reading process is done successfully
myReader.onload = function()
{
//MONITOR
//console.log(myReader.result);
//Contains keys.txt content
FileContent = myReader.result;
//Parse the content and fill the instance with keys and values
Parser(FileContent);
}
}
catch
{
alert("Please, select the file keys.txt first!");
}
}
//========
//Show All
//========
function ShowAll()
{
var numberOfAttribuntes = document.getElementById('numOfAttr');
var information = document.getElementById('interface');
//Reseting interface content
information.innerHTML = "";
/*
ATTENTION: Use of Object.getOwnPropertyNames()
*/
information.innerHTML = Object.getOwnPropertyNames(myInstance);
//MONITOR
//console.table(Object.getOwnPropertyNames(myInstance));
}
//===========
//Show Partly
//===========
function ShowPartly()
{
var numberOfAttribuntes = document.getElementById('numOfAttr');
var information = document.getElementById('interface');
//Reseting interface content
information.innerHTML = "";
/*
ATTENTION: Use of Object.keys()
*/
information.innerHTML = Object.keys(myInstance);
//MONITOR
//console.table(Object.keys(myInstance));
}
//============
//Refresh Page
//============
function Refresh()
{
location.reload();
}