forked from emberjs/ember.js
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Ember.isPresent as inverse of Ember.isBlank
- Loading branch information
Amiel Martin
committed
Jul 10, 2014
1 parent
a47897e
commit 065921e
Showing
5 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,33 @@ | |||
import isBlank from 'ember-metal/is_blank'; | |||
var isPresent; | |||
|
|||
if (Ember.FEATURES.isEnabled('ember-metal-is-present')) { | |||
/** | |||
A value is present if it not `isBlank`. | |||
```javascript | |||
Ember.isPresent(); // false | |||
Ember.isPresent(null); // false | |||
Ember.isPresent(undefined); // false | |||
Ember.isPresent(''); // false | |||
Ember.isPresent([]); // false | |||
Ember.isPresent('\n\t'); // false | |||
Ember.isPresent(' '); // false | |||
Ember.isPresent({}); // true | |||
Ember.isPresent('\n\t Hello'); // true | |||
Ember.isPresent('Hello world'); // true | |||
Ember.isPresent([1,2,3]); // true | |||
``` | |||
@method isPresent | |||
@for Ember | |||
@param {Object} obj Value to test | |||
@return {Boolean} | |||
@since 1.7.0 | |||
*/ | |||
isPresent = function isPresent(obj) { | |||
return !isBlank(obj); | |||
}; | |||
} | |||
|
|||
export default isPresent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,27 @@ | |||
import isPresent from 'ember-metal/is_present'; | |||
|
|||
if (Ember.FEATURES.isEnabled('ember-metal-is-present')) { | |||
QUnit.module("Ember.isPresent"); | |||
|
|||
test("Ember.isPresent", function() { | |||
var string = "string", fn = function() {}, | |||
object = {length: 0}; | |||
|
|||
equal(false, isPresent(), "for no params"); | |||
equal(false, isPresent(null), "for null"); | |||
equal(false, isPresent(undefined), "for undefined"); | |||
equal(false, isPresent(""), "for an empty String"); | |||
equal(false, isPresent(" "), "for a whitespace String"); | |||
equal(false, isPresent("\n\t"), "for another whitespace String"); | |||
equal(true, isPresent("\n\t Hi"), "for a String with whitespaces"); | |||
equal(true, isPresent(true), "for true"); | |||
equal(true, isPresent(false), "for false"); | |||
equal(true, isPresent(string), "for a String"); | |||
equal(true, isPresent(fn), "for a Function"); | |||
equal(true, isPresent(0), "for 0"); | |||
equal(false, isPresent([]), "for an empty Array"); | |||
equal(true, isPresent({}), "for an empty Object"); | |||
equal(false, isPresent(object), "for an Object that has zero 'length'"); | |||
equal(true, isPresent([1,2,3]), "for a non-empty array"); | |||
}); | |||
} |