Skip to content

Commit

Permalink
fix: typings for gt, gte, lt, lte utilities (#723)
Browse files Browse the repository at this point in the history
  • Loading branch information
sashkashishka authored Feb 18, 2024
1 parent d7ed1e7 commit 79013c7
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 356 deletions.
247 changes: 24 additions & 223 deletions .github/README.md

Large diffs are not rendered by default.

134 changes: 24 additions & 110 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6525,10 +6525,14 @@ It returns a new list by applying a `predicate` function to all elements of `lis

### insert

<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20list%20%3D%20%5B'a'%2C%20'b'%2C%20'c'%2C%20'd'%2C%20'e'%5D%3B%0Aconst%20result%20%3D%20R.insert(2%2C%20'x'%2C%20list)%3B%0A%2F%2F%20%3D%3E%20%5B'a'%2C%20'b'%2C%20'x'%2C%20'c'%2C%20'd'%2C%20'e'%5D">Try this <strong>R.insert</strong> example in Rambda REPL</a>

[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#insert)

### insertAll

<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20list%20%3D%20%5B'a'%2C%20'b'%2C%20'c'%2C%20'd'%2C%20'e'%5D%3B%0Aconst%20result%20%3D%20R.insertAll(2%2C%20%5B'x'%2C%20'y'%2C%20'z'%5D%2C%20list)%3B%0A%2F%2F%20%3D%3E%20%5B'a'%2C%20'b'%2C%20'x'%2C%20'y'%2C%20'z'%2C%20'c'%2C%20'd'%2C%20'e'%5D">Try this <strong>R.insertAll</strong> example in Rambda REPL</a>

[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#insertAll)

### intersection
Expand Down Expand Up @@ -6589,6 +6593,12 @@ export function isEmpty(input){
return false
if (!input) return true

if (type(input.isEmpty) === 'Function') {
return input.isEmpty();
} else if (input.isEmpty) {
return !!input.isEmpty;
}

if (inputType === 'Object'){
return Object.keys(input).length === 0
}
Expand Down Expand Up @@ -6623,6 +6633,10 @@ test('happy', () => {
expect(isEmpty(0)).toBeFalse()
expect(isEmpty(NaN)).toBeFalse()
expect(isEmpty([ '' ])).toBeFalse()
expect(isEmpty({ isEmpty: false})).toBeFalse()
expect(isEmpty({ isEmpty: () => false})).toBeFalse()
expect(isEmpty({ isEmpty: true})).toBeTrue()
expect(isEmpty({ isEmpty: () => true})).toBeTrue()
})
```

Expand Down Expand Up @@ -6702,6 +6716,8 @@ test('happy', () => {

### isNotNil

<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20%5B%0A%20%20R.isNotNil(null)%2C%0A%20%20R.isNotNil(undefined)%2C%0A%20%20R.isNotNil(%5B%5D)%2C%0A%5D%0A%2F%2F%20%3D%3E%20%5Bfalse%2C%20false%2C%20true%5D">Try this <strong>R.isNotNil</strong> example in Rambda REPL</a>

[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#isNotNil)

### join
Expand Down Expand Up @@ -8279,6 +8295,8 @@ describe('R.mergeAll', () => {

### mergeDeepLeft

<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20R.mergeDeepLeft(%0A%20%20%7Ba%3A%20%7Bb%3A%201%7D%7D%2C%0A%20%20%7Ba%3A%20%7Bb%3A%202%2C%20c%3A%203%7D%7D%0A)%0A%2F%2F%20%3D%3E%20%7Ba%3A%20%7Bb%3A%201%2C%20c%3A%203%7D%7D">Try this <strong>R.mergeDeepLeft</strong> example in Rambda REPL</a>

[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#mergeDeepLeft)

### mergeDeepRight
Expand Down Expand Up @@ -8990,120 +9008,10 @@ describe('R.modify', () => {

### modifyPath

```typescript

modifyPath<T extends Record<string, unknown>>(path: Path, fn: (x: any) => unknown, object: Record<string, unknown>): T
```

It changes a property of object on the base of provided path and transformer function.

<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20R.modifyPath('a.b.c'%2C%20x%3D%3E%20x%2B1%2C%20%7Ba%3A%7Bb%3A%20%7Bc%3A1%7D%7D%7D)%0A%2F%2F%20%3D%3E%20%7Ba%3A%7Bb%3A%20%7Bc%3A2%7D%7D%7D">Try this <strong>R.modifyPath</strong> example in Rambda REPL</a>

<details>

<summary>All TypeScript definitions</summary>

```typescript
modifyPath<T extends Record<string, unknown>>(path: Path, fn: (x: any) => unknown, object: Record<string, unknown>): T;
modifyPath<T extends Record<string, unknown>>(path: Path, fn: (x: any) => unknown): (object: Record<string, unknown>) => T;
modifyPath<T extends Record<string, unknown>>(path: Path): (fn: (x: any) => unknown) => (object: Record<string, unknown>) => T;
```

</details>

<details>

<summary><strong>R.modifyPath</strong> source</summary>

```javascript
import { createPath } from './_internals/createPath.js'
import { isArray } from './_internals/isArray.js'
import { assoc } from './assoc.js'
import { curry } from './curry.js'
import { path as pathModule } from './path.js'

export function modifyPathFn(
pathInput, fn, object
){
const path = createPath(pathInput)
if (path.length === 1){
return {
...object,
[ path[ 0 ] ] : fn(object[ path[ 0 ] ]),
}
}
if (pathModule(path, object) === undefined) return object

const val = modifyPath(
Array.prototype.slice.call(path, 1),
fn,
object[ path[ 0 ] ]
)
if (val === object[ path[ 0 ] ]){
return object
}

return assoc(
path[ 0 ], val, object
)
}

export const modifyPath = curry(modifyPathFn)
```

</details>

<details>

<summary><strong>Tests</strong></summary>

```javascript
import { modifyPath } from './modifyPath.js'

test('happy', () => {
const result = modifyPath(
'a.b.c', x => x + 1, { a : { b : { c : 1 } } }
)
expect(result).toEqual({ a : { b : { c : 2 } } })
})

test('with array', () => {
const input = { foo : [ { bar : '123' } ] }
const result = modifyPath(
'foo.0.bar', x => x + 'foo', input
)
expect(result).toEqual({ foo : { 0 : { bar : '123foo' } } })
})
```

</details>

<details>

<summary><strong>TypeScript</strong> test</summary>

```typescript
import {modifyPath} from 'rambda'

const obj = {a: {b: {c: 1}}}

describe('R.modifyPath', () => {
it('happy', () => {
const result = modifyPath('a.b.c', (x: number) => x + 1, obj)
result // $ExpectType Record<string, unknown>
})
it('explicit return type', () => {
interface Foo extends Record<string, unknown> {
a: 1,
}
const result = modifyPath<Foo>('a.b.c', (x: number) => x + 1, obj)
result // $ExpectType Foo
})
})
```

</details>

[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#modifyPath)

### modulo
Expand Down Expand Up @@ -11093,6 +11001,8 @@ describe('R.paths', () => {

### pathSatisfies

<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20R.pathSatisfies(%0A%20%20x%20%3D%3E%20x%20%3E%200%2C%0A%20%20%5B'a'%2C%20'b'%2C%20'c'%5D%2C%0A%20%20%7Ba%3A%20%7Bb%3A%20%7Bc%3A%201%7D%7D%7D%0A)%0A%2F%2F%20%3D%3E%20true">Try this <strong>R.pathSatisfies</strong> example in Rambda REPL</a>

[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#pathSatisfies)

### pick
Expand Down Expand Up @@ -11467,6 +11377,8 @@ describe('R.pickAll with string as props input', () => {

### pickBy

<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20R.pickBy(%0A%20%20x%20%3D%3E%20x%20%3E%201%2C%0A%20%20%7Ba%3A%201%2C%20b%3A%202%2C%20c%3A%203%7D%0A)%0A%2F%2F%20%3D%3E%20%7Bb%3A%202%2C%20c%3A%203%7D">Try this <strong>R.pickBy</strong> example in Rambda REPL</a>

[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#pickBy)

### pipe
Expand Down Expand Up @@ -14158,6 +14070,8 @@ test('happy', () => {

### swap

<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20R.swap(1%2C%202%2C%20%5B1%2C%202%2C%203%5D)%0A%2F%2F%20%3D%3E%20%5B1%2C%203%2C%202%5D">Try this <strong>R.swap</strong> example in Rambda REPL</a>

[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#swap)

### symmetricDifference
Expand Down
4 changes: 1 addition & 3 deletions dist/rambda.js
Original file line number Diff line number Diff line change
Expand Up @@ -1538,7 +1538,7 @@ function isEmpty(input) {
if (type(input.isEmpty) === 'Function') {
return input.isEmpty();
} else if (input.isEmpty) {
return input.isEmpty;
return !!input.isEmpty;
}
if (inputType === 'Object') {
return Object.keys(input).length === 0;
Expand Down Expand Up @@ -2710,8 +2710,6 @@ exports.startsWith = startsWith;
exports.subtract = subtract;
exports.sum = sum;
exports.swap = swap;
exports.swapArrayOrString = swapArrayOrString;
exports.swapFn = swapFn;
exports.symmetricDifference = symmetricDifference;
exports.tail = tail;
exports.take = take;
Expand Down
2 changes: 1 addition & 1 deletion dist/rambda.umd.js

Large diffs are not rendered by default.

25 changes: 15 additions & 10 deletions files/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5855,18 +5855,19 @@ Notes:
*/
// @SINGLE_MARKER
export function gt<T>(x: T): T;
export function gt<T, U>(x: T, y: U): boolean;
export function gt<T, U>(x: T): (y: U) => boolean;

/*
Method: lt
Method: gte
Explanation:
Example:
```
const result = [R.lt(2, 1), R.lt(2, 3)]
// => [false, true]
const result = [R.gte(2, 1), R.gte(2, 2), R.gte(2, 3)]
// => [true, true, false]
```
Categories: Number
Expand All @@ -5875,18 +5876,19 @@ Notes:
*/
// @SINGLE_MARKER
export function lt<T>(x: T): T;
export function gte<T, U>(x: T, y: U): boolean;
export function gte<T, U>(x: T): (y: U) => boolean;

/*
Method: gte
Method: lt
Explanation:
Example:
```
const result = [R.gte(2, 1), R.gte(2, 2), R.gte(2, 3)]
// => [true, true, false]
const result = [R.lt(2, 1), R.lt(2, 3)]
// => [false, true]
```
Categories: Number
Expand All @@ -5895,8 +5897,9 @@ Notes:
*/
// @SINGLE_MARKER
export function lt<T, U>(x: T, y: U): boolean;
export function lt<T, U>(x: T): (y: U) => boolean;

export function lte<T>(x: T): T;
/*
Method: lte
Expand All @@ -5915,7 +5918,9 @@ Notes:
*/
// @SINGLE_MARKER
export function gte<T>(x: T): T;

export function lte<T, U>(x: T, y: U): boolean;
export function lte<T, U>(x: T): (y: U) => boolean;

/*
Method: reduceBy
Expand Down
9 changes: 6 additions & 3 deletions immutable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -695,9 +695,11 @@ export function groupWith<T>(compareFn: (x: T, y: T) => boolean): (input: readon
export function groupWith<T>(compareFn: (x: T, y: T) => boolean, input: readonly T[]): readonly ((readonly T[]))[];
export function groupWith<T>(compareFn: (x: T, y: T) => boolean, input: string): readonly string[];

export function gt<T>(x: T): T;
export function gt<T, U>(x: T, y: U): boolean;
export function gt<T, U>(x: T): (y: U) => boolean;

export function gte<T>(x: T): T;
export function gte<T, U>(x: T, y: U): boolean;
export function gte<T, U>(x: T): (y: U) => boolean;

/**
* It returns `true` if `obj` has property `prop`.
Expand Down Expand Up @@ -953,7 +955,8 @@ export function lensPath<S = any, A = any>(path: Path): Lens<S, A>;
*/
export function lensProp<S, K extends keyof S = keyof S>(prop: K): Lens<S, S[K]>;

export function lt<T>(x: T): T;
export function lt<T, U>(x: T, y: U): boolean;
export function lt<T, U>(x: T): (y: U) => boolean;

/**
* It returns the result of looping through `iterable` with `fn`.
Expand Down
9 changes: 6 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -695,9 +695,11 @@ export function groupWith<T>(compareFn: (x: T, y: T) => boolean): (input: T[]) =
export function groupWith<T>(compareFn: (x: T, y: T) => boolean, input: T[]): (T[])[];
export function groupWith<T>(compareFn: (x: T, y: T) => boolean, input: string): string[];

export function gt<T>(x: T): T;
export function gt<T, U>(x: T, y: U): boolean;
export function gt<T, U>(x: T): (y: U) => boolean;

export function gte<T>(x: T): T;
export function gte<T, U>(x: T, y: U): boolean;
export function gte<T, U>(x: T): (y: U) => boolean;

/**
* It returns `true` if `obj` has property `prop`.
Expand Down Expand Up @@ -953,7 +955,8 @@ export function lensPath<S = any, A = any>(path: Path): Lens<S, A>;
*/
export function lensProp<S, K extends keyof S = keyof S>(prop: K): Lens<S, S[K]>;

export function lt<T>(x: T): T;
export function lt<T, U>(x: T, y: U): boolean;
export function lt<T, U>(x: T): (y: U) => boolean;

/**
* It returns the result of looping through `iterable` with `fn`.
Expand Down
11 changes: 11 additions & 0 deletions source/gt-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {gt} from 'rambda'

describe('R.gt', () => {
it('happy', () => {
const result = gt(1, 2)
const curriedResult = gt(2)(3)
result // $ExpectType boolean
curriedResult // $ExpectType boolean
})
})

10 changes: 10 additions & 0 deletions source/gte-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {gte} from 'rambda'

describe('R.gte', () => {
it('happy', () => {
const result = gte(1, 2)
const curriedResult = gte(2)(3)
result // $ExpectType boolean
curriedResult // $ExpectType boolean
})
})
10 changes: 10 additions & 0 deletions source/lt-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {lt} from 'rambda'

describe('R.lt', () => {
it('happy', () => {
const result = lt(1, 2)
const curriedResult = lt(2)(3)
result // $ExpectType boolean
curriedResult // $ExpectType boolean
})
})
10 changes: 10 additions & 0 deletions source/lte-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {lte} from 'rambda'

describe('R.lte', () => {
it('happy', () => {
const result = lte(1, 2)
const curriedResult = lte(2)(3)
result // $ExpectType boolean
curriedResult // $ExpectType boolean
})
})
3 changes: 2 additions & 1 deletion src/isEmpty.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ export function isEmpty(input){
if (type(input.isEmpty) === 'Function') {
return input.isEmpty();
} else if (input.isEmpty) {
return input.isEmpty;
return !!input.isEmpty;
}


if (inputType === 'Object'){
return Object.keys(input).length === 0
}
Expand Down
Loading

0 comments on commit 79013c7

Please sign in to comment.