UNPKG

@yamamotok/dataobject

Version:

Decorator based JSON serializer and deserializer.

38 lines 1.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.inContext = void 0; /** * Check if the current context is one of expected ones. */ function inContext(current, expected) { if (!expected || !current) { return true; } let buffer = []; if (typeof expected === 'string') { buffer = [expected]; } else if (Array.isArray(expected)) { buffer = [...expected]; } const expectedOnes = []; const notExpectedOnes = []; buffer.forEach((c) => { const matches = c.match(/^!(.+)$/); if (matches) { notExpectedOnes.push(matches[1]); } else { expectedOnes.push(c); } }); if (notExpectedOnes.indexOf(current) >= 0) { return false; } if (expectedOnes.length < 1) { return true; } return expectedOnes.indexOf(current) >= 0; } exports.inContext = inContext; //# sourceMappingURL=inContext.js.map