crash-js 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/crash-js +252 -0
- package/fs-utils +187 -0
- package/package.json +25 -0
package/crash-js
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
4
|
+
|
|
5
|
+
// ----------------------------------------------------------------------
|
|
6
|
+
// Copyright © 2024, 2025 Pellegrino Prevete
|
|
7
|
+
//
|
|
8
|
+
// All rights reserved
|
|
9
|
+
// ----------------------------------------------------------------------
|
|
10
|
+
//
|
|
11
|
+
// This program is free software: you can redistribute it and/or modify
|
|
12
|
+
// it under the terms of the GNU Affero General Public License as published by
|
|
13
|
+
// the Free Software Foundation, either version 3 of the License, or
|
|
14
|
+
// (at your option) any later version.
|
|
15
|
+
//
|
|
16
|
+
// This program is distributed in the hope that it will be useful,
|
|
17
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19
|
+
// GNU Affero General Public License for more details.
|
|
20
|
+
//
|
|
21
|
+
// You should have received a copy of the GNU Affero General Public License
|
|
22
|
+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
23
|
+
|
|
24
|
+
_argv =
|
|
25
|
+
process.argv
|
|
26
|
+
const
|
|
27
|
+
_fs_utils =
|
|
28
|
+
require(
|
|
29
|
+
"./fs-utils");
|
|
30
|
+
_basename =
|
|
31
|
+
_fs_utils._basename
|
|
32
|
+
|
|
33
|
+
function
|
|
34
|
+
_app_name_get() {
|
|
35
|
+
let
|
|
36
|
+
_filename;
|
|
37
|
+
_filename =
|
|
38
|
+
_basename(
|
|
39
|
+
__filename);
|
|
40
|
+
return _filename;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function
|
|
44
|
+
_msg_template(
|
|
45
|
+
_app_name,
|
|
46
|
+
_type) {
|
|
47
|
+
let
|
|
48
|
+
_out,
|
|
49
|
+
_partial,
|
|
50
|
+
_template;
|
|
51
|
+
_template =
|
|
52
|
+
"[{_app_name}] {_type}: {_msg}"
|
|
53
|
+
_partial =
|
|
54
|
+
_template.replaceAll(
|
|
55
|
+
"{_app_name}",
|
|
56
|
+
_app_name);
|
|
57
|
+
_out =
|
|
58
|
+
_partial.replaceAll(
|
|
59
|
+
"{_type}",
|
|
60
|
+
_type);
|
|
61
|
+
return _out;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function
|
|
65
|
+
_msg_info(
|
|
66
|
+
_msg) {
|
|
67
|
+
let
|
|
68
|
+
_out;
|
|
69
|
+
if ( quiet == "n" ) {
|
|
70
|
+
_template =
|
|
71
|
+
_msg_template(
|
|
72
|
+
app_name,
|
|
73
|
+
'INFO');
|
|
74
|
+
_out =
|
|
75
|
+
_template.replaceAll(
|
|
76
|
+
"{_msg}",
|
|
77
|
+
_msg);
|
|
78
|
+
console.log(
|
|
79
|
+
_out);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function
|
|
84
|
+
_msg_error(
|
|
85
|
+
_msg,
|
|
86
|
+
_exit) {
|
|
87
|
+
let
|
|
88
|
+
_template,
|
|
89
|
+
_out;
|
|
90
|
+
_template =
|
|
91
|
+
_msg_template(
|
|
92
|
+
app_name,
|
|
93
|
+
'ERROR');
|
|
94
|
+
_out =
|
|
95
|
+
_template.replaceAll(
|
|
96
|
+
"{_msg}",
|
|
97
|
+
_msg);
|
|
98
|
+
console.error(
|
|
99
|
+
_out);
|
|
100
|
+
if ( _exit == "1" ) {
|
|
101
|
+
process.exit(
|
|
102
|
+
1);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function
|
|
107
|
+
_msg_info_obj(
|
|
108
|
+
_name,
|
|
109
|
+
_obj) {
|
|
110
|
+
let
|
|
111
|
+
_template,
|
|
112
|
+
_partial,
|
|
113
|
+
_msg;
|
|
114
|
+
_template =
|
|
115
|
+
"{_name}: '{_obj}'"
|
|
116
|
+
_partial =
|
|
117
|
+
_template.replaceAll(
|
|
118
|
+
"{_name}",
|
|
119
|
+
_name);
|
|
120
|
+
_msg =
|
|
121
|
+
_partial.replaceAll(
|
|
122
|
+
"{_obj}",
|
|
123
|
+
_obj);
|
|
124
|
+
_msg_info(
|
|
125
|
+
_msg);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function
|
|
129
|
+
_error_display(
|
|
130
|
+
_error) {
|
|
131
|
+
let
|
|
132
|
+
_message;
|
|
133
|
+
if ( typeof(error) == "object" ) {
|
|
134
|
+
if ( 'error' in _error &&
|
|
135
|
+
_error[
|
|
136
|
+
'error'] != undefined &&
|
|
137
|
+
'message' in _error[
|
|
138
|
+
'error'] ) {
|
|
139
|
+
_message =
|
|
140
|
+
_error[
|
|
141
|
+
'error'][
|
|
142
|
+
'message'];
|
|
143
|
+
}
|
|
144
|
+
else if ( 'shortMessage' in _error ) {
|
|
145
|
+
_message =
|
|
146
|
+
_error[
|
|
147
|
+
'shortMessage'];
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
_message =
|
|
151
|
+
_error;
|
|
152
|
+
}
|
|
153
|
+
console.error(
|
|
154
|
+
_error);
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
_message =
|
|
158
|
+
_error;
|
|
159
|
+
console.error(
|
|
160
|
+
_error);
|
|
161
|
+
}
|
|
162
|
+
_msg_error(
|
|
163
|
+
_message,
|
|
164
|
+
0);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function
|
|
168
|
+
_cmdline_check(
|
|
169
|
+
_app_name) {
|
|
170
|
+
let
|
|
171
|
+
_program,
|
|
172
|
+
_program_name;
|
|
173
|
+
_program =
|
|
174
|
+
_argv[
|
|
175
|
+
1];
|
|
176
|
+
_program_name =
|
|
177
|
+
_basename(
|
|
178
|
+
_program);
|
|
179
|
+
if ( _program_name == _app_name ) {
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// This function is actually not a format
|
|
188
|
+
// print, but just how the author of this
|
|
189
|
+
// library calls a display function which
|
|
190
|
+
// does not add a goddamn newline at the
|
|
191
|
+
// end of the input text to display
|
|
192
|
+
function
|
|
193
|
+
_printf(
|
|
194
|
+
_text) {
|
|
195
|
+
process.stdout.write(
|
|
196
|
+
_text);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function
|
|
200
|
+
_echo(
|
|
201
|
+
_text) {
|
|
202
|
+
console.log(
|
|
203
|
+
_text);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function
|
|
207
|
+
_sleep(
|
|
208
|
+
_time) {
|
|
209
|
+
return new Promise(
|
|
210
|
+
resolve => setTimeout(
|
|
211
|
+
resolve,
|
|
212
|
+
_time));
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
module.exports = {
|
|
216
|
+
_app_name_get:
|
|
217
|
+
_app_name_get,
|
|
218
|
+
_basename:
|
|
219
|
+
_fs_utils._basename,
|
|
220
|
+
_cmdline_check:
|
|
221
|
+
_cmdline_check,
|
|
222
|
+
_dirname:
|
|
223
|
+
_fs_utils._dirname,
|
|
224
|
+
_echo:
|
|
225
|
+
_echo,
|
|
226
|
+
_error_display:
|
|
227
|
+
_error_display,
|
|
228
|
+
_ext_rm:
|
|
229
|
+
_fs_utils._ext_rm,
|
|
230
|
+
_file_exists:
|
|
231
|
+
_fs_utils._file_exists,
|
|
232
|
+
_file_read:
|
|
233
|
+
_fs_utils._file_read,
|
|
234
|
+
_file_write:
|
|
235
|
+
_fs_utils._file_write,
|
|
236
|
+
_json_display:
|
|
237
|
+
_fs_utils._json_display,
|
|
238
|
+
_json_read:
|
|
239
|
+
_fs_utils._json_read,
|
|
240
|
+
_msg_info:
|
|
241
|
+
_msg_info,
|
|
242
|
+
_msg_error:
|
|
243
|
+
_msg_error,
|
|
244
|
+
_msg_info_obj:
|
|
245
|
+
_msg_info_obj,
|
|
246
|
+
_path_join:
|
|
247
|
+
_fs_utils._path_join,
|
|
248
|
+
_printf:
|
|
249
|
+
_printf,
|
|
250
|
+
_sleep:
|
|
251
|
+
_sleep
|
|
252
|
+
};
|
package/fs-utils
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
4
|
+
|
|
5
|
+
// ----------------------------------------------------------------------
|
|
6
|
+
// Copyright © 2024, 2025 Pellegrino Prevete
|
|
7
|
+
//
|
|
8
|
+
// All rights reserved
|
|
9
|
+
// ----------------------------------------------------------------------
|
|
10
|
+
//
|
|
11
|
+
// This program is free software: you can redistribute it and/or modify
|
|
12
|
+
// it under the terms of the GNU Affero General Public License as published by
|
|
13
|
+
// the Free Software Foundation, either version 3 of the License, or
|
|
14
|
+
// (at your option) any later version.
|
|
15
|
+
//
|
|
16
|
+
// This program is distributed in the hope that it will be useful,
|
|
17
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19
|
+
// GNU Affero General Public License for more details.
|
|
20
|
+
//
|
|
21
|
+
// You should have received a copy of the GNU Affero General Public License
|
|
22
|
+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
23
|
+
|
|
24
|
+
const
|
|
25
|
+
_fs =
|
|
26
|
+
require(
|
|
27
|
+
"fs");
|
|
28
|
+
const
|
|
29
|
+
_path_module =
|
|
30
|
+
require(
|
|
31
|
+
'path');
|
|
32
|
+
_path_module_basename =
|
|
33
|
+
_path_module.basename;
|
|
34
|
+
_path_module_dirname =
|
|
35
|
+
_path_module.dirname;
|
|
36
|
+
_path_module_join =
|
|
37
|
+
_path_module.join;
|
|
38
|
+
_path_module_parse =
|
|
39
|
+
_path_module.parse;
|
|
40
|
+
const
|
|
41
|
+
_json_parse =
|
|
42
|
+
JSON.parse;
|
|
43
|
+
const
|
|
44
|
+
_json_display =
|
|
45
|
+
JSON.stringify;
|
|
46
|
+
|
|
47
|
+
function
|
|
48
|
+
_basename(
|
|
49
|
+
_file_path) {
|
|
50
|
+
let
|
|
51
|
+
_dir;
|
|
52
|
+
_dir =
|
|
53
|
+
_path_module_basename(
|
|
54
|
+
_file_path);
|
|
55
|
+
return _dir;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
function
|
|
60
|
+
_dirname(
|
|
61
|
+
_file_path) {
|
|
62
|
+
let
|
|
63
|
+
_dir;
|
|
64
|
+
_dir =
|
|
65
|
+
_path_module_dirname(
|
|
66
|
+
_file_path);
|
|
67
|
+
return _dir;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
function
|
|
72
|
+
_file_exists(
|
|
73
|
+
_path) {
|
|
74
|
+
let
|
|
75
|
+
_exists,
|
|
76
|
+
_return;
|
|
77
|
+
_return =
|
|
78
|
+
false;
|
|
79
|
+
_exists =
|
|
80
|
+
_fs.existsSync(
|
|
81
|
+
_path);
|
|
82
|
+
if (_exists) {
|
|
83
|
+
_return =
|
|
84
|
+
true;
|
|
85
|
+
}
|
|
86
|
+
return _return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
function
|
|
91
|
+
_file_read(
|
|
92
|
+
_path) {
|
|
93
|
+
let
|
|
94
|
+
_read_opts,
|
|
95
|
+
_return;
|
|
96
|
+
_read_opts =
|
|
97
|
+
{"encoding":
|
|
98
|
+
"utf8",
|
|
99
|
+
"flag":
|
|
100
|
+
'r'};
|
|
101
|
+
_return =
|
|
102
|
+
_fs.readFileSync(
|
|
103
|
+
_path,
|
|
104
|
+
_read_opts);
|
|
105
|
+
return _return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
function
|
|
110
|
+
_file_write(
|
|
111
|
+
_path,
|
|
112
|
+
_content) {
|
|
113
|
+
_fs.writeFileSync(
|
|
114
|
+
_path,
|
|
115
|
+
_content);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
function
|
|
120
|
+
_path_join(
|
|
121
|
+
_paths) {
|
|
122
|
+
let
|
|
123
|
+
_path;
|
|
124
|
+
_path =
|
|
125
|
+
_path_module_join.apply(
|
|
126
|
+
null,
|
|
127
|
+
_paths);
|
|
128
|
+
return _path;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
function
|
|
133
|
+
_ext_rm(
|
|
134
|
+
_path) {
|
|
135
|
+
let
|
|
136
|
+
_dir,
|
|
137
|
+
_name,
|
|
138
|
+
_paths;
|
|
139
|
+
_dir =
|
|
140
|
+
_path_module_parse(
|
|
141
|
+
_path).dir;
|
|
142
|
+
_name =
|
|
143
|
+
_path_module_parse(
|
|
144
|
+
_path).name;
|
|
145
|
+
_paths = [
|
|
146
|
+
_dir,
|
|
147
|
+
_name];
|
|
148
|
+
return _path_join(
|
|
149
|
+
_paths);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
function
|
|
154
|
+
_json_read(
|
|
155
|
+
_json_path) {
|
|
156
|
+
let
|
|
157
|
+
_json_str,
|
|
158
|
+
_json;
|
|
159
|
+
_json_str =
|
|
160
|
+
_file_read(
|
|
161
|
+
_json_path);
|
|
162
|
+
_json =
|
|
163
|
+
_json_parse(
|
|
164
|
+
_json_str);
|
|
165
|
+
return _json;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
module.exports = {
|
|
169
|
+
_basename:
|
|
170
|
+
_basename,
|
|
171
|
+
_dirname:
|
|
172
|
+
_dirname,
|
|
173
|
+
_ext_rm:
|
|
174
|
+
_ext_rm,
|
|
175
|
+
_file_exists:
|
|
176
|
+
_file_exists,
|
|
177
|
+
_file_read:
|
|
178
|
+
_file_read,
|
|
179
|
+
_file_write:
|
|
180
|
+
_file_write,
|
|
181
|
+
_path_join:
|
|
182
|
+
_path_join,
|
|
183
|
+
_json_display:
|
|
184
|
+
_json_display,
|
|
185
|
+
_json_read:
|
|
186
|
+
_json_read
|
|
187
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "crash-js",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Crash Javascript library.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"ur",
|
|
7
|
+
"themartiancompany",
|
|
8
|
+
"dogeos"
|
|
9
|
+
],
|
|
10
|
+
"homepage": "https://github.com/themartiancompany/crash-js",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/themartiancompany/crash-js/issues"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/themartiancompany/crash-js.git"
|
|
17
|
+
},
|
|
18
|
+
"license": "AGPL-3.0-or-later",
|
|
19
|
+
"author": "Pellegrino Prevete",
|
|
20
|
+
"type": "commonjs",
|
|
21
|
+
"main": "crash-js",
|
|
22
|
+
"scripts": {
|
|
23
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
24
|
+
}
|
|
25
|
+
}
|