@@ -27,6 +27,7 @@ const {
27
27
28
28
const INITIAL_CONTEXT_CACHE = new Map ( ) ;
29
29
const INITIAL_CONTEXT_CACHE_MAX_SIZE = 10000 ;
30
+ const KEYWORD_PATTERN = / ^ @ [ a - z A - Z ] + $ / ;
30
31
31
32
const api = { } ;
32
33
module . exports = api ;
@@ -350,7 +351,7 @@ api.createTermDefinition = ({
350
351
'Invalid JSON-LD syntax; keywords cannot be overridden.' ,
351
352
'jsonld.SyntaxError' ,
352
353
{ code : 'keyword redefinition' , context : localCtx , term} ) ;
353
- } else if ( term . match ( / @ [ a - z A - Z ] + $ / ) ) {
354
+ } else if ( term . match ( KEYWORD_PATTERN ) ) {
354
355
// FIXME: remove logging and use a handler
355
356
console . warn ( 'WARNING: terms beginning with "@" are reserved' +
356
357
' for future use and ignored' , { term} ) ;
@@ -450,7 +451,7 @@ api.createTermDefinition = ({
450
451
'jsonld.SyntaxError' , { code : 'invalid IRI mapping' , context : localCtx } ) ;
451
452
}
452
453
453
- if ( reverse . match ( / @ [ a - z A - Z ] + $ / ) ) {
454
+ if ( reverse . match ( KEYWORD_PATTERN ) ) {
454
455
// FIXME: remove logging and use a handler
455
456
console . warn ( 'WARNING: values beginning with "@" are reserved' +
456
457
' for future use and ignored' , { reverse} ) ;
@@ -468,7 +469,7 @@ api.createTermDefinition = ({
468
469
'of strings or a string.' ,
469
470
'jsonld.SyntaxError' , { code : 'invalid IRI mapping' , context : localCtx } ) ;
470
471
}
471
- if ( ! api . isKeyword ( id ) && id . match ( / @ [ a - z A - Z ] + $ / ) ) {
472
+ if ( ! api . isKeyword ( id ) && id . match ( KEYWORD_PATTERN ) ) {
472
473
// FIXME: remove logging and use a handler
473
474
console . warn ( 'WARNING: values beginning with "@" are reserved' +
474
475
' for future use and ignored' , { id} ) ;
@@ -811,7 +812,7 @@ function _expandIri(activeCtx, value, relativeTo, localCtx, defined, options) {
811
812
}
812
813
813
814
// ignore non-keyword things that look like a keyword
814
- if ( value . match ( / ^ @ [ a - z A - Z ] + $ / ) ) {
815
+ if ( value . match ( KEYWORD_PATTERN ) ) {
815
816
return null ;
816
817
}
817
818
0 commit comments