Skip to content

Commit

Permalink
Add a function for getting type that covers 'null' case
Browse files Browse the repository at this point in the history
  • Loading branch information
mohsen1 committed Dec 16, 2014
1 parent f53a078 commit e9d99ba
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 29 deletions.
2 changes: 1 addition & 1 deletion dist/json-formatter.css
@@ -1,7 +1,7 @@
/*!
* jsonformatter
*
* Version: 0.2.5 - 2014-12-16T18:51:42.214Z
* Version: 0.2.6 - 2014-12-16T21:33:23.610Z
* License: MIT
*/

Expand Down
21 changes: 8 additions & 13 deletions dist/json-formatter.js
@@ -1,7 +1,7 @@
/*!
* jsonformatter
*
* Version: 0.2.5 - 2014-12-16T18:51:45.410Z
* Version: 0.2.6 - 2014-12-16T21:33:46.343Z
* License: MIT
*/

Expand Down Expand Up @@ -31,6 +31,11 @@ angular.module('jsonFormatter', ['RecursionHelper'])
}
}

function getType(object) {
if (object === null) { return 'null'; }
return typeof object;
}

function link(scope, element, attributes) {
scope.isArray = function () {
return Array.isArray(scope.json);
Expand All @@ -45,22 +50,12 @@ angular.module('jsonFormatter', ['RecursionHelper'])
return Object.keys(scope.json);
}
};
scope.type = typeof scope.json;
scope.type = getType(scope.json);
scope.hasKey = typeof scope.key !== 'undefined';
scope.getConstructorName = function(){
return getObjectName(scope.json);
};

// Set custom type for null
if (scope.json === null){
scope.type = 'null';
}

// Set custom type for null
if (scope.json === undefined){
scope.type = 'undefined';
}

if (scope.type === 'string'){

// Add custom type for date
Expand Down Expand Up @@ -99,7 +94,7 @@ angular.module('jsonFormatter', ['RecursionHelper'])
};

scope.parseValue = function (value){
scope.type = typeof scope.json;
scope.type = getType(scope.json);
if (scope.type === 'null') {
return 'null';
}
Expand Down
2 changes: 1 addition & 1 deletion dist/json-formatter.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/json-formatter.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 7 additions & 12 deletions src/json-formatter.js
Expand Up @@ -23,6 +23,11 @@ angular.module('jsonFormatter', ['RecursionHelper'])
}
}

function getType(object) {
if (object === null) { return 'null'; }
return typeof object;
}

function link(scope, element, attributes) {
scope.isArray = function () {
return Array.isArray(scope.json);
Expand All @@ -37,22 +42,12 @@ angular.module('jsonFormatter', ['RecursionHelper'])
return Object.keys(scope.json);
}
};
scope.type = typeof scope.json;
scope.type = getType(scope.json);
scope.hasKey = typeof scope.key !== 'undefined';
scope.getConstructorName = function(){
return getObjectName(scope.json);
};

// Set custom type for null
if (scope.json === null){
scope.type = 'null';
}

// Set custom type for null
if (scope.json === undefined){
scope.type = 'undefined';
}

if (scope.type === 'string'){

// Add custom type for date
Expand Down Expand Up @@ -91,7 +86,7 @@ angular.module('jsonFormatter', ['RecursionHelper'])
};

scope.parseValue = function (value){
scope.type = typeof scope.json;
scope.type = getType(scope.json);
if (scope.type === 'null') {
return 'null';
}
Expand Down

0 comments on commit e9d99ba

Please sign in to comment.