-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdeepSkyUtils.js
More file actions
81 lines (67 loc) · 2.24 KB
/
deepSkyUtils.js
File metadata and controls
81 lines (67 loc) · 2.24 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
/*
deepSkyUtils.js: Generic utility methods.
================================================================================
Common utilities used across various scripts.
================================================================================
*
*
* Copyright Jeremy Likness, 2021
*
* License: https://github.com/DeepSkyWorkflows/DeepSkyWorkflowScripts/LICENSE
*
* Source: https://github.com/DeepSkyWorkflows/DeepSkyWorkflowScripts
*
* mailTo:deepskyworkflows@gmail.com
*
*/
#script-id DeepSkyUtils
#include "deepSkyInit.js"
#define DEBUG_UTILITY false
(function (ds) {
ds.debug.register('utilities', DEBUG_UTILITY);
ds.debug.utilities.debugLn('Utilities debugging is on.');
if (ds.utilities) {
return;
}
ds.utilities = {
// concatenate parts into a string
concatenateStr: function () {
let strings = Array.prototype.slice.call(arguments);
return strings.join('');
},
// replace a function by extending it
chainFn: function (target, oldFnName, newFn) {
let oldFn = target[oldFnName];
return function () {
if (oldFn) {
oldFn.apply(target, arguments);
}
return newFn.apply(target, arguments);
};
},
// write lines with title prefix
writeLines: function () {
for (var arg = 0; arg < arguments.length; ++arg) {
var val = arguments[arg];
if (arg === 0) {
console.writeln(ds.utilities.concatenateStr('<b>', ds.activeFeature.title, '</b>: ', val));
}
else {
console.writeln(val);
}
}
console.flush();
},
// get a unique name that doesn't conflict with existing
getNewName: function (name, suffix) {
ds.debug.utilities.debugLn('getNewName called with name', name, 'and suffix', suffix);
let viewName = name + suffix;
let n = 1;
while (!ImageWindow.windowById(viewName).isNull) {
++n;
viewName = name + suffix + n;
}
return viewName;
}
};
})(deepSky);