Socket
Socket
Sign inDemoInstall

@uxf/core

Package Overview
Dependencies
Maintainers
1
Versions
87
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@uxf/core - npm Package Compare versions

Comparing version 10.0.0-beta.15 to 10.0.0-beta.22

2

package.json
{
"name": "@uxf/core",
"version": "10.0.0-beta.15",
"version": "10.0.0-beta.22",
"description": "UXF Core",

@@ -5,0 +5,0 @@ "author": "Petr Vejvoda <vejvoda@uxf.cz>",

@@ -1,21 +0,9 @@

export declare function buildArray<T>(): {
add: (data: T) => {
add: any;
when: (condition: boolean, data: T) => {
add: any;
when: any;
get: () => T[];
};
get: () => T[];
};
when: (condition: boolean, data: T) => {
add: (data: T) => {
add: any;
when: any;
get: () => T[];
};
when: any;
get: () => T[];
};
get: () => T[];
};
type Element<T> = T;
type WhenFn<T> = (when: boolean, element: Element<T>) => ProxiedArray<T>;
type AddFn<T> = (element: Element<T>) => ProxiedArray<T>;
type ProxiedArray<T> = {
when: WhenFn<T>;
add: AddFn<T>;
} & T[];
export declare function buildArray<T = unknown>(initial?: T[]): ProxiedArray<T>;
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildArray = void 0;
function get(array) {
return () => {
return array;
};
function buildArray(initial) {
const initialArray = (initial ? [...initial] : []);
const proxiedArray = new Proxy(initialArray, {
get: (target, prop, receiver) => {
if ("add" === prop) {
return (element) => {
target.push(element);
return proxiedArray;
};
}
if ("when" === prop) {
return (when, element) => {
if (when) {
target.push(element);
}
return proxiedArray;
};
}
return Reflect.get(target, prop, receiver);
},
});
return proxiedArray;
}
function add(array) {
return (data) => {
array.push(data);
// eslint-disable-next-line @typescript-eslint/no-use-before-define
return { add: add(array), when: when(array), get: get(array) };
};
}
function when(array) {
return (condition, data) => {
if (condition) {
array.push(data);
}
return { add: add(array), when: when(array), get: get(array) };
};
}
function buildArray() {
const array = [];
return { add: add(array), when: when(array), get: get(array) };
}
exports.buildArray = buildArray;

@@ -5,7 +5,7 @@ "use strict";

test("buildArray", () => {
expect((0, buildArray_1.buildArray)().get()).toStrictEqual([]);
expect((0, buildArray_1.buildArray)().add("uxf").get()).toStrictEqual(["uxf"]);
expect((0, buildArray_1.buildArray)().add("ux").add("fans").get()).toStrictEqual(["ux", "fans"]);
expect((0, buildArray_1.buildArray)().add("ux").when(true, "fans").get()).toStrictEqual(["ux", "fans"]);
expect((0, buildArray_1.buildArray)().add("ux").when(false, "fans").get()).toStrictEqual(["ux"]);
expect((0, buildArray_1.buildArray)()).toStrictEqual([]);
expect((0, buildArray_1.buildArray)().add("uxf")).toStrictEqual(["uxf"]);
expect((0, buildArray_1.buildArray)().add("ux").add("fans")).toStrictEqual(["ux", "fans"]);
expect((0, buildArray_1.buildArray)().add("ux").when(true, "fans")).toStrictEqual(["ux", "fans"]);
expect((0, buildArray_1.buildArray)().add("ux").when(false, "fans")).toStrictEqual(["ux"]);
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc