aboutsummaryrefslogtreecommitdiffstats
path: root/sdc-workflow-designer-ui/src/app/paletx/util/util.ts
diff options
context:
space:
mode:
authorYuanHu <yuan.hu1@zte.com.cn>2018-03-27 15:50:00 +0800
committerYuanHu <yuan.hu1@zte.com.cn>2018-03-27 15:50:00 +0800
commit309680feb63ec6a49163387cb1e116b721254847 (patch)
tree0d58a1e12acad73b1421236412f6e41ca08196d3 /sdc-workflow-designer-ui/src/app/paletx/util/util.ts
parent5b3cc39ad139793fe689683a4a7344ddb3c8361f (diff)
Add paletx common & util
Add paletx common & util Issue-ID: SDC-1130,SDC-1131 Change-Id: Ibbdd8d4fabf45637be7d44400c18d34efc15d46e Signed-off-by: YuanHu <yuan.hu1@zte.com.cn>
Diffstat (limited to 'sdc-workflow-designer-ui/src/app/paletx/util/util.ts')
-rw-r--r--sdc-workflow-designer-ui/src/app/paletx/util/util.ts65
1 files changed, 65 insertions, 0 deletions
diff --git a/sdc-workflow-designer-ui/src/app/paletx/util/util.ts b/sdc-workflow-designer-ui/src/app/paletx/util/util.ts
new file mode 100644
index 00000000..5df0381e
--- /dev/null
+++ b/sdc-workflow-designer-ui/src/app/paletx/util/util.ts
@@ -0,0 +1,65 @@
+export function toInteger(value: any): number {
+ return parseInt(`${value}`, 10);
+}
+
+export function toString(value: any): string {
+ return (value !== undefined && value !== null) ? `${value}` : '';
+}
+
+export function getValueInRange(value: number, max: number, min = 0): number {
+ return Math.max(Math.min(value, max), min);
+}
+
+export function isString(value: any): boolean {
+ return typeof value === 'string';
+}
+
+export function isNumber(value: any): boolean {
+ return !isNaN(toInteger(value));
+}
+
+export function isInteger(value: any): boolean {
+ return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
+}
+
+export function isDefined(value: any): boolean {
+ return value !== undefined && value !== null;
+}
+
+export function padNumber(value: number) {
+ if (isNumber(value)) {
+ return `0${value}`.slice(-2);
+ } else {
+ return '';
+ }
+}
+
+export function regExpEscape(text) {
+ return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
+}
+
+
+export function parseDate(date: Date, format) {
+ let o = {
+ 'M+': date.getMonth() + 1, // month
+ 'd+': date.getDate(), // day
+ 'h+': date.getHours(), // hour
+ 'm+': date.getMinutes(), // minute
+ 's+': date.getSeconds(), // second
+ 'q+': Math.floor((date.getMonth() + 3) / 3), // quarter
+ 'S': date.getMilliseconds() // millisecond
+ };
+ if (/(y+)/.test(format)) {
+ format = format.replace(RegExp.$1,
+ (date.getFullYear() + '').substr(4 - RegExp.$1.length));
+ }
+ for (let k in o) {
+ if (new RegExp('(' + k + ')').test(format)) {
+ format = format.replace(RegExp.$1,
+ RegExp.$1.length === 1 ? o[k] :
+ ('00' + o[k]).substr(('' + o[k]).length));
+ }
+ }
+ return format;
+}
+