diff options
author | Thom Williams <thom.williams@pnnl.gov> | 2016-08-19 13:46:29 -0700 |
---|---|---|
committer | Thom Williams <thom.williams@pnnl.gov> | 2016-08-19 13:46:29 -0700 |
commit | 0a05cb38232e77a3d26c94b3d7d0ec0209240ffe (patch) | |
tree | 13278f33c473a4bb3002dbddd2d73b4815d4f874 | |
parent | 7b9d29bcf54887f002c4814757587ce078a64aab (diff) | |
download | yamljs-0a05cb38232e77a3d26c94b3d7d0ec0209240ffe.tar.gz |
Simplify source by adding Utils.isEmptyObject method
-rw-r--r-- | src/Utils.coffee | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/Utils.coffee b/src/Utils.coffee index 1c36faa..568a748 100644 --- a/src/Utils.coffee +++ b/src/Utils.coffee @@ -79,15 +79,23 @@ class Utils return str.replace(regexRight, '') - # Checks if the given value is empty (null, undefined, empty string, string '0') + # Checks if the given value is empty (null, undefined, empty string, string '0', empty Array, empty Object) # # @param [Object] value The value to check # # @return [Boolean] true if the value is empty # @isEmpty: (value) -> - return not(value) or value is '' or value is '0' or (value instanceof Array and value.length is 0) or (value instanceof Object and (k for own k of value).length is 0) + return not(value) or value is '' or value is '0' or (value instanceof Array and value.length is 0) or @isEmptyObject(value) + # Checks if the given value is an empty object + # + # @param [Object] value The value to check + # + # @return [Boolean] true if the value is empty and is an object + # + @isEmptyObject: (value) -> + return value instanceof Object and (k for own k of value).length is 0 # Counts the number of occurences of subString inside string # |