File tree Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @scaleway/regex ' : minor
3+ ---
4+
5+ Add ` pathSegment ` and ` absolutePath ` regex
Original file line number Diff line number Diff line change 11import { describe , expect , test } from '@jest/globals'
22import {
33 absoluteLinuxPath ,
4+ absolutePath ,
45 accessKeyRegex ,
56 advancedDomainName ,
67 alpha ,
@@ -36,6 +37,7 @@ import {
3637 ipv6 ,
3738 ipv6Cidr ,
3839 macAddress ,
40+ pathSegment ,
3941 phone ,
4042 reverseDNS ,
4143 s3BucketName ,
@@ -958,4 +960,30 @@ describe('@regex', () => {
958960 expect ( accessKeyRegex . test ( string ) ) . toBe ( expected )
959961 } )
960962 } )
963+
964+ describe . only ( 'pathSegment' , ( ) => {
965+ test . each ( [
966+ [ '/hello' , false ] ,
967+ [ 'hello' , true ] ,
968+ [ 'hello nop' , false ] ,
969+ [ 'hello?' , false ] ,
970+ [ 'hello-world' , true ] ,
971+ [ 'hello/world' , false ] ,
972+ ] ) ( 'should match regex %s to be %s' , ( string , expected ) => {
973+ expect ( pathSegment . test ( string ) ) . toBe ( expected )
974+ } )
975+ } )
976+
977+ describe . only ( 'absolutePath' , ( ) => {
978+ test . each ( [
979+ [ '/hello' , true ] ,
980+ [ 'hello' , false ] ,
981+ [ '/hello nop' , false ] ,
982+ [ '/hello?' , false ] ,
983+ [ '/hello-world' , true ] ,
984+ [ '/hello/world' , true ] ,
985+ ] ) ( 'should match regex %s to be %s' , ( string , expected ) => {
986+ expect ( absolutePath . test ( string ) ) . toBe ( expected )
987+ } )
988+ } )
961989} )
Original file line number Diff line number Diff line change @@ -81,3 +81,7 @@ export const ipv6Cidr = new RegExp(`^${cidrv6}$`)
8181export const reverseDNS = / ^ [ a - z 0 - 9 - ] + ( \. [ a - z 0 - 9 - ] { 1 , 63 } ) + ( \. ) $ /
8282export const dashedIpv4 =
8383 / ( \b 2 5 [ 0 - 5 ] | \b 2 [ 0 - 4 ] [ 0 - 9 ] | \b [ 0 1 ] ? [ 0 - 9 ] [ 0 - 9 ] ? ) ( - ( 2 5 [ 0 - 5 ] | 2 [ 0 - 4 ] [ 0 - 9 ] | [ 0 1 ] ? [ 0 - 9 ] [ 0 - 9 ] ? ) ) { 3 } /
84+
85+ export const pathSegment = / ^ [ _ a - z A - Z 0 - 9 ] [ - _ . a - z A - Z 0 - 9 ] * [ _ a - z A - Z 0 - 9 ] $ /
86+ export const absolutePath =
87+ / ^ \/ ( [ _ a - z A - Z 0 - 9 ] [ - _ . a - z A - Z 0 - 9 ] * [ _ a - z A - Z 0 - 9 ] \/ ? ) { 1 , 10 } $ /
You can’t perform that action at this time.
0 commit comments