@@ -27,6 +27,7 @@ const {
2727
2828const INITIAL_CONTEXT_CACHE = new Map ( ) ;
2929const INITIAL_CONTEXT_CACHE_MAX_SIZE = 10000 ;
30+ const KEYWORD_PATTERN = / ^ @ [ a - z A - Z ] + $ / ;
3031
3132const api = { } ;
3233module . exports = api ;
@@ -350,7 +351,7 @@ api.createTermDefinition = ({
350351 'Invalid JSON-LD syntax; keywords cannot be overridden.' ,
351352 'jsonld.SyntaxError' ,
352353 { code : 'keyword redefinition' , context : localCtx , term} ) ;
353- } else if ( term . match ( / @ [ a - z A - Z ] + $ / ) ) {
354+ } else if ( term . match ( KEYWORD_PATTERN ) ) {
354355 // FIXME: remove logging and use a handler
355356 console . warn ( 'WARNING: terms beginning with "@" are reserved' +
356357 ' for future use and ignored' , { term} ) ;
@@ -450,7 +451,7 @@ api.createTermDefinition = ({
450451 'jsonld.SyntaxError' , { code : 'invalid IRI mapping' , context : localCtx } ) ;
451452 }
452453
453- if ( reverse . match ( / @ [ a - z A - Z ] + $ / ) ) {
454+ if ( reverse . match ( KEYWORD_PATTERN ) ) {
454455 // FIXME: remove logging and use a handler
455456 console . warn ( 'WARNING: values beginning with "@" are reserved' +
456457 ' for future use and ignored' , { reverse} ) ;
@@ -468,7 +469,7 @@ api.createTermDefinition = ({
468469 'of strings or a string.' ,
469470 'jsonld.SyntaxError' , { code : 'invalid IRI mapping' , context : localCtx } ) ;
470471 }
471- if ( ! api . isKeyword ( id ) && id . match ( / @ [ a - z A - Z ] + $ / ) ) {
472+ if ( ! api . isKeyword ( id ) && id . match ( KEYWORD_PATTERN ) ) {
472473 // FIXME: remove logging and use a handler
473474 console . warn ( 'WARNING: values beginning with "@" are reserved' +
474475 ' for future use and ignored' , { id} ) ;
@@ -819,7 +820,7 @@ function _expandIri(activeCtx, value, relativeTo, localCtx, defined, options) {
819820 }
820821
821822 // ignore non-keyword things that look like a keyword
822- if ( value . match ( / ^ @ [ a - z A - Z ] + $ / ) ) {
823+ if ( value . match ( KEYWORD_PATTERN ) ) {
823824 return null ;
824825 }
825826
0 commit comments