概述

文本 predicate 函数集合


目录


isEmail (常量)

Determines whether the given string is Email.

签名


export const isEmail: (a: string) => boolean = ...

示例

import { isEmail } from 'macoolka-predicate'
import * as assert from 'assert'
assert(isEmail('a@mail.com'))
assert(!isEmail('12'))

v0.2.0 中添加

isIpV4 (常量)

Determines whether the given string is IPV4.

签名


export const isIpV4: (a: string) => boolean = ...

示例

import { isIpV4 } from 'macoolka-predicate'
import * as assert from 'assert'
assert(isIpV4('8.8.8.8'))
assert(!isIpV4('12'))

v0.2.0 中添加

isIpV6 (常量)

判断文本是否为IPV6

签名


export const isIpV6: (a: string) => boolean = ...

示例

import { isIpV6 } from 'macoolka-predicate'
import * as assert from 'assert'
assert(isIpV6('2409:8a15:244a:a780:b0f5:8e9a:2c2e:5ce2'))
assert(!isIpV6('8.8.8.8'))

v0.2.0 中添加

isUUID (常量)

判断文本是否为UUID

签名


export const isUUID: (a: string) => boolean = ...

示例

import { isUrl } from 'macoolka-predicate'
import * as assert from 'assert'
assert(isUUID('00000000-0000-0000-0000-000000000000'))
assert(!isUUID('8.8.8.8'))

v0.2.0 中添加

isUrl (常量)

判断文本是否为Url

签名


export const isUrl: (a: string) => boolean = ...

示例

import { isUrl } from 'macoolka-predicate'
import * as assert from 'assert'
expect(isUrl('http://bing.com'))
expect(!isUrl('8.8.8.8'))

v0.2.0 中添加

contains (函数)

Determines whether the given string contain passed string.

签名


export const contains = (substring: string) => (str: string) => ...

示例

import { contains } from 'macoolka-predicate'
import * as assert from 'assert'
assert(contains('firstColorHover')('firstColorHover'))
assert(contains('Color')('firstColorHover'))
assert(contains('er')('firstColorHover'))
assert(contains('fi')('firstColorHover'))
assert(!contains('abc')('firstColorHover'))

v0.2.0 中添加

endsIn (函数)

Determines whether the given string ends with given suffix array.

签名


export const endsIn = (suffix: Array<string>) => (str: string) =>
    suffix.some(a => ...

示例

import { endsIn } from 'macoolka-predicate'
import * as assert from 'assert'
assert(endsIn(['start_with', 'end_with'])('a_start_with'))
assert(endsIn(['start_with', 'end_with'])('a_end_with'))
assert(!endsIn(['start_with', 'end_with'])('a_endwith'))
assert(!endsIn(['start_with', 'end_with'])(''))

v0.2.0 中添加

endsInOption (函数)

Determines whether the given string ends with given suffix array. split given string when ture

签名


export const endsInOption = (suffix: Array<string>) => (str: string) => ...

示例

import { endsInOption } from 'macoolka-predicate'
import * as assert from 'assert'
assert(endsInOption(['_start_with', '_end_with'])('') == none)
expect(endsInOption(['_start_with', '_end_with'])('a_start_with')).toEqual(some({ start: 'a', end: '_start_with' }))
expect(endsInOption(['_start_with', '_end_with'])('a_end_with')).toEqual(some({ start: 'a', end: '_end_with' }))
expect(endsInOption(['_start_with', '_end_with'])('a_endwith') == none)

v0.2.0 中添加

endsWith (函数)

Determines whether the given string ends with given suffix.

签名


export const endsWith = (suffix: string) => (str: string) => ...

示例

import { endsWith } from 'macoolka-predicate'
import * as assert from 'assert'
assert(endsWith('b')('ab'))
assert(endsWith('b')('ab1') === false)

v0.2.0 中添加

endsWithOption (函数)

Determines whether the given string ends with given suffix. remove given suffix when ture

签名


export const endsWithOption = (suffix: string) => (str: string) => ...

示例

import { endsWithOption } from 'macoolka-predicate'
import * as assert from 'assert'
expect(endsWithOption('firstColorHover')('firstColorHover')).toEqual(some(''))
expect(endsWithOption('b')('ab')).toEqual(some('a'))
assert(endsWithOption('b')('ab1') === none)

v0.2.0 中添加

ins (函数)

Determines whether the given string be contained in with passed string array.

签名


export const ins = (v: Array<string>) => (str: string) => ...

示例


import { ins } from 'macoolka-predicate'
import * as assert from 'assert'
assert(ins(['firstColorHover', 'b'])('firstColorHover'));
assert(!ins(['firstColorHover1', 'b'])('firstColorHover'))
});

v0.2.0 中添加

match (函数)

判断文本是否匹配正则表达式

签名


export const match = (reg: RegExp) => (a: string) => ...

示例

import { match } from 'macoolka-predicate'
import * as assert from 'assert'
assert(match(/^A/)('AB'))
assert(!match(/^A/)('12'))

v0.2.0 中添加

maxLength (函数)

判断文本长度是否小于等于输入的最大长度

签名


export const maxLength = (length: number) => (a: string) => ...

示例

import { maxLength } from 'macoolka-predicate'
import * as assert from 'assert'
assert(maxLength(3)('123'))
assert(!maxLength(3)('1234'))

v0.2.0 中添加

minLength (函数)

判断文本长度是否大于等于输入的最小长度

签名


export const minLength = (length: number) => (a: string) => ...

示例

import { minLength } from 'macoolka-predicate'
import * as assert from 'assert'
assert(minLength(3)('123'))
assert(!minLength(3)('12'))

v0.2.0 中添加

notContains (函数)

Determines whether the given string non contain passed string.

签名


export const notContains = (substring: string) => ...

示例

import { notContains } from 'macoolka-predicate'
import * as assert from 'assert'
assert(!notContains('firstColorHover')('firstColorHover'))
assert(!notContains('Color')('firstColorHover'))
assert(!notContains('er')('firstColorHover'))

v0.2.0 中添加

notEndsWith (函数)

Determines whether the given string non ends with given suffix.

签名


export const notEndsWith = (substring: string) => ...

示例

import { notEndsWith } from 'macoolka-predicate'
import * as assert from 'assert'
assert(!notEndsWith('firstColorHover')('firstColorHover'))
assert(!notEndsWith('Hover')('firstColorHover'))
assert(notEndsWith('b')('firstColorHover'))

v0.2.0 中添加

notIn (函数)

Determines whether the given string be not contained in with passed string array.

签名


export const notIn = (a: Array<string>) => (str: string) => ...

示例

import { notIn } from 'macoolka-predicate'
import * as assert from 'assert'
assert(!notIn(['firstColorHover', 'b'])('firstColorHover'))
assert(notIn(['firstColorHover1', 'b'])('firstColorHover'))

v0.2.0 中添加

notStartsWith (函数)

Determines whether the given string non start with given suffix.

签名


export const notStartsWith = (substring: string) => ...

示例

import { notStartsWith } from 'macoolka-predicate'
import * as assert from 'assert'
assert(notStartsWith('firstColorHove')('firstColorHover') === false)
assert(notStartsWith('b')('firstColorHover'))

v0.2.0 中添加

startsWith (函数)

Determines whether the given string start with given suffix.

签名


export const startsWith = (suffix: string) => (str: string) => ...

示例

import { startsWith } from 'macoolka-predicate'
import * as assert from 'assert'
assert(startsWith('a')('ab'))
assert(startsWith('a')('ba') === false)
assert(startsWith('b')('firstColorHover') === false)

v0.2.0 中添加