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

feat: add isValidNumber, isNotValidNumber #247

Merged
merged 5 commits into from
Dec 22, 2017

Conversation

Undistraction
Copy link
Collaborator

@Undistraction Undistraction commented Dec 20, 2017

  • adds isValidNumber which tests whether a value is a number that is not either NaN, Infinity or -Infinity.
  • adds isNotValidNumber which is the complement of isValidNumber.
  • adds isInvalidNumber which is aliased to isNotValidNumber.

Ref #235

Please note the following:

Typescript

I haven't added the three new functions to index.d.ts as I have no familiarity with TypeScript and I would be doing so blindly.

Docs

I have set the @since versions at X.X.X as I don't know what version you will include this feat in.

Tests

npm test

I have one failing test which was already failing when I pulled the branch and is unrelated to my changes. If you want me to dig deeper please let me know and I'll see if I can work out why it's failing on my machine:

isPromise when value is an instance of native Promise should return true:

      AssertionError: 'false' === 'true'
      + expected - actual

      -false
      +true

npm test:ramda

Initally failed because of unmet peer dependency of ajv. I upgraded ajv to @5 and all pass other than the test outlined above.

@Undistraction Undistraction changed the title Feat/is valid number Feat/isValidNumber Dec 20, 2017
@Undistraction Undistraction changed the title Feat/isValidNumber add: isValidNumber, isNotValidNumber, isInvalidNumber Dec 20, 2017
@Undistraction Undistraction changed the title add: isValidNumber, isNotValidNumber, isInvalidNumber feat: add isValidNumber, isNotValidNumber, isInvalidNumber Dec 20, 2017
src/index.js Outdated
@@ -53,6 +53,9 @@ export { default as isInteger } from './isInteger';
export { default as isNotInteger } from './isNotInteger';
export { default as isFloat } from './isFloat';
export { default as isNotFloat } from './isNotFloat';
export { default as isValidNumber } from './isValidNumber';
export { default as isNotValidNumber } from './isNotValidNumber';
export { default as isInvalidNumber } from './isNotValidNumber'; // alias of isNotValidNumber
Copy link
Owner

Choose a reason for hiding this comment

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

IMHO this is somehow misleading naming for isInvalidNumber. The name indicates that the value checked by the predicate will be number, but not a valid one e.g. NaN, Infinity.

I would imagine isInvalidNumber to have the following signature

const isInvalidNumber = both(isNumber, isNotValidNumber);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK. Agreed so:

  1. Do we need an alias for isNotValidNumber? I think probably not.
  2. Do we want an isInvalidNumber function that only returns true for NaN, Infinity and -Infinity? I'd say it's probably pretty esoteric.

import { complement } from 'ramda';
import isValidNumber from './isValidNumber';

/* eslint-disable max-len */
Copy link
Owner

Choose a reason for hiding this comment

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

Drop this. Your lines length should not go over 100 chars

* RA.isNotValidNumber(1); //=> false
* RA.isNotValidNumber(''); //=> true
*/
/* eslint-enable max-len */
Copy link
Owner

Choose a reason for hiding this comment

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

Drop this. Your lines length should not go over 100 chars

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure what you mean. What should I drop?

Copy link
Owner

Choose a reason for hiding this comment

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

/* eslint-enable max-len */

Copy link
Collaborator Author

@Undistraction Undistraction Dec 20, 2017

Choose a reason for hiding this comment

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

Ah. Sorry. Thought you'd wrapped all your jsdoc comment blocks in the enable/disable comments, but was just the one I cribbed from.

*
* @func isNotValidNumber
* @memberOf RA
* @since {@link https://char0n.github.io/ramda-adjunct/X.X.X|vX.X.X}
Copy link
Owner

Choose a reason for hiding this comment

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

/2.2.0/v2.2.0

@@ -0,0 +1,24 @@
import { complement } from 'ramda';
Copy link
Owner

Choose a reason for hiding this comment

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

divide absolute and relative imports by one empty line pls

*
* @func isValidNumber
* @memberOf RA
* @since {@link https://char0n.github.io/ramda-adjunct/X.X.X|vX.X.X}
Copy link
Owner

Choose a reason for hiding this comment

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

2.2.0

* @memberOf RA
* @since {@link https://char0n.github.io/ramda-adjunct/X.X.X|vX.X.X}
* @category Type
* @sig * -> Boolean
Copy link
Owner

Choose a reason for hiding this comment

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

Add

@see {@link RA.isNotValidNumber|isNotValidNumber}

import eq from './shared/eq';
import args from './shared/arguments';
import Symbol from './shared/Symbol';

Copy link
Owner

Choose a reason for hiding this comment

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

insert empty line

});
});

describe('isInvalidNumber', function() {
Copy link
Owner

Choose a reason for hiding this comment

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

Please drop this one. We'll not deal with isInvalidNumber in this PR.

import eq from './shared/eq';
import args from './shared/arguments';
import Symbol from './shared/Symbol';

Copy link
Owner

Choose a reason for hiding this comment

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

insert another empty line

@char0n
Copy link
Owner

char0n commented Dec 20, 2017

Regarding the isPromise not passing. I'am not able to reproduce. That is really really strange because these tests are running inside node.

@char0n
Copy link
Owner

char0n commented Dec 20, 2017

Typescript signatures will looks like this:

/**
* ... description
*/
isValidNumber(val: any): boolean;

/**
* ... description
*/
isNotValidNumber(val: any): boolean;

* @return {Boolean}
* @example
*
* RA.isValidNumber(1); //=> true
Copy link
Owner

Choose a reason for hiding this comment

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

I'd add examples also for NaN, Infinity and -Infinity

* RA.isValidNumber(1); //=> true
* RA.isValidNumber(''); //=> false
*/
/* eslint-enable max-len */
Copy link
Owner

Choose a reason for hiding this comment

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

Drop this. Your lines length should not go over 100 chars

@char0n char0n added the feature label Dec 20, 2017
@char0n char0n added this to the v2.2.0 milestone Dec 20, 2017
@Undistraction Undistraction changed the title feat: add isValidNumber, isNotValidNumber, isInvalidNumber feat: add isValidNumber, isNotValidNumber Dec 22, 2017
@Undistraction
Copy link
Collaborator Author

Undistraction commented Dec 22, 2017

All changes made and I have removed alias isInvalidNumber.

Copy link
Owner

@char0n char0n left a comment

Choose a reason for hiding this comment

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

LGTM. Good job and thank you for the contribution!

@char0n char0n merged commit d94c1b5 into char0n:master Dec 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants