概述
文本类型集合
目录
- EMailBrand (接口)
- EmailBrand (接口)
- IpV4Brand (接口)
- IpV6Brand (接口)
- NonEmptyStringBrand (接口)
- NonEmptyStringC (接口)
- StringMatchBrand (接口)
- StringMaxLengthBrand (接口)
- StringMinLengthBrand (接口)
- UUIDBrand (接口)
- UrlBrand (接口)
- NonEmptyString (类型)
- UUID (类型)
- Url (类型)
- email (类型)
- ipv4 (类型)
- ipv6 (类型)
- email (常量)
- ipv4 (常量)
- ipv6 (常量)
- nonEmptyString (常量)
- url (常量)
- uuid (常量)
- stringMatch (函数)
- stringMaxLength (函数)
- stringMinLength (函数)
EMailBrand (接口)
签名
interface EMailBrand {
readonly EMail: unique symbol
}
v0.2.0 中添加
EmailBrand (接口)
签名
interface EmailBrand {
readonly email: unique symbol
}
v0.2.0 中添加
IpV4Brand (接口)
签名
interface IpV4Brand {
readonly ipv4: unique symbol
}
v0.2.0 中添加
IpV6Brand (接口)
签名
interface IpV6Brand {
readonly ipv6: unique symbol
}
v0.2.0 中添加
NonEmptyStringBrand (接口)
签名
interface NonEmptyStringBrand {
readonly NonEmptyString: unique symbol
}
v0.2.0 中添加
NonEmptyStringC (接口)
签名
interface NonEmptyStringC extends Type {}
v0.2.0 中添加
StringMatchBrand (接口)
签名
interface StringMatchBrand {
readonly StringMatch: unique symbol
}
v0.2.0 中添加
StringMaxLengthBrand (接口)
签名
interface StringMaxLengthBrand {
readonly StringMaxLength: unique symbol
}
v0.2.0 中添加
StringMinLengthBrand (接口)
签名
interface StringMinLengthBrand {
readonly StringMinLength: unique symbol
}
v0.2.0 中添加
UUIDBrand (接口)
签名
interface UUIDBrand {
readonly UUID: unique symbol
}
v0.2.0 中添加
UrlBrand (接口)
签名
interface UrlBrand {
readonly Url: unique symbol
}
v0.2.0 中添加
NonEmptyString (类型)
签名
export type NonEmptyString = t.Branded<string, NonEmptyStringBrand>
v0.2.0 中添加
UUID (类型)
签名
export type UUID = t.Branded<string, UUIDBrand>
v0.2.0 中添加
Url (类型)
签名
export type Url = t.Branded<string, UrlBrand>
v0.2.0 中添加
email (类型)
签名
export type email = t.Branded<string, EmailBrand>
v0.2.0 中添加
ipv4 (类型)
签名
export type ipv4 = t.Branded<string, IpV4Brand>
v0.2.0 中添加
ipv6 (类型)
签名
export type ipv6 = t.Branded<string, IpV6Brand>
v0.2.0 中添加
email (常量)
校验文本是 EMAIL
签名
export const email: t.BrandC<t.StringC, EmailBrand> = ...
示例
import { email } from 'macoolka-io'
import { right, isLeft } from 'fp-ts/lib/Either'
expect(email.decode('a@mail.com')).toEqual(right('a@mail.com'))
expect(isLeft(email.decode('12'))).toEqual(true)
v0.2.0 中添加
ipv4 (常量)
校验文本是 IPV4
签名
export const ipv4: t.BrandC<t.StringC, IpV4Brand> = ...
示例
import { ipv4 } from 'macoolka-io'
import { right, isLeft } from 'fp-ts/lib/Either'
expect(ipv4.decode('8.8.8.8')).toEqual(right('8.8.8.8'))
expect(isLeft(ipv4.decode('12'))).toEqual(true)
v0.2.0 中添加
ipv6 (常量)
校验文本是 IPV6
签名
export const ipv6: t.BrandC<t.StringC, IpV6Brand> = ...
示例
import { ipv6 } from 'macoolka-io'
import { right, isLeft } from 'fp-ts/lib/Either'
expect(ipv6.decode('2409:8a15:244a:a780:b0f5:8e9a:2c2e:5ce2')).toEqual(right('2409:8a15:244a:a780:b0f5:8e9a:2c2e:5ce2'))
expect(isLeft(ipv6.decode('8.8.8.8'))).toEqual(true)
v0.2.0 中添加
nonEmptyString (常量)
非空文本
签名
export const nonEmptyString: NonEmptyStringC = ...
示例
import { NonEmptyString } from 'macoolka-io'
import { right, isLeft } from 'fp-ts/lib/Either'
assert.deepStrictEqual(NonEmptyString.decode('a'), right('a'))
assert(isLeft(NonEmptyString.decode('')))
v0.2.0 中添加
url (常量)
校验文本是 url
签名
export const url: t.BrandC<t.StringC, UrlBrand> = ...
示例
import { url } from 'macoolka-io'
import { right, isLeft } from 'fp-ts/lib/Either'
expect(url.decode('http://bing.com')).toEqual(right('http://bing.com'))
expect(isLeft(url.decode('8.8.8.8'))).toEqual(true)
v0.2.0 中添加
uuid (常量)
校验文本是 UUID
签名
export const uuid: t.BrandC<t.StringC, UUIDBrand> = ...
示例
import { uuid } from 'macoolka-io'
import { right, isLeft } from 'fp-ts/lib/Either'
v0.2.0 中添加
stringMatch (函数)
校验文本匹配正则表达式
签名
export const stringMatch = (regexp: RegExp) => new t.Type<string, string, unknown>(
['stringMatch', regexp].join(NameSplit),
t.string.is,
(u, c) => ...
示例
import { stringMatch } from 'macoolka-io'
import { right, isLeft } from 'fp-ts/lib/Either'
expect(stringMatch(/^A/).decode('ABC')).toEqual(right('ABC'))
expect(isLeft(stringMatch(/^A/).decode('12'))).toEqual(true)
v0.2.0 中添加
stringMaxLength (函数)
校验文本最大长度
签名
export const stringMaxLength = (_maxLength: number) => new t.Type<string, string, unknown>(
['stringMaxLength', _maxLength].join(NameSplit),
t.string.is,
(u, c) => ...
示例
import { stringMaxLength } from 'macoolka-io'
import { right, isLeft } from 'fp-ts/lib/Either'
expect(t.stringMaxLength(3).decode('123')).toEqual(right('123'))
expect(isLeft(t.stringMaxLength(3).decode('1234'))).toEqual(true)
v0.2.0 中添加
stringMinLength (函数)
校验文本最小长度
签名
export const stringMinLength = (_minLength: number) => new t.Type<string, string, unknown>(
['stringMinLength', _minLength].join(NameSplit),
t.string.is,
(u, c) => ...
示例
import { stringMinLength } from 'macoolka-io'
import { right, isLeft } from 'fp-ts/lib/Either'
expect(stringMinLength(3).decode('123')).toEqual(right('123'))
expect(isLeft(stringMinLength(3).decode('12'))).toEqual(true)
v0.2.0 中添加