node-opcua-utils 2.90.1 → 2.98.1
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/dist/buffer_ellipsis.d.ts +5 -5
- package/dist/buffer_ellipsis.js +16 -16
- package/dist/compare_buffers.d.ts +2 -2
- package/dist/compare_buffers.js +26 -26
- package/dist/function_variadic.d.ts +1 -1
- package/dist/function_variadic.js +2 -2
- package/dist/get_clock_tick.d.ts +4 -4
- package/dist/get_clock_tick.js +16 -16
- package/dist/get_function_parameters_name.d.ts +2 -2
- package/dist/get_function_parameters_name.js +17 -17
- package/dist/hrtime.d.ts +2 -2
- package/dist/hrtime.js +31 -31
- package/dist/index.d.ts +28 -28
- package/dist/index.js +74 -74
- package/dist/line_file.d.ts +9 -9
- package/dist/line_file.js +23 -23
- package/dist/match_uri.d.ts +11 -11
- package/dist/match_uri.js +23 -23
- package/dist/object_classname.d.ts +9 -9
- package/dist/object_classname.js +15 -15
- package/dist/replace_buffer_with_hex_dump.d.ts +6 -6
- package/dist/replace_buffer_with_hex_dump.js +20 -20
- package/dist/set_deprecated.d.ts +2 -2
- package/dist/set_deprecated.js +25 -25
- package/dist/string_utils.d.ts +66 -66
- package/dist/string_utils.js +127 -127
- package/dist/timestamp.d.ts +1 -1
- package/dist/timestamp.js +13 -13
- package/dist/watchdog.d.ts +57 -57
- package/dist/watchdog.js +142 -142
- package/dist/watchdog.js.map +1 -1
- package/package.json +9 -5
package/dist/object_classname.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getObjectClassName = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* @module node-opcua-utils
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* @method getObjectClassName
|
|
9
|
-
* @param obj
|
|
10
|
-
* @return {string}
|
|
11
|
-
*/
|
|
12
|
-
function getObjectClassName(obj) {
|
|
13
|
-
return Object.prototype.toString.call(obj).slice(8, -1);
|
|
14
|
-
}
|
|
15
|
-
exports.getObjectClassName = getObjectClassName;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getObjectClassName = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @module node-opcua-utils
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* @method getObjectClassName
|
|
9
|
+
* @param obj
|
|
10
|
+
* @return {string}
|
|
11
|
+
*/
|
|
12
|
+
function getObjectClassName(obj) {
|
|
13
|
+
return Object.prototype.toString.call(obj).slice(8, -1);
|
|
14
|
+
}
|
|
15
|
+
exports.getObjectClassName = getObjectClassName;
|
|
16
16
|
//# sourceMappingURL=object_classname.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module node-opcua-utils
|
|
3
|
-
*/
|
|
4
|
-
export declare function replaceBufferWithHexDump(obj: Record<string, {
|
|
5
|
-
toString(format: string): void;
|
|
6
|
-
}>): any;
|
|
1
|
+
/**
|
|
2
|
+
* @module node-opcua-utils
|
|
3
|
+
*/
|
|
4
|
+
export declare function replaceBufferWithHexDump(obj: Record<string, {
|
|
5
|
+
toString(format: string): void;
|
|
6
|
+
}>): any;
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.replaceBufferWithHexDump = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* @module node-opcua-utils
|
|
6
|
-
*/
|
|
7
|
-
function replaceBufferWithHexDump(obj) {
|
|
8
|
-
for (const p in obj) {
|
|
9
|
-
if (Object.prototype.hasOwnProperty.call(obj, p)) {
|
|
10
|
-
if (obj[p] instanceof Buffer) {
|
|
11
|
-
obj[p] = "<BUFFER>" + obj[p].toString("hex") + "</BUFFER>";
|
|
12
|
-
}
|
|
13
|
-
else if (typeof obj[p] === "object") {
|
|
14
|
-
replaceBufferWithHexDump(obj[p]);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return obj;
|
|
19
|
-
}
|
|
20
|
-
exports.replaceBufferWithHexDump = replaceBufferWithHexDump;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.replaceBufferWithHexDump = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @module node-opcua-utils
|
|
6
|
+
*/
|
|
7
|
+
function replaceBufferWithHexDump(obj) {
|
|
8
|
+
for (const p in obj) {
|
|
9
|
+
if (Object.prototype.hasOwnProperty.call(obj, p)) {
|
|
10
|
+
if (obj[p] instanceof Buffer) {
|
|
11
|
+
obj[p] = "<BUFFER>" + obj[p].toString("hex") + "</BUFFER>";
|
|
12
|
+
}
|
|
13
|
+
else if (typeof obj[p] === "object") {
|
|
14
|
+
replaceBufferWithHexDump(obj[p]);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return obj;
|
|
19
|
+
}
|
|
20
|
+
exports.replaceBufferWithHexDump = replaceBufferWithHexDump;
|
|
21
21
|
//# sourceMappingURL=replace_buffer_with_hex_dump.js.map
|
package/dist/set_deprecated.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { FunctionVariadic } from "./function_variadic";
|
|
2
|
-
export declare function setDeprecated(constructor: FunctionVariadic, methodName: string, helpString: string): void;
|
|
1
|
+
import { FunctionVariadic } from "./function_variadic";
|
|
2
|
+
export declare function setDeprecated(constructor: FunctionVariadic, methodName: string, helpString: string): void;
|
package/dist/set_deprecated.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setDeprecated = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* @module node-opcua-utils
|
|
6
|
-
*/
|
|
7
|
-
// tslint:disable:ban-types
|
|
8
|
-
const chalk = require("chalk");
|
|
9
|
-
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
10
|
-
/* istanbul ignore next */
|
|
11
|
-
function setDeprecated(constructor, methodName, helpString) {
|
|
12
|
-
const oldMethod = constructor.prototype[methodName];
|
|
13
|
-
(0, node_opcua_assert_1.assert)(oldMethod instanceof Function, "expecting a valid " + methodName + "method on class " + constructor.constructor.name);
|
|
14
|
-
let counter = 0;
|
|
15
|
-
constructor.prototype[methodName] = function (...args) {
|
|
16
|
-
if (counter % 1000 === 0) {
|
|
17
|
-
// tslint:disable:no-console
|
|
18
|
-
console.log(chalk.green("Warning !"), chalk.green(chalk.bold(constructor.name + "#" + methodName), " is now deprecated"));
|
|
19
|
-
console.log(" ", helpString);
|
|
20
|
-
}
|
|
21
|
-
counter++;
|
|
22
|
-
return oldMethod.call(this, ...args);
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
exports.setDeprecated = setDeprecated;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setDeprecated = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @module node-opcua-utils
|
|
6
|
+
*/
|
|
7
|
+
// tslint:disable:ban-types
|
|
8
|
+
const chalk = require("chalk");
|
|
9
|
+
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
10
|
+
/* istanbul ignore next */
|
|
11
|
+
function setDeprecated(constructor, methodName, helpString) {
|
|
12
|
+
const oldMethod = constructor.prototype[methodName];
|
|
13
|
+
(0, node_opcua_assert_1.assert)(oldMethod instanceof Function, "expecting a valid " + methodName + "method on class " + constructor.constructor.name);
|
|
14
|
+
let counter = 0;
|
|
15
|
+
constructor.prototype[methodName] = function (...args) {
|
|
16
|
+
if (counter % 1000 === 0) {
|
|
17
|
+
// tslint:disable:no-console
|
|
18
|
+
console.log(chalk.green("Warning !"), chalk.green(chalk.bold(constructor.name + "#" + methodName), " is now deprecated"));
|
|
19
|
+
console.log(" ", helpString);
|
|
20
|
+
}
|
|
21
|
+
counter++;
|
|
22
|
+
return oldMethod.call(this, ...args);
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
exports.setDeprecated = setDeprecated;
|
|
26
26
|
//# sourceMappingURL=set_deprecated.js.map
|
package/dist/string_utils.d.ts
CHANGED
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module node-opcua-utils
|
|
3
|
-
*/
|
|
4
|
-
export declare function capitalizeFirstLetter(str: string): string;
|
|
5
|
-
export declare function isUpperCaseChar(c: string): boolean;
|
|
6
|
-
export declare function isAlpha(c: string): boolean;
|
|
7
|
-
export declare function countUpperCaseSlow(str: string): number;
|
|
8
|
-
export declare function countAlphaSlow(str: string): number;
|
|
9
|
-
export declare function countUpperCase(str: string): number;
|
|
10
|
-
export declare function countAlpha(str: string): number;
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
* lowerFirstLetter convert a OPCUA Identifier to a javascript Identifier
|
|
14
|
-
*
|
|
15
|
-
* @summary
|
|
16
|
-
*
|
|
17
|
-
* OPCUA and Javascript use two different rules to build identifiers.
|
|
18
|
-
*
|
|
19
|
-
* OPCUA Identifier usually starts with a upper case letter and word are join together, this is known as
|
|
20
|
-
* the Pascal case, or CapitalizedWords convention. (for instance HelloWorld)
|
|
21
|
-
* But sometime, OPCUA identifiers do not follow this convention strictly and we can find various
|
|
22
|
-
* other convention being applied such as underscore between word, or addition of ACRONYMIC prefixes.
|
|
23
|
-
* On it's own, this causes great confusion and inconsistency in programming style.
|
|
24
|
-
*
|
|
25
|
-
* Javascript uses a slightly different convention called camelCase where word are joined together
|
|
26
|
-
* and inner words starts with a capital letter whereas first word starts with a lower case letter.
|
|
27
|
-
* (for instance helloWorld)
|
|
28
|
-
*
|
|
29
|
-
* In node-opcua we have taken the opinionated decision to consistently use camelCase convention for
|
|
30
|
-
* object properties so that all the code look nice and consistent.
|
|
31
|
-
* the lowerFirstLetter method can be used to easily convert from the OPCUA naming convention
|
|
32
|
-
* to javascript naming convention by applying the following rules.
|
|
33
|
-
*
|
|
34
|
-
* * each ascii sequence in a identifier will be converted to lower camel case.
|
|
35
|
-
* * when an identifier only contains upper case letter then it will be untouched. ( i.e CQDF => CQFD)
|
|
36
|
-
* (this rules helps to preserve acronyms)
|
|
37
|
-
* * when a identifier starts with more than one UpperCase letter but still contain lowercase letter
|
|
38
|
-
* then the first Uppercase letter excluding the last one will be converted to lower case
|
|
39
|
-
* ( ie: EURange = > euRange)
|
|
40
|
-
* * when a identifier contains several sequences delimited with underscores (_) the above rules
|
|
41
|
-
* will be applied to each of the element of the sequence
|
|
42
|
-
* ( ie: ALM_FlowOutOfTolerance => ALM_flowOutOfTolerance ( ALM=>ALM , FlowOutOfTolerance=>flowOutOfTolerance)
|
|
43
|
-
*
|
|
44
|
-
* @reference
|
|
45
|
-
* * https://en.wikipedia.org/wiki/Camel_case
|
|
46
|
-
* * https://en.wikipedia.org/wiki/Hungarian_notation
|
|
47
|
-
* * http://wiki.c2.com/?UnderscoreVersusCapitalAndLowerCaseVariableNaming
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* HelloWorld => helloWorld
|
|
53
|
-
* XAxis => xAxis
|
|
54
|
-
* EURange => euRange
|
|
55
|
-
* DATE => DATE
|
|
56
|
-
* XYZ => XYZ
|
|
57
|
-
* AB => AB
|
|
58
|
-
* Ab => ab
|
|
59
|
-
* A => a
|
|
60
|
-
* T1ABC8 => T1ABC8
|
|
61
|
-
* F_ABC_D => F_ABC_D
|
|
62
|
-
* ALM_Timeout => ALM_timeout
|
|
63
|
-
* SV_GasOn => SV_gasOn
|
|
64
|
-
* DI_VAL_FlowImp => DI_VAL_flowImp
|
|
65
|
-
*/
|
|
66
|
-
export declare function lowerFirstLetter(str: string): string;
|
|
1
|
+
/**
|
|
2
|
+
* @module node-opcua-utils
|
|
3
|
+
*/
|
|
4
|
+
export declare function capitalizeFirstLetter(str: string): string;
|
|
5
|
+
export declare function isUpperCaseChar(c: string): boolean;
|
|
6
|
+
export declare function isAlpha(c: string): boolean;
|
|
7
|
+
export declare function countUpperCaseSlow(str: string): number;
|
|
8
|
+
export declare function countAlphaSlow(str: string): number;
|
|
9
|
+
export declare function countUpperCase(str: string): number;
|
|
10
|
+
export declare function countAlpha(str: string): number;
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* lowerFirstLetter convert a OPCUA Identifier to a javascript Identifier
|
|
14
|
+
*
|
|
15
|
+
* @summary
|
|
16
|
+
*
|
|
17
|
+
* OPCUA and Javascript use two different rules to build identifiers.
|
|
18
|
+
*
|
|
19
|
+
* OPCUA Identifier usually starts with a upper case letter and word are join together, this is known as
|
|
20
|
+
* the Pascal case, or CapitalizedWords convention. (for instance HelloWorld)
|
|
21
|
+
* But sometime, OPCUA identifiers do not follow this convention strictly and we can find various
|
|
22
|
+
* other convention being applied such as underscore between word, or addition of ACRONYMIC prefixes.
|
|
23
|
+
* On it's own, this causes great confusion and inconsistency in programming style.
|
|
24
|
+
*
|
|
25
|
+
* Javascript uses a slightly different convention called camelCase where word are joined together
|
|
26
|
+
* and inner words starts with a capital letter whereas first word starts with a lower case letter.
|
|
27
|
+
* (for instance helloWorld)
|
|
28
|
+
*
|
|
29
|
+
* In node-opcua we have taken the opinionated decision to consistently use camelCase convention for
|
|
30
|
+
* object properties so that all the code look nice and consistent.
|
|
31
|
+
* the lowerFirstLetter method can be used to easily convert from the OPCUA naming convention
|
|
32
|
+
* to javascript naming convention by applying the following rules.
|
|
33
|
+
*
|
|
34
|
+
* * each ascii sequence in a identifier will be converted to lower camel case.
|
|
35
|
+
* * when an identifier only contains upper case letter then it will be untouched. ( i.e CQDF => CQFD)
|
|
36
|
+
* (this rules helps to preserve acronyms)
|
|
37
|
+
* * when a identifier starts with more than one UpperCase letter but still contain lowercase letter
|
|
38
|
+
* then the first Uppercase letter excluding the last one will be converted to lower case
|
|
39
|
+
* ( ie: EURange = > euRange)
|
|
40
|
+
* * when a identifier contains several sequences delimited with underscores (_) the above rules
|
|
41
|
+
* will be applied to each of the element of the sequence
|
|
42
|
+
* ( ie: ALM_FlowOutOfTolerance => ALM_flowOutOfTolerance ( ALM=>ALM , FlowOutOfTolerance=>flowOutOfTolerance)
|
|
43
|
+
*
|
|
44
|
+
* @reference
|
|
45
|
+
* * https://en.wikipedia.org/wiki/Camel_case
|
|
46
|
+
* * https://en.wikipedia.org/wiki/Hungarian_notation
|
|
47
|
+
* * http://wiki.c2.com/?UnderscoreVersusCapitalAndLowerCaseVariableNaming
|
|
48
|
+
*
|
|
49
|
+
*
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* HelloWorld => helloWorld
|
|
53
|
+
* XAxis => xAxis
|
|
54
|
+
* EURange => euRange
|
|
55
|
+
* DATE => DATE
|
|
56
|
+
* XYZ => XYZ
|
|
57
|
+
* AB => AB
|
|
58
|
+
* Ab => ab
|
|
59
|
+
* A => a
|
|
60
|
+
* T1ABC8 => T1ABC8
|
|
61
|
+
* F_ABC_D => F_ABC_D
|
|
62
|
+
* ALM_Timeout => ALM_timeout
|
|
63
|
+
* SV_GasOn => SV_gasOn
|
|
64
|
+
* DI_VAL_FlowImp => DI_VAL_flowImp
|
|
65
|
+
*/
|
|
66
|
+
export declare function lowerFirstLetter(str: string): string;
|
package/dist/string_utils.js
CHANGED
|
@@ -1,128 +1,128 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.lowerFirstLetter = exports.countAlpha = exports.countUpperCase = exports.countAlphaSlow = exports.countUpperCaseSlow = exports.isAlpha = exports.isUpperCaseChar = exports.capitalizeFirstLetter = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* @module node-opcua-utils
|
|
6
|
-
*/
|
|
7
|
-
// tslint:disable:variable-name
|
|
8
|
-
function capitalizeFirstLetter(str) {
|
|
9
|
-
if (str == null) {
|
|
10
|
-
return str;
|
|
11
|
-
}
|
|
12
|
-
return str.substring(0, 1).toUpperCase() + str.substring(1);
|
|
13
|
-
}
|
|
14
|
-
exports.capitalizeFirstLetter = capitalizeFirstLetter;
|
|
15
|
-
const ACode = "A".charCodeAt(0);
|
|
16
|
-
const ZCode = "Z".charCodeAt(0);
|
|
17
|
-
function isUpperCaseChar(c) {
|
|
18
|
-
const code = c.charCodeAt(0);
|
|
19
|
-
return code >= ACode && code <= ZCode;
|
|
20
|
-
}
|
|
21
|
-
exports.isUpperCaseChar = isUpperCaseChar;
|
|
22
|
-
const aCode = "a".charCodeAt(0);
|
|
23
|
-
const zCode = "z".charCodeAt(0);
|
|
24
|
-
function isAlpha(c) {
|
|
25
|
-
const code = c.charCodeAt(0);
|
|
26
|
-
return (code >= ACode && code <= ZCode) || (code >= aCode && code <= zCode);
|
|
27
|
-
}
|
|
28
|
-
exports.isAlpha = isAlpha;
|
|
29
|
-
function countUpperCaseSlow(str) {
|
|
30
|
-
return str.split("").reduce((p, c) => p + (isUpperCaseChar(c) ? 1 : 0), 0);
|
|
31
|
-
}
|
|
32
|
-
exports.countUpperCaseSlow = countUpperCaseSlow;
|
|
33
|
-
function countAlphaSlow(str) {
|
|
34
|
-
return str.split("").reduce((p, c) => p + (isAlpha(c) ? 1 : 0), 0);
|
|
35
|
-
}
|
|
36
|
-
exports.countAlphaSlow = countAlphaSlow;
|
|
37
|
-
function countUpperCase(str) {
|
|
38
|
-
let count = 0;
|
|
39
|
-
const n = str.length;
|
|
40
|
-
for (let i = 0; i < n; i++) {
|
|
41
|
-
count += isUpperCaseChar(str[i]) ? 1 : 0;
|
|
42
|
-
}
|
|
43
|
-
return count;
|
|
44
|
-
}
|
|
45
|
-
exports.countUpperCase = countUpperCase;
|
|
46
|
-
function countAlpha(str) {
|
|
47
|
-
let count = 0;
|
|
48
|
-
const n = str.length;
|
|
49
|
-
for (let i = 0; i < n; i++) {
|
|
50
|
-
count += isAlpha(str[i]) ? 1 : 0;
|
|
51
|
-
}
|
|
52
|
-
return count;
|
|
53
|
-
}
|
|
54
|
-
exports.countAlpha = countAlpha;
|
|
55
|
-
/**
|
|
56
|
-
*
|
|
57
|
-
* lowerFirstLetter convert a OPCUA Identifier to a javascript Identifier
|
|
58
|
-
*
|
|
59
|
-
* @summary
|
|
60
|
-
*
|
|
61
|
-
* OPCUA and Javascript use two different rules to build identifiers.
|
|
62
|
-
*
|
|
63
|
-
* OPCUA Identifier usually starts with a upper case letter and word are join together, this is known as
|
|
64
|
-
* the Pascal case, or CapitalizedWords convention. (for instance HelloWorld)
|
|
65
|
-
* But sometime, OPCUA identifiers do not follow this convention strictly and we can find various
|
|
66
|
-
* other convention being applied such as underscore between word, or addition of ACRONYMIC prefixes.
|
|
67
|
-
* On it's own, this causes great confusion and inconsistency in programming style.
|
|
68
|
-
*
|
|
69
|
-
* Javascript uses a slightly different convention called camelCase where word are joined together
|
|
70
|
-
* and inner words starts with a capital letter whereas first word starts with a lower case letter.
|
|
71
|
-
* (for instance helloWorld)
|
|
72
|
-
*
|
|
73
|
-
* In node-opcua we have taken the opinionated decision to consistently use camelCase convention for
|
|
74
|
-
* object properties so that all the code look nice and consistent.
|
|
75
|
-
* the lowerFirstLetter method can be used to easily convert from the OPCUA naming convention
|
|
76
|
-
* to javascript naming convention by applying the following rules.
|
|
77
|
-
*
|
|
78
|
-
* * each ascii sequence in a identifier will be converted to lower camel case.
|
|
79
|
-
* * when an identifier only contains upper case letter then it will be untouched. ( i.e CQDF => CQFD)
|
|
80
|
-
* (this rules helps to preserve acronyms)
|
|
81
|
-
* * when a identifier starts with more than one UpperCase letter but still contain lowercase letter
|
|
82
|
-
* then the first Uppercase letter excluding the last one will be converted to lower case
|
|
83
|
-
* ( ie: EURange = > euRange)
|
|
84
|
-
* * when a identifier contains several sequences delimited with underscores (_) the above rules
|
|
85
|
-
* will be applied to each of the element of the sequence
|
|
86
|
-
* ( ie: ALM_FlowOutOfTolerance => ALM_flowOutOfTolerance ( ALM=>ALM , FlowOutOfTolerance=>flowOutOfTolerance)
|
|
87
|
-
*
|
|
88
|
-
* @reference
|
|
89
|
-
* * https://en.wikipedia.org/wiki/Camel_case
|
|
90
|
-
* * https://en.wikipedia.org/wiki/Hungarian_notation
|
|
91
|
-
* * http://wiki.c2.com/?UnderscoreVersusCapitalAndLowerCaseVariableNaming
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
* @example
|
|
96
|
-
* HelloWorld => helloWorld
|
|
97
|
-
* XAxis => xAxis
|
|
98
|
-
* EURange => euRange
|
|
99
|
-
* DATE => DATE
|
|
100
|
-
* XYZ => XYZ
|
|
101
|
-
* AB => AB
|
|
102
|
-
* Ab => ab
|
|
103
|
-
* A => a
|
|
104
|
-
* T1ABC8 => T1ABC8
|
|
105
|
-
* F_ABC_D => F_ABC_D
|
|
106
|
-
* ALM_Timeout => ALM_timeout
|
|
107
|
-
* SV_GasOn => SV_gasOn
|
|
108
|
-
* DI_VAL_FlowImp => DI_VAL_flowImp
|
|
109
|
-
*/
|
|
110
|
-
function lowerFirstLetter(str) {
|
|
111
|
-
if (str == null) {
|
|
112
|
-
return str;
|
|
113
|
-
}
|
|
114
|
-
// at least, 2 all upper
|
|
115
|
-
if (str.length >= 2 && countUpperCase(str) === countAlpha(str)) {
|
|
116
|
-
return str;
|
|
117
|
-
}
|
|
118
|
-
if (str.match(/_/)) {
|
|
119
|
-
return str.split("_").map(lowerFirstLetter).join("_");
|
|
120
|
-
}
|
|
121
|
-
let result = str.substring(0, 1).toLowerCase() + str.substring(1);
|
|
122
|
-
if (result.length > 3 && isUpperCaseChar(str[1]) && isUpperCaseChar(str[2])) {
|
|
123
|
-
result = str.substring(0, 2).toLowerCase() + str.substring(2);
|
|
124
|
-
}
|
|
125
|
-
return result;
|
|
126
|
-
}
|
|
127
|
-
exports.lowerFirstLetter = lowerFirstLetter;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.lowerFirstLetter = exports.countAlpha = exports.countUpperCase = exports.countAlphaSlow = exports.countUpperCaseSlow = exports.isAlpha = exports.isUpperCaseChar = exports.capitalizeFirstLetter = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @module node-opcua-utils
|
|
6
|
+
*/
|
|
7
|
+
// tslint:disable:variable-name
|
|
8
|
+
function capitalizeFirstLetter(str) {
|
|
9
|
+
if (str == null) {
|
|
10
|
+
return str;
|
|
11
|
+
}
|
|
12
|
+
return str.substring(0, 1).toUpperCase() + str.substring(1);
|
|
13
|
+
}
|
|
14
|
+
exports.capitalizeFirstLetter = capitalizeFirstLetter;
|
|
15
|
+
const ACode = "A".charCodeAt(0);
|
|
16
|
+
const ZCode = "Z".charCodeAt(0);
|
|
17
|
+
function isUpperCaseChar(c) {
|
|
18
|
+
const code = c.charCodeAt(0);
|
|
19
|
+
return code >= ACode && code <= ZCode;
|
|
20
|
+
}
|
|
21
|
+
exports.isUpperCaseChar = isUpperCaseChar;
|
|
22
|
+
const aCode = "a".charCodeAt(0);
|
|
23
|
+
const zCode = "z".charCodeAt(0);
|
|
24
|
+
function isAlpha(c) {
|
|
25
|
+
const code = c.charCodeAt(0);
|
|
26
|
+
return (code >= ACode && code <= ZCode) || (code >= aCode && code <= zCode);
|
|
27
|
+
}
|
|
28
|
+
exports.isAlpha = isAlpha;
|
|
29
|
+
function countUpperCaseSlow(str) {
|
|
30
|
+
return str.split("").reduce((p, c) => p + (isUpperCaseChar(c) ? 1 : 0), 0);
|
|
31
|
+
}
|
|
32
|
+
exports.countUpperCaseSlow = countUpperCaseSlow;
|
|
33
|
+
function countAlphaSlow(str) {
|
|
34
|
+
return str.split("").reduce((p, c) => p + (isAlpha(c) ? 1 : 0), 0);
|
|
35
|
+
}
|
|
36
|
+
exports.countAlphaSlow = countAlphaSlow;
|
|
37
|
+
function countUpperCase(str) {
|
|
38
|
+
let count = 0;
|
|
39
|
+
const n = str.length;
|
|
40
|
+
for (let i = 0; i < n; i++) {
|
|
41
|
+
count += isUpperCaseChar(str[i]) ? 1 : 0;
|
|
42
|
+
}
|
|
43
|
+
return count;
|
|
44
|
+
}
|
|
45
|
+
exports.countUpperCase = countUpperCase;
|
|
46
|
+
function countAlpha(str) {
|
|
47
|
+
let count = 0;
|
|
48
|
+
const n = str.length;
|
|
49
|
+
for (let i = 0; i < n; i++) {
|
|
50
|
+
count += isAlpha(str[i]) ? 1 : 0;
|
|
51
|
+
}
|
|
52
|
+
return count;
|
|
53
|
+
}
|
|
54
|
+
exports.countAlpha = countAlpha;
|
|
55
|
+
/**
|
|
56
|
+
*
|
|
57
|
+
* lowerFirstLetter convert a OPCUA Identifier to a javascript Identifier
|
|
58
|
+
*
|
|
59
|
+
* @summary
|
|
60
|
+
*
|
|
61
|
+
* OPCUA and Javascript use two different rules to build identifiers.
|
|
62
|
+
*
|
|
63
|
+
* OPCUA Identifier usually starts with a upper case letter and word are join together, this is known as
|
|
64
|
+
* the Pascal case, or CapitalizedWords convention. (for instance HelloWorld)
|
|
65
|
+
* But sometime, OPCUA identifiers do not follow this convention strictly and we can find various
|
|
66
|
+
* other convention being applied such as underscore between word, or addition of ACRONYMIC prefixes.
|
|
67
|
+
* On it's own, this causes great confusion and inconsistency in programming style.
|
|
68
|
+
*
|
|
69
|
+
* Javascript uses a slightly different convention called camelCase where word are joined together
|
|
70
|
+
* and inner words starts with a capital letter whereas first word starts with a lower case letter.
|
|
71
|
+
* (for instance helloWorld)
|
|
72
|
+
*
|
|
73
|
+
* In node-opcua we have taken the opinionated decision to consistently use camelCase convention for
|
|
74
|
+
* object properties so that all the code look nice and consistent.
|
|
75
|
+
* the lowerFirstLetter method can be used to easily convert from the OPCUA naming convention
|
|
76
|
+
* to javascript naming convention by applying the following rules.
|
|
77
|
+
*
|
|
78
|
+
* * each ascii sequence in a identifier will be converted to lower camel case.
|
|
79
|
+
* * when an identifier only contains upper case letter then it will be untouched. ( i.e CQDF => CQFD)
|
|
80
|
+
* (this rules helps to preserve acronyms)
|
|
81
|
+
* * when a identifier starts with more than one UpperCase letter but still contain lowercase letter
|
|
82
|
+
* then the first Uppercase letter excluding the last one will be converted to lower case
|
|
83
|
+
* ( ie: EURange = > euRange)
|
|
84
|
+
* * when a identifier contains several sequences delimited with underscores (_) the above rules
|
|
85
|
+
* will be applied to each of the element of the sequence
|
|
86
|
+
* ( ie: ALM_FlowOutOfTolerance => ALM_flowOutOfTolerance ( ALM=>ALM , FlowOutOfTolerance=>flowOutOfTolerance)
|
|
87
|
+
*
|
|
88
|
+
* @reference
|
|
89
|
+
* * https://en.wikipedia.org/wiki/Camel_case
|
|
90
|
+
* * https://en.wikipedia.org/wiki/Hungarian_notation
|
|
91
|
+
* * http://wiki.c2.com/?UnderscoreVersusCapitalAndLowerCaseVariableNaming
|
|
92
|
+
*
|
|
93
|
+
*
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* HelloWorld => helloWorld
|
|
97
|
+
* XAxis => xAxis
|
|
98
|
+
* EURange => euRange
|
|
99
|
+
* DATE => DATE
|
|
100
|
+
* XYZ => XYZ
|
|
101
|
+
* AB => AB
|
|
102
|
+
* Ab => ab
|
|
103
|
+
* A => a
|
|
104
|
+
* T1ABC8 => T1ABC8
|
|
105
|
+
* F_ABC_D => F_ABC_D
|
|
106
|
+
* ALM_Timeout => ALM_timeout
|
|
107
|
+
* SV_GasOn => SV_gasOn
|
|
108
|
+
* DI_VAL_FlowImp => DI_VAL_flowImp
|
|
109
|
+
*/
|
|
110
|
+
function lowerFirstLetter(str) {
|
|
111
|
+
if (str == null) {
|
|
112
|
+
return str;
|
|
113
|
+
}
|
|
114
|
+
// at least, 2 all upper
|
|
115
|
+
if (str.length >= 2 && countUpperCase(str) === countAlpha(str)) {
|
|
116
|
+
return str;
|
|
117
|
+
}
|
|
118
|
+
if (str.match(/_/)) {
|
|
119
|
+
return str.split("_").map(lowerFirstLetter).join("_");
|
|
120
|
+
}
|
|
121
|
+
let result = str.substring(0, 1).toLowerCase() + str.substring(1);
|
|
122
|
+
if (result.length > 3 && isUpperCaseChar(str[1]) && isUpperCaseChar(str[2])) {
|
|
123
|
+
result = str.substring(0, 2).toLowerCase() + str.substring(2);
|
|
124
|
+
}
|
|
125
|
+
return result;
|
|
126
|
+
}
|
|
127
|
+
exports.lowerFirstLetter = lowerFirstLetter;
|
|
128
128
|
//# sourceMappingURL=string_utils.js.map
|
package/dist/timestamp.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function timestamp(): string;
|
|
1
|
+
export declare function timestamp(): string;
|
package/dist/timestamp.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.timestamp = void 0;
|
|
4
|
-
function w(s, length) {
|
|
5
|
-
return ("" + s).padStart(length, "0");
|
|
6
|
-
}
|
|
7
|
-
function t(d) {
|
|
8
|
-
return w(d.getUTCHours(), 2) + ":" + w(d.getUTCMinutes(), 2) + ":" + w(d.getUTCSeconds(), 2) + ":" + w(d.getMilliseconds(), 3);
|
|
9
|
-
}
|
|
10
|
-
function timestamp() {
|
|
11
|
-
return t(new Date());
|
|
12
|
-
}
|
|
13
|
-
exports.timestamp = timestamp;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.timestamp = void 0;
|
|
4
|
+
function w(s, length) {
|
|
5
|
+
return ("" + s).padStart(length, "0");
|
|
6
|
+
}
|
|
7
|
+
function t(d) {
|
|
8
|
+
return w(d.getUTCHours(), 2) + ":" + w(d.getUTCMinutes(), 2) + ":" + w(d.getUTCSeconds(), 2) + ":" + w(d.getMilliseconds(), 3);
|
|
9
|
+
}
|
|
10
|
+
function timestamp() {
|
|
11
|
+
return t(new Date());
|
|
12
|
+
}
|
|
13
|
+
exports.timestamp = timestamp;
|
|
14
14
|
//# sourceMappingURL=timestamp.js.map
|