Skip to content

Commit

Permalink
fix: revert the clarify type change in 5.1.3
Browse files Browse the repository at this point in the history
The type system needs to overhaul.

The clarified type is causing usage problems.
  • Loading branch information
unional committed May 6, 2022
1 parent be0431d commit 529cfcb
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 55 deletions.
5 changes: 2 additions & 3 deletions ts/every.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Tersible, tersible, tersify } from 'tersify'
import { tersible, tersify } from 'tersify'
import { createSatisfier } from './createSatisfier'
import { Predicate } from './interfaces'

/**
* Check if every entry in the array satisfies the expectation.
* @param expectation expectation
*/
export function every(expectation: any): Tersible<Predicate> {
export function every(expectation: any) {
const s = createSatisfier(expectation)
return tersible((e: any) => e && Array.isArray(e) && e.reduce((p, v, i) => {
const d = s.exec(v)
Expand Down
10 changes: 0 additions & 10 deletions ts/exact.spec.ts

This file was deleted.

19 changes: 0 additions & 19 deletions ts/exact.ts

This file was deleted.

5 changes: 2 additions & 3 deletions ts/has.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Tersible, tersible, tersify } from 'tersify'
import { tersible, tersify } from 'tersify'
import { createSatisfier } from './createSatisfier'
import { Predicate } from './interfaces'

/**
* Check if an array has entries satisfy the expectations in order.
*/
export function has(...expectations: any[]): Tersible<Predicate> {
export function has(...expectations: any[]) {
return tersible((arr: any) => {
if (!Array.isArray(arr)) return false
let index = 0
Expand Down
11 changes: 5 additions & 6 deletions ts/isInInterval.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { Tersible, tersible } from 'tersify'
import { Predicate } from './interfaces'
import { tersible } from 'tersify'

export function isInOpenInterval(start: number, end: number): Tersible<Predicate> {
export function isInOpenInterval(start: number, end: number) {
return tersible((a: any) => a > start && (a < end), () => `(${start}...${end})`)
}
export function isInClosedInterval(start: number, end: number): Tersible<Predicate> {
export function isInClosedInterval(start: number, end: number) {
return tersible((a: any) => a >= start && a <= end, () => `[${start}...${end}]`)
}

export function isInLeftClosedInterval(start: number, end: number): Tersible<Predicate> {
export function isInLeftClosedInterval(start: number, end: number) {
return tersible((a: any) => a >= start && (a < end), () => `[${start}...${end})`)
}

export function isInRightClosedInterval(start: number, end: number): Tersible<Predicate> {
export function isInRightClosedInterval(start: number, end: number) {
return tersible((a: any) => a > start && a <= end, () => `(${start}...${end}]`)
}
5 changes: 2 additions & 3 deletions ts/isInRange.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Tersible, tersible } from 'tersify'
import { Predicate } from './interfaces'
import { tersible } from 'tersify'

export function isInRange(start: number, end: number): Tersible<Predicate> {
export function isInRange(start: number, end: number) {
return tersible((a: any) => a >= start && a <= end, () => `[${start}...${end}]`)
}
6 changes: 2 additions & 4 deletions ts/isTypeOf.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { Tersible, tersible } from 'tersify'
import { Predicate } from './interfaces'
import { tersible } from 'tersify'

export function isTypeOf(x: 'number' | 'boolean' | 'string'): Tersible<Predicate>{
export function isTypeOf(x: 'number' | 'boolean' | 'string') {
return tersible(
// tslint:disable-next-line:strict-type-predicates
(a: any) => typeof a === x,
() => `typeof ${x}`)
}
5 changes: 2 additions & 3 deletions ts/none.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Tersible, tersible, tersify } from 'tersify'
import { tersible, tersify } from 'tersify'
import { createSatisfier } from './createSatisfier'
import { Predicate } from './interfaces'

/**
* Check if an array have no entry satisfying the expectation.
* @param expectation expectation
*/
export function none(expectation: any): Tersible<Predicate> {
export function none(expectation: any) {
const s = createSatisfier(expectation)
return tersible((e: any) => e && Array.isArray(e) && !e.some(v => s.test(v)), () => `none(${tersify(expectation)})`)
}
5 changes: 2 additions & 3 deletions ts/some.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Tersible, tersible, tersify } from 'tersify'
import { tersible, tersify } from 'tersify'
import { createSatisfier, Expectation } from './createSatisfier'
import { Predicate } from './interfaces'

/**
* Check if an array have at least one entry satisfying the expectation.
* @param expectation expectation
*/
export function some<E extends Expectation>(expectation: E): Tersible<Predicate> {
export function some<E extends Expectation>(expectation: E) {
const s = createSatisfier(expectation)
return tersible((e: any) => e && Array.isArray(e) && e.some(v => s.test(v)), () => `some(${tersify(expectation)})`)
}
1 change: 0 additions & 1 deletion ts/startsWith.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { tersible, tersify } from 'tersify'
import { createSatisfier } from './createSatisfier'


/**
* Check if an array has the first n entries satisfying the specified expectations.
*/
Expand Down

0 comments on commit 529cfcb

Please sign in to comment.