Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added formats for "empty" and "year" #2

Merged
merged 6 commits into from
Feb 21, 2015

Conversation

ewsheng
Copy link
Contributor

@ewsheng ewsheng commented Feb 18, 2015

No description provided.

assert.equal(tr(TEST_OBJECT, TEST_NOT_EMPTY_FIELD_TRUE), true);
assert.equal(tr(TEST_OBJECT, TEST_NOT_EMPTY_FIELD_FALSE), false);
});
it('should return true/false when a test field is empty', function () {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this also work if emptyField: null/false/0?

What if emptyField isn't defined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emptyField is an arbitrary test field. If empty is not defined, the test will not be triggered.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ha true, my bad

return testValue is objectValue
objectValue = JSON.stringify(objectValue) # match in stringified arrays and objects too
re = RegExp testValue, "im"
match = re.test objectValue
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just do return re.test objectValue no need to store match and return it right after

return (objectValue is null) or (objectValue is 0) or (objectValue.length is 0) or (Object.keys(objectValue).length is 0)

else #return true if objectValue is not empty
return not ((objectValue is null) or (objectValue is 0) or (objectValue.length is 0) or (Object.keys(objectValue).length is 0))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can merge this and the above if statment by doing checking if isEmpty. Then return if shouldBeEmpty return isEmpty else return not isEmpty

swarajban added a commit that referenced this pull request Feb 21, 2015
Added formats for "empty" and "year"
@swarajban swarajban merged commit 594dca8 into swarajban:master Feb 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants