Skip to content

Commit

Permalink
feat/docs: Add types for testPattern util and document it (fix: #16091)…
Browse files Browse the repository at this point in the history
… (#16092)

* docs: Document testPattern util

* feat(ui): add types for patterns utils
  • Loading branch information
yusufkandemir authored Jul 19, 2023
1 parent 6ec4520 commit a092524
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
23 changes: 22 additions & 1 deletion docs/src/pages/quasar-utils/other-utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ The `opts` parameter is optional and can be a String (mimeType) or an Object wit

* **mimeType** (optional)

Examples: 'application/octect-stream' (default), 'text/plain', 'application/json', 'text/plain;charset=UTF-8', 'video/mp4', 'image/png', 'application/pdf'
Examples: 'application/octet-stream' (default), 'text/plain', 'application/json', 'text/plain;charset=UTF-8', 'video/mp4', 'image/png', 'application/pdf'
[https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types)

* **byteOrderMark** (optional)
Expand Down Expand Up @@ -475,3 +475,24 @@ node.addEventListener('click', evt => {
event.stopAndPrevent(evt)
})
```

## testPattern

Test against particular patterns.

```js
import { patterns } from 'quasar'

const { testPattern } = patterns

testPattern.email('[email protected]') // true
testPattern.email('foo') // false

testPattern.hexColor('#fff') // true
testPattern.hexColor('#ffffff') // true
testPattern.hexColor('#FFF') // true
testPattern.hexColor('#gggggg') // false

// See the full list of patterns here:
// https://github.com/quasarframework/quasar/blob/dev/ui/src/utils/patterns.js
```
1 change: 1 addition & 0 deletions ui/types/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export * from "./utils/event";
export * from "./utils/format";
export * from "./utils/scroll";
export * from "./utils/is";
export * from "./utils/patterns";
export * from "./utils/run-sequential-promises";

import { BrandColor } from "./api/color";
Expand Down
10 changes: 10 additions & 0 deletions ui/types/utils/patterns.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { EmbeddedValidationRule } from "../api/validation";

interface Patterns {
/**
* Test against particular patterns.
*/
testPattern: Record<EmbeddedValidationRule, (value: any) => boolean>;
}

export declare const patterns: Patterns;

0 comments on commit a092524

Please sign in to comment.