@zappinginc/zm2 6.0.14
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/.claude/settings.local.json +8 -0
- package/.gitattributes +4 -0
- package/.mocharc.js +14 -0
- package/CHANGELOG.md +2416 -0
- package/CLAUDE.md +84 -0
- package/CONTRIBUTING.md +124 -0
- package/GNU-AGPL-3.0.txt +665 -0
- package/LICENSE +1 -0
- package/README.md +248 -0
- package/bin/zm2 +3 -0
- package/bin/zm2-dev +3 -0
- package/bin/zm2-docker +3 -0
- package/bin/zm2-runtime +3 -0
- package/bin/zm2-windows +3 -0
- package/bin/zm2.ps1 +3 -0
- package/bun.lock +421 -0
- package/constants.js +114 -0
- package/index.js +13 -0
- package/lib/API/Configuration.js +212 -0
- package/lib/API/Containerizer.js +335 -0
- package/lib/API/Dashboard.js +459 -0
- package/lib/API/Deploy.js +117 -0
- package/lib/API/Extra.js +775 -0
- package/lib/API/ExtraMgmt/Docker.js +30 -0
- package/lib/API/Log.js +315 -0
- package/lib/API/LogManagement.js +371 -0
- package/lib/API/Modules/LOCAL.js +122 -0
- package/lib/API/Modules/Modularizer.js +148 -0
- package/lib/API/Modules/NPM.js +445 -0
- package/lib/API/Modules/TAR.js +362 -0
- package/lib/API/Modules/flagExt.js +46 -0
- package/lib/API/Modules/index.js +120 -0
- package/lib/API/Monit.js +247 -0
- package/lib/API/Serve.js +343 -0
- package/lib/API/Startup.js +629 -0
- package/lib/API/UX/helpers.js +213 -0
- package/lib/API/UX/index.js +9 -0
- package/lib/API/UX/pm2-describe.js +193 -0
- package/lib/API/UX/pm2-ls-minimal.js +31 -0
- package/lib/API/UX/pm2-ls.js +483 -0
- package/lib/API/Version.js +382 -0
- package/lib/API/interpreter.json +12 -0
- package/lib/API/pm2-plus/PM2IO.js +372 -0
- package/lib/API/pm2-plus/auth-strategies/CliAuth.js +288 -0
- package/lib/API/pm2-plus/auth-strategies/WebAuth.js +187 -0
- package/lib/API/pm2-plus/helpers.js +97 -0
- package/lib/API/pm2-plus/link.js +126 -0
- package/lib/API/pm2-plus/pres/motd +16 -0
- package/lib/API/pm2-plus/pres/motd.update +26 -0
- package/lib/API/pm2-plus/pres/welcome +28 -0
- package/lib/API/pm2-plus/process-selector.js +52 -0
- package/lib/API/schema.json +379 -0
- package/lib/API.js +1931 -0
- package/lib/Client.js +776 -0
- package/lib/Common.js +911 -0
- package/lib/Configuration.js +304 -0
- package/lib/Daemon.js +456 -0
- package/lib/Event.js +37 -0
- package/lib/God/ActionMethods.js +909 -0
- package/lib/God/ClusterMode.js +97 -0
- package/lib/God/ForkMode.js +297 -0
- package/lib/God/Methods.js +265 -0
- package/lib/God/Reload.js +240 -0
- package/lib/God.js +632 -0
- package/lib/HttpInterface.js +76 -0
- package/lib/ProcessContainer.js +305 -0
- package/lib/ProcessContainerBun.js +360 -0
- package/lib/ProcessContainerFork.js +42 -0
- package/lib/ProcessContainerForkBun.js +33 -0
- package/lib/ProcessUtils.js +55 -0
- package/lib/TreeKill.js +118 -0
- package/lib/Utility.js +430 -0
- package/lib/VersionCheck.js +46 -0
- package/lib/Watcher.js +117 -0
- package/lib/Worker.js +169 -0
- package/lib/binaries/CLI.js +1041 -0
- package/lib/binaries/DevCLI.js +183 -0
- package/lib/binaries/Runtime.js +101 -0
- package/lib/binaries/Runtime4Docker.js +192 -0
- package/lib/completion.js +229 -0
- package/lib/completion.sh +40 -0
- package/lib/motd +36 -0
- package/lib/templates/Dockerfiles/Dockerfile-java.tpl +7 -0
- package/lib/templates/Dockerfiles/Dockerfile-nodejs.tpl +8 -0
- package/lib/templates/Dockerfiles/Dockerfile-ruby.tpl +7 -0
- package/lib/templates/ecosystem-es.tpl +24 -0
- package/lib/templates/ecosystem-simple-es.tpl +8 -0
- package/lib/templates/ecosystem-simple.tpl +6 -0
- package/lib/templates/ecosystem.tpl +22 -0
- package/lib/templates/init-scripts/launchd.tpl +35 -0
- package/lib/templates/init-scripts/openrc.tpl +52 -0
- package/lib/templates/init-scripts/pm2-init-amazon.sh +86 -0
- package/lib/templates/init-scripts/rcd-openbsd.tpl +41 -0
- package/lib/templates/init-scripts/rcd.tpl +44 -0
- package/lib/templates/init-scripts/smf.tpl +43 -0
- package/lib/templates/init-scripts/systemd-online.tpl +22 -0
- package/lib/templates/init-scripts/systemd.tpl +22 -0
- package/lib/templates/init-scripts/upstart.tpl +103 -0
- package/lib/templates/logrotate.d/pm2 +10 -0
- package/lib/templates/sample-apps/http-server/README.md +14 -0
- package/lib/templates/sample-apps/http-server/api.js +9 -0
- package/lib/templates/sample-apps/http-server/ecosystem.config.js +14 -0
- package/lib/templates/sample-apps/http-server/package.json +11 -0
- package/lib/templates/sample-apps/pm2-plus-metrics-actions/README.md +45 -0
- package/lib/templates/sample-apps/pm2-plus-metrics-actions/custom-metrics.js +66 -0
- package/lib/templates/sample-apps/pm2-plus-metrics-actions/ecosystem.config.js +12 -0
- package/lib/templates/sample-apps/pm2-plus-metrics-actions/package.json +11 -0
- package/lib/templates/sample-apps/python-app/README.md +4 -0
- package/lib/templates/sample-apps/python-app/echo.py +7 -0
- package/lib/templates/sample-apps/python-app/ecosystem.config.js +12 -0
- package/lib/templates/sample-apps/python-app/package.json +11 -0
- package/lib/tools/Config.js +248 -0
- package/lib/tools/IsAbsolute.js +20 -0
- package/lib/tools/copydirSync.js +101 -0
- package/lib/tools/deleteFolderRecursive.js +19 -0
- package/lib/tools/find-package-json.js +74 -0
- package/lib/tools/fmt.js +72 -0
- package/lib/tools/isbinaryfile.js +94 -0
- package/lib/tools/json5.js +752 -0
- package/lib/tools/open.js +63 -0
- package/lib/tools/passwd.js +58 -0
- package/lib/tools/promise.min.js +1 -0
- package/lib/tools/sexec.js +55 -0
- package/lib/tools/treeify.js +113 -0
- package/lib/tools/which.js +120 -0
- package/lib/tools/xdg-open +861 -0
- package/package.json +219 -0
- package/paths.js +93 -0
- package/pm2 +11 -0
- package/preinstall.js +24 -0
- package/run.sh +9 -0
- package/types/index.d.ts +722 -0
- package/types/tsconfig.json +14 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
|
|
2
|
+
const util = require('util')
|
|
3
|
+
const spawn = require('child_process').spawn
|
|
4
|
+
const DockerMgmt = {}
|
|
5
|
+
|
|
6
|
+
module.exports = DockerMgmt
|
|
7
|
+
|
|
8
|
+
function execDocker(cmd, cb) {
|
|
9
|
+
var i = spawn('docker', cmd, {
|
|
10
|
+
stdio : 'inherit',
|
|
11
|
+
env: process.env,
|
|
12
|
+
shell : true
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
i.on('close', cb)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
DockerMgmt.processCommand = function(PM2, start_id, select_id, action, cb) {
|
|
19
|
+
PM2.Client.executeRemote('getSystemData', {}, (err, sys_infos) => {
|
|
20
|
+
if (sys_infos.containers && sys_infos.containers.length == 0)
|
|
21
|
+
return cb(new Error(`Process ${select_id} not found`))
|
|
22
|
+
var container = sys_infos.containers[select_id - start_id - 1]
|
|
23
|
+
if (action == 'stopProcessId')
|
|
24
|
+
execDocker(['stop', container.id], cb)
|
|
25
|
+
if (action == 'deleteProcessId')
|
|
26
|
+
execDocker(['rm', container.id], cb)
|
|
27
|
+
if (action == 'restartProcessId')
|
|
28
|
+
execDocker(['restart', container.id], cb)
|
|
29
|
+
})
|
|
30
|
+
}
|
package/lib/API/Log.js
ADDED
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2013-2022 the PM2 project authors. All rights reserved.
|
|
3
|
+
* Use of this source code is governed by a license that
|
|
4
|
+
* can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
var fs = require('fs'),
|
|
7
|
+
util = require('util'),
|
|
8
|
+
chalk = require('ansis'),
|
|
9
|
+
forEachLimit = require('async/forEachLimit'),
|
|
10
|
+
dayjs = require('dayjs');
|
|
11
|
+
|
|
12
|
+
var Log = module.exports = {};
|
|
13
|
+
|
|
14
|
+
var DEFAULT_PADDING = ' ';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Tail logs from file stream.
|
|
18
|
+
* @param {Object} apps_list
|
|
19
|
+
* @param {Number} lines
|
|
20
|
+
* @param {Boolean} raw
|
|
21
|
+
* @param {Function} callback
|
|
22
|
+
* @return
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
Log.tail = function(apps_list, lines, raw, callback) {
|
|
26
|
+
var that = this;
|
|
27
|
+
|
|
28
|
+
if (lines === 0 || apps_list.length === 0)
|
|
29
|
+
return callback && callback();
|
|
30
|
+
|
|
31
|
+
var count = 0;
|
|
32
|
+
|
|
33
|
+
var getLastLines = function (filename, lines, callback) {
|
|
34
|
+
var chunk = '';
|
|
35
|
+
var size = Math.max(0, fs.statSync(filename).size - (lines * 200));
|
|
36
|
+
|
|
37
|
+
var fd = fs.createReadStream(filename, {start : size});
|
|
38
|
+
fd.on('data', function(data) { chunk += data.toString(); });
|
|
39
|
+
fd.on('end', function() {
|
|
40
|
+
chunk = chunk.split('\n').slice(-(lines+1));
|
|
41
|
+
chunk.pop();
|
|
42
|
+
callback(chunk);
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
apps_list.sort(function(a, b) {
|
|
47
|
+
return (fs.existsSync(a.path) ? fs.statSync(a.path).mtime.valueOf() : 0) -
|
|
48
|
+
(fs.existsSync(b.path) ? fs.statSync(b.path).mtime.valueOf() : 0);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
forEachLimit(apps_list, 1, function(app, next) {
|
|
52
|
+
if (!fs.existsSync(app.path || ''))
|
|
53
|
+
return next();
|
|
54
|
+
|
|
55
|
+
getLastLines(app.path, lines, function(output) {
|
|
56
|
+
console.log(chalk.gray('%s last %d lines:'), app.path, lines);
|
|
57
|
+
output.forEach(function(out) {
|
|
58
|
+
if (raw)
|
|
59
|
+
return app.type === 'err' ? console.error(out) : console.log(out);
|
|
60
|
+
if (app.type === 'out')
|
|
61
|
+
process.stdout.write(chalk.green(pad(DEFAULT_PADDING, app.app_name) + ' | '));
|
|
62
|
+
else if (app.type === 'err')
|
|
63
|
+
process.stdout.write(chalk.red(pad(DEFAULT_PADDING, app.app_name) + ' | '));
|
|
64
|
+
else
|
|
65
|
+
process.stdout.write(chalk.blue(pad(DEFAULT_PADDING, 'PM2') + ' | '));
|
|
66
|
+
console.log(out);
|
|
67
|
+
});
|
|
68
|
+
if (output.length)
|
|
69
|
+
process.stdout.write('\n');
|
|
70
|
+
next();
|
|
71
|
+
});
|
|
72
|
+
}, function() {
|
|
73
|
+
callback && callback();
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Stream logs in realtime from the bus eventemitter.
|
|
79
|
+
* @param {String} id
|
|
80
|
+
* @param {Boolean} raw
|
|
81
|
+
* @return
|
|
82
|
+
*/
|
|
83
|
+
|
|
84
|
+
Log.stream = function(Client, id, raw, timestamp, exclusive, highlight) {
|
|
85
|
+
var that = this;
|
|
86
|
+
|
|
87
|
+
Client.launchBus(function(err, bus, socket) {
|
|
88
|
+
|
|
89
|
+
socket.on('reconnect attempt', function() {
|
|
90
|
+
if (global._auto_exit === true) {
|
|
91
|
+
if (timestamp)
|
|
92
|
+
process.stdout.write(chalk['dim'](chalk.gray(dayjs().format(timestamp) + ' ')));
|
|
93
|
+
process.stdout.write(chalk.blue(pad(DEFAULT_PADDING, 'PM2') + ' | ') + '[[[ Target PM2 killed. ]]]');
|
|
94
|
+
process.exit(0);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
var min_padding = 3
|
|
99
|
+
|
|
100
|
+
bus.on('log:*', function(type, packet) {
|
|
101
|
+
var isMatchingProcess = id === 'all'
|
|
102
|
+
|| packet.process.name == id
|
|
103
|
+
|| packet.process.pm_id == id
|
|
104
|
+
|| packet.process.namespace == id;
|
|
105
|
+
|
|
106
|
+
if (!isMatchingProcess)
|
|
107
|
+
return;
|
|
108
|
+
|
|
109
|
+
if ((type === 'out' && exclusive === 'err')
|
|
110
|
+
|| (type === 'err' && exclusive === 'out')
|
|
111
|
+
|| (type === 'PM2' && exclusive !== false))
|
|
112
|
+
return;
|
|
113
|
+
|
|
114
|
+
var lines;
|
|
115
|
+
|
|
116
|
+
if (typeof(packet.data) === 'string')
|
|
117
|
+
lines = (packet.data || '').split('\n');
|
|
118
|
+
else
|
|
119
|
+
return;
|
|
120
|
+
|
|
121
|
+
lines.forEach(function(line) {
|
|
122
|
+
if (!line || line.length === 0) return;
|
|
123
|
+
|
|
124
|
+
if (raw)
|
|
125
|
+
return type === 'err' ? process.stderr.write(util.format(line) + '\n') : process.stdout.write(util.format(line) + '\n');
|
|
126
|
+
|
|
127
|
+
if (timestamp)
|
|
128
|
+
process.stdout.write(chalk['dim'](chalk.gray(dayjs().format(timestamp) + ' ')));
|
|
129
|
+
|
|
130
|
+
var name = packet.process.pm_id + '|' + packet.process.name;
|
|
131
|
+
|
|
132
|
+
if (name.length > min_padding)
|
|
133
|
+
min_padding = name.length + 1
|
|
134
|
+
|
|
135
|
+
if (type === 'out')
|
|
136
|
+
process.stdout.write(chalk.green(pad(' '.repeat(min_padding), name) + ' | '));
|
|
137
|
+
else if (type === 'err')
|
|
138
|
+
process.stdout.write(chalk.red(pad(' '.repeat(min_padding), name) + ' | '));
|
|
139
|
+
else if (!raw && (id === 'all' || id === 'PM2'))
|
|
140
|
+
process.stdout.write(chalk.blue(pad(' '.repeat(min_padding), 'PM2') + ' | '));
|
|
141
|
+
if (highlight)
|
|
142
|
+
process.stdout.write(util.format(line).replace(highlight, chalk.bgBlackBright(highlight)) + '\n');
|
|
143
|
+
else
|
|
144
|
+
process.stdout.write(util.format(line)+ '\n');
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
Log.devStream = function(Client, id, raw, timestamp, exclusive) {
|
|
151
|
+
var that = this;
|
|
152
|
+
|
|
153
|
+
Client.launchBus(function(err, bus) {
|
|
154
|
+
|
|
155
|
+
setTimeout(function() {
|
|
156
|
+
bus.on('process:event', function(packet) {
|
|
157
|
+
if (packet.event == 'online')
|
|
158
|
+
console.log(chalk.green('[rundev] App %s restarted'), packet.process.name);
|
|
159
|
+
});
|
|
160
|
+
}, 1000);
|
|
161
|
+
|
|
162
|
+
var min_padding = 3
|
|
163
|
+
|
|
164
|
+
bus.on('log:*', function(type, packet) {
|
|
165
|
+
if (id !== 'all'
|
|
166
|
+
&& packet.process.name != id
|
|
167
|
+
&& packet.process.pm_id != id)
|
|
168
|
+
return;
|
|
169
|
+
|
|
170
|
+
if ((type === 'out' && exclusive === 'err')
|
|
171
|
+
|| (type === 'err' && exclusive === 'out')
|
|
172
|
+
|| (type === 'PM2' && exclusive !== false))
|
|
173
|
+
return;
|
|
174
|
+
|
|
175
|
+
if (type === 'PM2')
|
|
176
|
+
return;
|
|
177
|
+
|
|
178
|
+
var name = packet.process.pm_id + '|' + packet.process.name;
|
|
179
|
+
|
|
180
|
+
var lines;
|
|
181
|
+
|
|
182
|
+
if (typeof(packet.data) === 'string')
|
|
183
|
+
lines = (packet.data || '').split('\n');
|
|
184
|
+
else
|
|
185
|
+
return;
|
|
186
|
+
|
|
187
|
+
lines.forEach(function(line) {
|
|
188
|
+
if (!line || line.length === 0) return;
|
|
189
|
+
|
|
190
|
+
if (raw)
|
|
191
|
+
return process.stdout.write(util.format(line) + '\n');
|
|
192
|
+
|
|
193
|
+
if (timestamp)
|
|
194
|
+
process.stdout.write(chalk['dim'](chalk.gray(dayjs().format(timestamp) + ' ')));
|
|
195
|
+
|
|
196
|
+
var name = packet.process.name + '-' + packet.process.pm_id;
|
|
197
|
+
|
|
198
|
+
if (name.length > min_padding)
|
|
199
|
+
min_padding = name.length + 1
|
|
200
|
+
|
|
201
|
+
if (type === 'out')
|
|
202
|
+
process.stdout.write(chalk.green(pad(' '.repeat(min_padding), name) + ' | '));
|
|
203
|
+
else if (type === 'err')
|
|
204
|
+
process.stdout.write(chalk.red(pad(' '.repeat(min_padding), name) + ' | '));
|
|
205
|
+
else if (!raw && (id === 'all' || id === 'PM2'))
|
|
206
|
+
process.stdout.write(chalk.blue(pad(' '.repeat(min_padding), 'PM2') + ' | '));
|
|
207
|
+
process.stdout.write(util.format(line) + '\n');
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
Log.jsonStream = function(Client, id) {
|
|
214
|
+
var that = this;
|
|
215
|
+
|
|
216
|
+
Client.launchBus(function(err, bus) {
|
|
217
|
+
if (err) console.error(err);
|
|
218
|
+
|
|
219
|
+
bus.on('process:event', function(packet) {
|
|
220
|
+
process.stdout.write(JSON.stringify({
|
|
221
|
+
timestamp : dayjs(packet.at),
|
|
222
|
+
type : 'process_event',
|
|
223
|
+
status : packet.event,
|
|
224
|
+
app_name : packet.process.name
|
|
225
|
+
}));
|
|
226
|
+
process.stdout.write('\n');
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
bus.on('log:*', function(type, packet) {
|
|
230
|
+
if (id !== 'all'
|
|
231
|
+
&& packet.process.name != id
|
|
232
|
+
&& packet.process.pm_id != id)
|
|
233
|
+
return;
|
|
234
|
+
|
|
235
|
+
if (type === 'PM2')
|
|
236
|
+
return;
|
|
237
|
+
|
|
238
|
+
if (typeof(packet.data) == 'string')
|
|
239
|
+
packet.data = packet.data.replace(/(\r\n|\n|\r)/gm,'');
|
|
240
|
+
|
|
241
|
+
process.stdout.write(JSON.stringify({
|
|
242
|
+
message : packet.data,
|
|
243
|
+
timestamp : dayjs(packet.at),
|
|
244
|
+
type : type,
|
|
245
|
+
process_id : packet.process.pm_id,
|
|
246
|
+
app_name : packet.process.name
|
|
247
|
+
}));
|
|
248
|
+
process.stdout.write('\n');
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
Log.formatStream = function(Client, id, raw, timestamp, exclusive, highlight) {
|
|
254
|
+
var that = this;
|
|
255
|
+
|
|
256
|
+
Client.launchBus(function(err, bus) {
|
|
257
|
+
|
|
258
|
+
bus.on('log:*', function(type, packet) {
|
|
259
|
+
if (id !== 'all'
|
|
260
|
+
&& packet.process.name != id
|
|
261
|
+
&& packet.process.pm_id != id)
|
|
262
|
+
return;
|
|
263
|
+
|
|
264
|
+
if ((type === 'out' && exclusive === 'err')
|
|
265
|
+
|| (type === 'err' && exclusive === 'out')
|
|
266
|
+
|| (type === 'PM2' && exclusive !== false))
|
|
267
|
+
return;
|
|
268
|
+
|
|
269
|
+
if (type === 'PM2' && raw)
|
|
270
|
+
return;
|
|
271
|
+
|
|
272
|
+
var name = packet.process.name + '-' + packet.process.pm_id;
|
|
273
|
+
|
|
274
|
+
var lines;
|
|
275
|
+
|
|
276
|
+
if (typeof(packet.data) === 'string')
|
|
277
|
+
lines = (packet.data || '').split('\n');
|
|
278
|
+
else
|
|
279
|
+
return;
|
|
280
|
+
|
|
281
|
+
lines.forEach(function(line) {
|
|
282
|
+
if (!line || line.length === 0) return;
|
|
283
|
+
|
|
284
|
+
if (!raw) {
|
|
285
|
+
if (timestamp)
|
|
286
|
+
process.stdout.write('timestamp=' + dayjs().format(timestamp) + ' ');
|
|
287
|
+
if (packet.process.name === 'PM2')
|
|
288
|
+
process.stdout.write('app=pm2 ');
|
|
289
|
+
if (packet.process.name !== 'PM2')
|
|
290
|
+
process.stdout.write('app=' + packet.process.name + ' id=' + packet.process.pm_id + ' ');
|
|
291
|
+
if (type === 'out')
|
|
292
|
+
process.stdout.write('type=out ');
|
|
293
|
+
else if (type === 'err')
|
|
294
|
+
process.stdout.write('type=error ');
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
process.stdout.write('message=');
|
|
298
|
+
if (highlight)
|
|
299
|
+
process.stdout.write(util.format(line).replace(highlight, chalk.bgBlackBright(highlight)) + '\n');
|
|
300
|
+
else
|
|
301
|
+
process.stdout.write(util.format(line) + '\n');
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
function pad(pad, str, padLeft) {
|
|
308
|
+
if (typeof str === 'undefined')
|
|
309
|
+
return pad;
|
|
310
|
+
if (padLeft) {
|
|
311
|
+
return (pad + str).slice(-pad.length);
|
|
312
|
+
} else {
|
|
313
|
+
return (str + pad).substring(0, pad.length);
|
|
314
|
+
}
|
|
315
|
+
}
|