UNPKG

@klayr-did/klayr-verifiable-credentials

Version:

A library for working with W3C verifiable credentials (VC) and verifiable presentations (VP) using Klayr DID

34 lines 1.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.preprocessRequired = void 0; function arrayMoveMutable(array, fromIndex, toIndex) { const startIndex = fromIndex < 0 ? array.length + fromIndex : fromIndex; if (startIndex >= 0 && startIndex < array.length) { const endIndex = toIndex < 0 ? array.length + toIndex : toIndex; const [item] = array.splice(fromIndex, 1); array.splice(endIndex, 0, item); } } function preprocessRequired(properties, required) { let tmpArray = properties; if (tmpArray === undefined) return [required]; if (Array.isArray(properties)) { const findIndex = tmpArray.indexOf(required); tmpArray = tmpArray.filter((v, i, self) => { return i == self.indexOf(v); }); if (tmpArray.includes(required) && findIndex > 0) { arrayMoveMutable(tmpArray, findIndex, 0); } if (tmpArray[0] !== required) { tmpArray.unshift(required); } } if (typeof tmpArray === 'string' && tmpArray !== required) { tmpArray = [required]; } return tmpArray; } exports.preprocessRequired = preprocessRequired; //# sourceMappingURL=util.js.map