@next-core/brick-kit 2.103.7 → 2.103.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -229,6 +229,37 @@ function compareVersions(v1, v2) {
229
229
 
230
230
  return 0;
231
231
  }
232
+ var validate = v => typeof v === 'string' && /^[v\d]/.test(v) && semver.test(v);
233
+ var compare = (v1, v2, operator) => {
234
+ // validate input operator
235
+ assertValidOperator(operator); // since result of compareVersions can only be -1 or 0 or 1
236
+ // a simple map can be used to replace switch
237
+
238
+ var res = compareVersions(v1, v2);
239
+ return operatorResMap[operator].includes(res);
240
+ };
241
+ var satisfies = (v, r) => {
242
+ // if no range operator then "="
243
+ var m = r.match(/^([<>=~^]+)/);
244
+ var op = m ? m[1] : '='; // if gt/lt/eq then operator compare
245
+
246
+ if (op !== '^' && op !== '~') return compare(v, r, op); // else range of either "~" or "^" is assumed
247
+
248
+ var [v1, v2, v3] = validateAndParse(v);
249
+ var [r1, r2, r3] = validateAndParse(r);
250
+ if (compareStrings(v1, r1) !== 0) return false;
251
+
252
+ if (op === '^') {
253
+ return compareSegments([v2, v3], [r2, r3]) >= 0;
254
+ }
255
+
256
+ if (compareStrings(v2, r2) !== 0) return false;
257
+ return compareStrings(v3, r3) >= 0;
258
+ }; // export CJS style for parity
259
+
260
+ compareVersions.validate = validate;
261
+ compareVersions.compare = compare;
262
+ compareVersions.sastisfies = satisfies;
232
263
  var semver = /^[v^~<>=]*?(\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+))?(?:-([\da-z\-]+(?:\.[\da-z\-]+)*))?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i;
233
264
 
234
265
  var validateAndParse = v => {
@@ -272,6 +303,25 @@ var compareSegments = (a, b) => {
272
303
  return 0;
273
304
  };
274
305
 
306
+ var operatorResMap = {
307
+ '>': [1],
308
+ '>=': [0, 1],
309
+ '=': [0],
310
+ '<=': [-1, 0],
311
+ '<': [-1]
312
+ };
313
+ var allowedOperators = Object.keys(operatorResMap);
314
+
315
+ var assertValidOperator = op => {
316
+ if (typeof op !== 'string') {
317
+ throw new TypeError("Invalid operator type, expected string but got ".concat(typeof op));
318
+ }
319
+
320
+ if (allowedOperators.indexOf(op) === -1) {
321
+ throw new Error("Invalid operator, expected one of ".concat(allowedOperators.join('|')));
322
+ }
323
+ };
324
+
275
325
  var brickTemplateRegistry = new Map();
276
326
  function registerBrickTemplate(name, factory) {
277
327
  if (brickTemplateRegistry.has(name)) {