UNPKG

@iimm/shared

Version:

shared utils on browser and react env

53 lines (51 loc) 1.78 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/cjs/set/index.ts var set_exports = {}; __export(set_exports, { differenceSet: () => differenceSet, intersection: () => intersection, union: () => union }); module.exports = __toCommonJS(set_exports); var import_isX = require("../isX"); var intersection = (a = [], b = [], compareOptions) => { if (!Array.isArray(a) || !Array.isArray(b)) return []; return a.filter((item) => (0, import_isX.isInArray)(item, b, compareOptions)); }; var differenceSet = (a = [], b = [], compareOptions) => { if (!Array.isArray(a)) return []; if (!Array.isArray(b)) return a; return a.filter((item) => !(0, import_isX.isInArray)(item, b), compareOptions); }; var union = (a = [], b = [], compareOptions) => { if (!Array.isArray(a)) return b; if (!Array.isArray(b)) return a; return [...a, ...differenceSet(b, a, compareOptions)]; }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { differenceSet, intersection, union });