[PORTAL-7] Rebase
[portal.git] / ecomp-portal-FE-common / client / app / services / utils / utils.service.js
1 /*-
2  * ================================================================================
3  * eCOMP Portal
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ================================================================================
19  */
20 'use strict';
21
22 (function () {
23     class UtilsService {
24         constructor($log) {
25             this.$log = $log;
26         }
27
28         isRunningInLocalDevEnv() {
29             var myHostName;
30             myHostName = location.host;
31
32             if (myHostName.includes('localhost')) {
33                 return true;
34             } else {
35                 return false;
36             }
37         }
38
39         isValidJSON(json) {
40             try {
41                 var checkJSON = JSON.parse(JSON.stringify(json));
42                 if (checkJSON && typeof checkJSON === 'object' && checkJSON !== null) {
43                     // this.$log.debug('UtilsService::isValidJSON: JSON is valid!');
44                     return true;
45                 }
46             } catch (err) {
47                 this.$log.debug('UtilsService::isValidJSON: json passed is not valid: ' + JSON.stringify(err));
48             }
49             return false;
50         }
51
52     }
53     UtilsService.$inject = ['$log'];
54     angular.module('ecompApp').service('utilsService', UtilsService)
55 })();