Skip to content

Commit

Permalink
Merge pull request #10 from TomokiMiyauci/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
TomokiMiyauci authored May 31, 2023
2 parents 08bbcd0 + 3b777aa commit 8144b16
Show file tree
Hide file tree
Showing 20 changed files with 443 additions and 66 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# [1.4.0-beta.1](https://github.com/TomokiMiyauci/isx/compare/1.3.1...1.4.0-beta.1) (2023-05-31)


### Features

* **number:** add positive integer validation function ([fa38d96](https://github.com/TomokiMiyauci/isx/commit/fa38d96deaf1bcdbd454d449cd66dc9d538e020d))
* **number:** mark as duplicated ([a774643](https://github.com/TomokiMiyauci/isx/commit/a7746438d393cc39c2d7276e621478012bd43f17))
* **numeric:** add numeric validators ([51999df](https://github.com/TomokiMiyauci/isx/commit/51999dfa2d7e069543747337af79179f4292744d))

## [1.3.1](https://github.com/TomokiMiyauci/isx/compare/1.3.0...1.3.1) (2023-04-20)


Expand Down
138 changes: 78 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,90 +312,123 @@ assertEquals(isRegExp(new RegExp("")), true);
assertEquals(isRegExp({}), false);
```

## Number subtypes
## Numeric subtypes

Validates a subtype of `number`. All validate functions must satisfy ⊂ `number`.
Validates a subtype of `number` or `bigint`.

### isOdd
### isPositiveNumber

[![badge](https://deno.bundlejs.com/?q=https://deno.land/x/isx/number/is_odd.ts&badge=)](https://bundlejs.com/?q=https%3A%2F%2Fdeno.land%2Fx%2Fisx%2Fnumber%2Fis_odd.ts)
[![badge](https://deno.bundlejs.com/?q=https://deno.land/x/isx/numeric/is_positive_number.ts&badge=)](https://bundlejs.com/?q=https%3A%2F%2Fdeno.land%2Fx%2Fisx%2Fnumeric%2Fis_positive_number.ts)

Whether the input is odd or not.
Whether the input is positive number or not.

```ts
import { isOdd } from "https://deno.land/x/isx@$VERSION/number/is_odd.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(isOdd(1), true);
assertEquals(isOdd(0), false);
import { isPositiveNumber } from "https://deno.land/x/isx@$VERSION/numeric/is_positive_number.ts";
import { assert, assertFalse } from "https://deno.land/std/testing/asserts.ts";
assert(isPositiveNumber(1));
assert(isPositiveNumber(Infinity));
assertFalse(isPositiveNumber(0));
```

### isEven
### isNonPositiveNumber

[![badge](https://deno.bundlejs.com/?q=https://deno.land/x/isx/number/is_even.ts&badge=)](https://bundlejs.com/?q=https%3A%2F%2Fdeno.land%2Fx%2Fisx%2Fnumber%2Fis_even.ts)
[![badge](https://deno.bundlejs.com/?q=https://deno.land/x/isx/numeric/is_non_positive_number.ts&badge=)](https://bundlejs.com/?q=https%3A%2F%2Fdeno.land%2Fx%2Fisx%2Fnumeric%2Fis_non_positive_number.ts)

Whether the input is even or not.
Whether the input is non-positive number or not. Non-positive number means less
than or equal to zero.

```ts
import { isEven } from "https://deno.land/x/isx@$VERSION/number/is_even.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(isEven(0), true);
assertEquals(isEven(1), false);
import { isNonPositiveNumber } from "https://deno.land/x/isx@$VERSION/numeric/is_non_positive_number.ts";
import { assert, assertFalse } from "https://deno.land/std/testing/asserts.ts";
assert(isNonPositiveNumber(0));
assert(isNonPositiveNumber(-1));
assertFalse(isNonPositiveNumber(1));
```

### isPositiveNumber
### isNegativeNumber

[![badge](https://deno.bundlejs.com/?q=https://deno.land/x/isx/number/is_positive_number.ts&badge=)](https://bundlejs.com/?q=https%3A%2F%2Fdeno.land%2Fx%2Fisx%2Fnumber%2Fis_positive_number.ts)
[![badge](https://deno.bundlejs.com/?q=https://deno.land/x/isx/numeric/is_negative_number.ts&badge=)](https://bundlejs.com/?q=https%3A%2F%2Fdeno.land%2Fx%2Fisx%2Fnumeric%2Fis_negative_number.ts)

Whether the input is positive number or not.
Whether the input is negative number or not.

```ts
import { isPositiveNumber } from "https://deno.land/x/isx@$VERSION/number/is_positive_number.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(isPositiveNumber(1), true);
assertEquals(isPositiveNumber(0), false);
import { isNegativeNumber } from "https://deno.land/x/isx@$VERSION/numeric/is_negative_number.ts";
import { assert, assertFalse } from "https://deno.land/std/testing/asserts.ts";
assert(isNegativeNumber(-1));
assertFalse(isNegativeNumber(0));
```

### isNonPositiveNumber
### isNonNegativeNumber

[![badge](https://deno.bundlejs.com/?q=https://deno.land/x/isx/number/is_non_positive_number.ts&badge=)](https://bundlejs.com/?q=https%3A%2F%2Fdeno.land%2Fx%2Fisx%2Fnumber%2Fis_non_positive_number.ts)
[![badge](https://deno.bundlejs.com/?q=https://deno.land/x/isx/numeric/is_non_negative_number.ts&badge=)](https://bundlejs.com/?q=https%3A%2F%2Fdeno.land%2Fx%2Fisx%2Fnumeric%2Fis_non_negative_number.ts)

Whether the input is non-positive number or not. Non-positive number means less
than or equal to zero.
Whether the input is non-negative number or not. Non-negative number means
greater than or equal to zero.

```ts
import { isNonPositiveNumber } from "https://deno.land/x/isx@$VERSION/number/is_non_positive_number.ts";
import { isNonNegativeNumber } from "https://deno.land/x/isx@$VERSION/numeric/is_non_negative_number.ts";
import { assert, assertFalse } from "https://deno.land/std/testing/asserts.ts";
assert(isNonNegativeNumber(0));
assert(isNonNegativeNumber(1));
assertFalse(isNonNegativeNumber(-1));
```

### isUnitInterval

[![badge](https://deno.bundlejs.com/?q=https://deno.land/x/isx/numeric/is_unit_interval.ts&badge=)](https://bundlejs.com/?q=https%3A%2F%2Fdeno.land%2Fx%2Fisx%2Fnumeric%2Fis_unit_interval.ts)

Whether the input is unit interval or not. The unit interval refers to the
interval between 0 and 1 on the real number line.

```ts
import { isUnitInterval } from "https://deno.land/x/isx@$VERSION/numeric/is_unit_interval.ts";
import { assert, assertFalse } from "https://deno.land/std/testing/asserts.ts";
assert(isUnitInterval(0));
assert(isUnitInterval(1.0));
assertFalse(isUnitInterval(-1));
```

## Number subtypes

Validates a subtype of `number`. All validate functions must satisfy ⊂ `number`.

### isOdd

[![badge](https://deno.bundlejs.com/?q=https://deno.land/x/isx/number/is_odd.ts&badge=)](https://bundlejs.com/?q=https%3A%2F%2Fdeno.land%2Fx%2Fisx%2Fnumber%2Fis_odd.ts)

Whether the input is odd or not.

```ts
import { isOdd } from "https://deno.land/x/isx@$VERSION/number/is_odd.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(isNonPositiveNumber(0), true);
assertEquals(isNonPositiveNumber(-1), true);
assertEquals(isNonPositiveNumber(1), false);
assertEquals(isOdd(1), true);
assertEquals(isOdd(0), false);
```

### isNegativeNumber
### isEven

[![badge](https://deno.bundlejs.com/?q=https://deno.land/x/isx/number/is_negative_number.ts&badge=)](https://bundlejs.com/?q=https%3A%2F%2Fdeno.land%2Fx%2Fisx%2Fnumber%2Fis_negative_number.ts)
[![badge](https://deno.bundlejs.com/?q=https://deno.land/x/isx/number/is_even.ts&badge=)](https://bundlejs.com/?q=https%3A%2F%2Fdeno.land%2Fx%2Fisx%2Fnumber%2Fis_even.ts)

Whether the input is negative number or not.
Whether the input is even or not.

```ts
import { isNegativeNumber } from "https://deno.land/x/isx@$VERSION/number/is_negative_number.ts";
import { isEven } from "https://deno.land/x/isx@$VERSION/number/is_even.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(isNegativeNumber(-1), true);
assertEquals(isNegativeNumber(0), false);
assertEquals(isEven(0), true);
assertEquals(isEven(1), false);
```

### isNonNegativeNumber
### isPositiveInteger

[![badge](https://deno.bundlejs.com/?q=https://deno.land/x/isx/number/is_non_negative_number.ts&badge=)](https://bundlejs.com/?q=https%3A%2F%2Fdeno.land%2Fx%2Fisx%2Fnumber%2Fis_non_negative_number.ts)
[![badge](https://deno.bundlejs.com/?q=https://deno.land/x/isx/number/is_positive_integer.ts&badge=)](https://bundlejs.com/?q=https%3A%2F%2Fdeno.land%2Fx%2Fisx%2Fnumber%2Fis_positive_integer.ts)

Whether the input is non-negative number or not. Non-negative number means
greater than or equal to zero.
Whether the input is positive integer or not.

```ts
import { isNonNegativeNumber } from "https://deno.land/x/isx@$VERSION/number/is_non_negative_number.ts";
import { isPositiveInteger } from "https://deno.land/x/isx@$VERSION/number/is_positive_integer.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(isNonNegativeNumber(0), true);
assertEquals(isNonNegativeNumber(1), true);
assertEquals(isNonNegativeNumber(-1), false);
assertEquals(isPositiveInteger(1), true);
assertEquals(isPositiveInteger(0), false);
```

### isNonNegativeInteger
Expand All @@ -412,21 +445,6 @@ assertEquals(isNonNegativeInteger(1.0), true);
assertEquals(isNonNegativeInteger(-1), false);
```

### isUnitInterval

[![badge](https://deno.bundlejs.com/?q=https://deno.land/x/isx/number/is_unit_interval.ts&badge=)](https://bundlejs.com/?q=https%3A%2F%2Fdeno.land%2Fx%2Fisx%2Fnumber%2Fis_unit_interval.ts)

Whether the input is unit interval or not. The unit interval refers to the
interval between 0 and 1 on the real number line.

```ts
import { isUnitInterval } from "https://deno.land/x/isx@$VERSION/number/is_unit_interval.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(isUnitInterval(0), true);
assertEquals(isUnitInterval(1.0), true);
assertEquals(isUnitInterval(-1), false);
```

## Iterable subtypes

Validates a subtype of `Iterable`. All validate functions must satisfy ⊂
Expand Down
13 changes: 7 additions & 6 deletions _tools/publish_npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ if (import.meta.main) {
const tag = isPrerelease?.[0] ?? "latest";

const pkg = makeOptions(version);
const result = await Deno.run({
cmd: ["npm", "publish", pkg.outDir, "--tag", String(tag)],
stdout: "piped",
})
.output();
const command = new Deno.Command("npm", {
args: ["publish", pkg.outDir, "--tag", String(tag)],
});
const result = await command.output();

console.log(new TextDecoder().decode(result));
if (!result.success) {
console.error(new TextDecoder().decode(result.stderr));
}
}
2 changes: 2 additions & 0 deletions number/is_negative_number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* assertEquals(isNegativeNumber(-1), true)
* assertEquals(isNegativeNumber(0), false)
* ```
*
* @deprecated use numeric::isNegativeNumber
*/
export function isNegativeNumber(input: number): boolean {
return input < 0;
Expand Down
2 changes: 2 additions & 0 deletions number/is_non_negative_number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { isPositiveNumber } from "./is_positive_number.ts";
* assertEquals(isNonNegativeNumber(1), true);
* assertEquals(isNonNegativeNumber(-1), false);
* ```
*
* @deprecated use numeric::isNonNegativeNumber
*/
export function isNonNegativeNumber(input: number): boolean {
return input === 0 || isPositiveNumber(input);
Expand Down
2 changes: 2 additions & 0 deletions number/is_non_positive_number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { isNegativeNumber } from "./is_negative_number.ts";
* assertEquals(isNonPositiveNumber(-1), true);
* assertEquals(isNonPositiveNumber(1), false);
* ```
*
* @deprecated use numeric::isNonPositiveNumber
*/
export function isNonPositiveNumber(input: number): boolean {
return input === 0 || isNegativeNumber(input);
Expand Down
18 changes: 18 additions & 0 deletions number/is_positive_integer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2023-latest Tomoki Miyauchi. All rights reserved. MIT license.
// This module is browser compatible.

import { isPositiveNumber } from "./is_positive_number.ts";

/** Whether the input is positive integer or not.
* @param input - Any `number`.
* @example
* ```ts
* import { isPositiveInteger } from "https://deno.land/x/isx@$VERSION/number/is_positive_integer.ts";
* import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
* assertEquals(isPositiveInteger(1), true);
* assertEquals(isPositiveInteger(0), false);
* ```
*/
export function isPositiveInteger(input: number): boolean {
return Number.isInteger(input) && isPositiveNumber(input);
}
35 changes: 35 additions & 0 deletions number/is_positive_integer_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { isPositiveInteger } from "./is_positive_integer.ts";
import { assert, assertFalse, describe, it } from "../_dev_deps.ts";

describe("isPositiveInteger", () => {
it("should return true", () => {
const table: number[] = [
1,
Number.MAX_VALUE,
Number.MAX_SAFE_INTEGER,
];

table.forEach((input) => {
assert(isPositiveInteger(input));
});
});

it("should return false", () => {
const table: number[] = [
NaN,
0,
-0,
-1,
-1.1,
-Infinity,
Infinity,
1.1,
Number.NEGATIVE_INFINITY,
Number.MIN_SAFE_INTEGER,
];

table.forEach((input) => {
assertFalse(isPositiveInteger(input));
});
});
});
3 changes: 3 additions & 0 deletions number/is_positive_number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
* import { isPositiveNumber } from "https://deno.land/x/isx@$VERSION/number/is_positive_number.ts"
* import { assertEquals } from "https://deno.land/std/testing/asserts.ts"
* assertEquals(isPositiveNumber(1), true)
* assertEquals(isPositiveNumber(Infinity), true);
* assertEquals(isPositiveNumber(0), false)
* ```
*
* @deprecated use numeric::isPositiveNumber
*/
export function isPositiveNumber(input: number): boolean {
return 0 < input;
Expand Down
2 changes: 2 additions & 0 deletions number/is_unit_interval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
* assertEquals(isUnitInterval(1.0), true);
* assertEquals(isUnitInterval(-1), false);
* ```
*
* @deprecated use numeric::isUnitInterval
*/
export function isUnitInterval(input: number): boolean {
return 0 <= input && input <= 1;
Expand Down
16 changes: 16 additions & 0 deletions numeric/is_negative_number.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2023-latest Tomoki Miyauchi. All rights reserved. MIT license.
// This module is browser compatible.

/** Whether the input is negative number or not.
* @param input - Any numeric.
* @example
* ```ts
* import { isNegativeNumber } from "https://deno.land/x/isx@$VERSION/numeric/is_negative_number.ts"
* import { assert, assertFalse } from "https://deno.land/std/testing/asserts.ts"
* assert(isNegativeNumber(-1))
* assertFalse(isNegativeNumber(0))
* ```
*/
export function isNegativeNumber(input: number | bigint): boolean {
return input < 0;
}
38 changes: 38 additions & 0 deletions numeric/is_negative_number_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { isNegativeNumber } from "./is_negative_number.ts";
import { assert, assertFalse, describe, it } from "../_dev_deps.ts";

describe("isNegativeNumber", () => {
it("should return true", () => {
const table: (number | bigint)[] = [
-1,
-0.1,
-Infinity,
Number.NEGATIVE_INFINITY,
Number.MIN_SAFE_INTEGER,
-1n,
];

table.forEach((input) => {
assert(isNegativeNumber(input));
});
});

it("should return false", () => {
const table: (number | bigint)[] = [
NaN,
0,
-0,
Infinity,
0.1,
1,
Number.MAX_VALUE,
Number.MAX_SAFE_INTEGER,
0n,
1n,
];

table.forEach((input) => {
assertFalse(isNegativeNumber(input));
});
});
});
Loading

0 comments on commit 8144b16

Please sign in to comment.