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

Add typeof utility #1648

Merged
merged 1 commit into from
Apr 18, 2021
Merged

Add typeof utility #1648

merged 1 commit into from
Apr 18, 2021

Conversation

ezkemboi
Copy link
Member

What I have done

  • Added type of utility to make sure it is easy to check the type of null, object, array, date, among others.
    I.e type of {} == 'object' and type of null == 'null' and not that all are object.
  • Added tests for the same, as a way to protect any changes/breaking

@codecov
Copy link

codecov bot commented Apr 17, 2021

Codecov Report

❗ No coverage uploaded for pull request base (master@a31c116). Click here to learn what that means.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             master     #1648   +/-   ##
==========================================
  Coverage          ?   100.00%           
==========================================
  Files             ?       101           
  Lines             ?      1851           
  Branches          ?         0           
==========================================
  Hits              ?      1851           
  Misses            ?         0           
  Partials          ?         0           
Impacted Files Coverage Δ
src/lib/util/typeOf.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a31c116...3808d4c. Read the comment docs.

tux-tn
tux-tn previously approved these changes Apr 17, 2021
Copy link
Member

@tux-tn tux-tn left a comment

Choose a reason for hiding this comment

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

LGTM ! Will be helpful in many places 👍

assert.strictEqual(typeOf(null), 'null');
assert.strictEqual(typeOf({}), 'object');
assert.strictEqual(typeOf(new Date()), 'date');
assert.strictEqual(typeOf('ezkemboi'), 'string');
Copy link
Member

Choose a reason for hiding this comment

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

BTW, could you add one more test for String('kemboi') ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I will add

Copy link
Member Author

Choose a reason for hiding this comment

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

Added the test @profnandaa

@ezkemboi
Copy link
Member Author

ezkemboi commented Apr 18, 2021

I will try to identify the areas that this can help and see if I can create PR making those necessary changes.
I will be keen on regressions.

Cc. @profnandaa and @tux-tn

@profnandaa profnandaa merged commit 1fa0959 into validatorjs:master Apr 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants