CARVIEW |
Select Language
HTTP/2 200
date: Tue, 22 Jul 2025 04:06:20 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
x-robots-tag: none
etag: W/"261385399734a8562bca0f68bd8f555e"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: no-referrer-when-downgrade
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=HZdFfaJF2pqvoBXHySWNDNrV2nlhB2Qlu2DvHKDdIX4zVN8UB0jdeQCFEP0uW1YWAQIW3U7cBv7ihrQiLmSiBGfk2RgQjK1oGwyH5wMtN%2FYIBmIPWvAEaHlIhr5YgXyJ7MugoIYOaTSLfBDxg6kXxqerfHynSGxZMU2NYLnwTx334BEubgZwhxIX4HzXQp6Aen%2BmnbzLGqU55MgcpYoV67GB5hqlt8I86tNc%2Fm4lPQIs3F4P%2B3814BkCG8EsCHYjYrVX69aDG9xLxJ25G20yqA%3D%3D--C49nl07kf0f1aXRl--A7TwbjaqBsx1%2Bp2s8pyQEA%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.2049581744.1753157179; Path=/; Domain=github.com; Expires=Wed, 22 Jul 2026 04:06:19 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Wed, 22 Jul 2026 04:06:19 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: AA6A:102498:11E8FB:18F09B:687F0E3B
Core Pattern helpers · shuckster/match-iz Wiki · GitHub
Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 2
Core Pattern helpers
Conan edited this page Jun 23, 2022
·
9 revisions
match-iz
provides a number of composable matchers you can use to build patterns:
Numbers | Strings | Strings/Arrays | Arrays | Truthiness | Primitives | Negation | Combinators |
---|---|---|---|---|---|---|---|
gt(n) |
startsWith('s') |
includes(o) |
some(...) |
empty |
isArray |
not(...) |
allOf(...) |
lt(n) |
endsWith('s') |
- | every(...) |
falsy |
isDate |
- | anyOf(...) |
gte(n) |
- | - | - | defined |
isFunction |
- | firstOf(...) |
lte(n) |
- | - | - | truthy |
isNumber |
- | lastOf(...) |
inRange(x,y) |
- | - | - | eq(obj) |
isPojo |
- | includedIn(...) |
- | - | - | - | deepEp(obj) |
isRegExp |
- | hasOwn(...) |
- | - | - | - | - | isString |
- | isStrictly(x) |
- | - | - | - | - | instanceOf |
- | - |
Just import them from match-iz
as you do the core library:
import { gt, lt, ...etc } from 'match-iz'
Matchers | Meaning |
---|---|
gt / lt / gte / lte / inRange
|
number comparisons |
match(5)(
when(3, 'Exactly 3'),
when(gt(0), 'Greater than 0'),
when(gte(4), 'Greater than or equal to 4'),
when(lt(10), 'Less than 10'),
when(lte(9), 'Less than or equal to 9'),
when(inRange(5, 10), 'Between 5 and 10 inclusive')
)
Matchers | Meaning |
---|---|
startsWith / endsWith
|
string comparisons |
match('lorem ipsum')(
when('lipsum', 'Exactly "lipsum"'),
when(startsWith('ip'), 'Starts with "ip"'),
when(endsWith('um'), 'Ends with "um"')
)
Helper | Meaning |
---|---|
includes |
string/array comparisons |
match('lorem ipsum')(
when(includes('em'), 'Got "em"'),
when(includes('zap'), 'Found "zap"')
)
match([1, 2, 3, 4])(
when(includes(5), 'Array has a 5'),
when([1, 2, 3, gt(3)], 'Array is [1, 2, 3, >3]')
)
Matchers | Meaning |
---|---|
some / every
|
array item comparisons |
match(array)(
when(every(isNumber), 'all items are numbers'),
when(some(isNumber), 'some items are numbers'),
when(every({ id: isNumber }), 'all items have an id property')
)
Matchers | Meaning |
---|---|
empty / defined / falsy / truthy
|
bottom-value comparisons |
match('')(
when(empty, () => {
return "It's '', {}, [], null, undefined, or NaN"
}),
when(defined, 'Opposite of empty'),
when(falsy, "It's falsy"),
when(truthy, "It's truthy")
)
Matchers | Meaning |
---|---|
eq / deepEq
|
"full" object-equality comparison |
match({ one: '1', two: '2', three: '3' })(
when({ one: '1', two: '2' }, 'partial match')
)
// 'partial match'
match({ one: '1', two: '2', three: '3' })(
when(eq({ one: '1', two: '2' }), 'shallow match')
)
// undefined
match({ one: '1', two: '2', three: { four: '4', five: '5' } })(
when(
eq({ one: '1', two: '2', three: eq({ four: '4' }) }),
'deep match using nested eq()'
)
)
// undefined
match({ one: '1', two: '2', three: { four: '4', five: '5' } })(
when(
deepEq({ one: '1', two: '2', three: { four: '4' } }),
'deep match using deepEq()'
)
)
// undefined
Matchers | Meaning |
---|---|
isArray / isDate / isFunction / isNumber / isPojo / isRegExp / isString / instanceOf
|
primitive comparisons |
match([1, 2, 3])(
when(isArray, 'Looks like an array, eh?'),
when(instanceOf(Component), 'A nice component')
)
Helper | Meaning |
---|---|
not |
negation |
match(5)(
when(not(5), 'Not a 5'),
when(not(gte(4)), 'Less than 4'),
when(not(inRange(100, 0)), () => {
return 'Less than 0 or greater than 100'
})
)
Matchers | Meaning |
---|---|
allOf / anyOf / firstOf / lastOf / includedIn / hasOwn / isStrictly
|
combinators |
match({ one: 1, two: 2, three: [1, 2, 'a'] })(
when(allOf(isPojo, hasOwn('one')), () => {
return 'Has "one"'
}),
when({ one: anyOf(1, 2, 3) }, () => {
return 'Has "one" of 1, 2, or 3'
}),
when({ two: includedIn(1, gt(3)) }, () => {
return 'Has "two" with a value of 1 or >3'
}),
when({ three: lastOf(isString) }, () => {
return 'Has "three" with a string value in the last position'
})
)
const obj = { one: 1, two: 2 }
match([1, 'a', 3, 4, 5, 6, obj])(
when(lastOf(isNumber, isString), () => {
return 'last two items are a number and a string'
}),
when(firstOf(isNumber, isString), () => {
return 'first two items are a number and a string'
}),
when(lastOf(isStrictly(obj)), () => {
return 'last item is strictly equal to the object'
})
)
Clone this wiki locally
You can’t perform that action at this time.