Skip to content

Commit 5cd47a1

Browse files
committed
Use a constant for KEYWORD_PATTERN.
1 parent 150ce5a commit 5cd47a1

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});
@@ -450,7 +451,7 @@ api.createTermDefinition = ({
450451
'jsonld.SyntaxError', {code: 'invalid IRI mapping', context: localCtx});
451452
}
452453

453-
if(reverse.match(/@[a-zA-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-zA-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});
@@ -811,7 +812,7 @@ function _expandIri(activeCtx, value, relativeTo, localCtx, defined, options) {
811812
}
812813

813814
// ignore non-keyword things that look like a keyword
814-
if(value.match(/^@[a-zA-Z]+$/)) {
815+
if(value.match(KEYWORD_PATTERN)) {
815816
return null;
816817
}
817818

0 commit comments

Comments
 (0)