Skip to content

Commit 14220e9

Browse files
gkelloggdavidlehn
authored andcommitted
Use a constant for KEYWORD_PATTERN.
1 parent 25dbf2f commit 14220e9

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/context.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const {
2727

2828
const INITIAL_CONTEXT_CACHE = new Map();
2929
const INITIAL_CONTEXT_CACHE_MAX_SIZE = 10000;
30+
const KEYWORD_PATTERN = /^@[a-zA-Z]+$/;
3031

3132
const api = {};
3233
module.exports = api;
@@ -397,7 +398,7 @@ api.createTermDefinition = ({
397398
'Invalid JSON-LD syntax; keywords cannot be overridden.',
398399
'jsonld.SyntaxError',
399400
{code: 'keyword redefinition', context: localCtx, term});
400-
} else if(term.match(/@[a-zA-Z]+$/)) {
401+
} else if(term.match(KEYWORD_PATTERN)) {
401402
// FIXME: remove logging and use a handler
402403
console.warn('WARNING: terms beginning with "@" are reserved' +
403404
' for future use and ignored', {term});
@@ -490,7 +491,7 @@ api.createTermDefinition = ({
490491
'jsonld.SyntaxError', {code: 'invalid IRI mapping', context: localCtx});
491492
}
492493

493-
if(reverse.match(/@[a-zA-Z]+$/)) {
494+
if(reverse.match(KEYWORD_PATTERN)) {
494495
// FIXME: remove logging and use a handler
495496
console.warn('WARNING: values beginning with "@" are reserved' +
496497
' for future use and ignored', {reverse});
@@ -511,7 +512,7 @@ api.createTermDefinition = ({
511512
if(id === null) {
512513
// reserve a null term, which may be protected
513514
mapping['@id'] = null;
514-
} else if(!api.isKeyword(id) && id.match(/@[a-zA-Z]+$/)) {
515+
} else if(!api.isKeyword(id) && id.match(KEYWORD_PATTERN)) {
515516
// FIXME: remove logging and use a handler
516517
console.warn('WARNING: values beginning with "@" are reserved' +
517518
' for future use and ignored', {id});
@@ -877,7 +878,7 @@ function _expandIri(activeCtx, value, relativeTo, localCtx, defined, options) {
877878
}
878879

879880
// ignore non-keyword things that look like a keyword
880-
if(value.match(/^@[a-zA-Z]+$/)) {
881+
if(value.match(KEYWORD_PATTERN)) {
881882
return null;
882883
}
883884

0 commit comments

Comments
 (0)