1+ /*--------------------------------------------------------------------------
2+
3+ ParseBox
4+
5+ The MIT License (MIT)
6+
7+ Copyright (c) 2024-2026 Haydn Paterson
8+
9+ Permission is hereby granted, free of charge, to any person obtaining a copy
10+ of this software and associated documentation files (the "Software"), to deal
11+ in the Software without restriction, including without limitation the rights
12+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+ copies of the Software, and to permit persons to whom the Software is
14+ furnished to do so, subject to the following conditions:
15+
16+ The above copyright notice and this permission notice shall be included in
17+ all copies or substantial portions of the Software.
18+
19+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+ THE SOFTWARE.
26+
27+ ---------------------------------------------------------------------------*/
28+
29+ // deno-fmt-ignore-file
30+
31+ import * as Token from '../token/index.ts'
32+
33+ import { Arguments } from '../system/arguments/index.ts'
34+ import { Guard } from '../guard/index.ts'
35+ import { type IParser , type IMapping , Identity } from './parser.ts'
36+
37+ // ------------------------------------------------------------------
38+ // Type
39+ // ------------------------------------------------------------------
40+ export interface IUnsignedInteger < Output extends unknown = unknown > extends IParser < Output > {
41+ type : 'UnsignedInteger'
42+ }
43+ // ------------------------------------------------------------------
44+ // Factory
45+ // ------------------------------------------------------------------
46+ export function UnsignedInteger < Mapping extends IMapping < string > > ( mapping : Mapping ) : IUnsignedInteger < ReturnType < Mapping > >
47+ export function UnsignedInteger ( ) : IUnsignedInteger < string >
48+ export function UnsignedInteger ( ...args : unknown [ ] ) : never {
49+ const [ mapping ] = Arguments . Match < [ IParser , IMapping ] > ( args , {
50+ 1 : ( mapping ) => [ mapping ] ,
51+ 0 : ( ) => [ Identity ]
52+ } )
53+ return { type : 'UnsignedInteger' , mapping } as never
54+ }
55+ // ------------------------------------------------------------------
56+ // Guard
57+ // ------------------------------------------------------------------
58+ export function IsUnsignedInteger ( value : unknown ) : value is IUnsignedInteger {
59+ return Guard . IsObject ( value )
60+ && Guard . HasPropertyKey ( value , 'type' )
61+ && Guard . IsEqual ( value . type , 'UnsignedInteger' )
62+ }
63+ // ------------------------------------------------------------------
64+ // Parse
65+ // ------------------------------------------------------------------
66+ export function ParseUnsignedInteger ( input : string ) : [ ] | [ string , string ] {
67+ return Token . UnsignedInteger ( input )
68+ }
0 commit comments