Skip to content

Commit 26c6884

Browse files
committed
Use a constant for KEYWORD_PATTERN.
1 parent d67c316 commit 26c6884

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;
@@ -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-zA-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});
@@ -443,7 +444,7 @@ api.createTermDefinition = ({
443444
'jsonld.SyntaxError', {code: 'invalid IRI mapping', context: localCtx});
444445
}
445446

446-
if(reverse.match(/@[a-zA-Z]+$/)) {
447+
if(reverse.match(KEYWORD_PATTERN)) {
447448
// FIXME: remove logging and use a handler
448449
console.warn('WARNING: values beginning with "@" are reserved' +
449450
' for future use and ignored', {reverse});
@@ -464,7 +465,7 @@ api.createTermDefinition = ({
464465
if(id === null) {
465466
// reserve a null term, which may be protected
466467
mapping['@id'] = null;
467-
} else if(!api.isKeyword(id) && id.match(/@[a-zA-Z]+$/)) {
468+
} else if(!api.isKeyword(id) && id.match(KEYWORD_PATTERN)) {
468469
// FIXME: remove logging and use a handler
469470
console.warn('WARNING: values beginning with "@" are reserved' +
470471
' for future use and ignored', {id});
@@ -830,7 +831,7 @@ function _expandIri(activeCtx, value, relativeTo, localCtx, defined, options) {
830831
}
831832

832833
// ignore non-keyword things that look like a keyword
833-
if(value.match(/^@[a-zA-Z]+$/)) {
834+
if(value.match(KEYWORD_PATTERN)) {
834835
return null;
835836
}
836837

0 commit comments

Comments
 (0)