Socket
Socket
Sign inDemoInstall

@zag-js/utils

Package Overview
Dependencies
Maintainers
1
Versions
769
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zag-js/utils - npm Package Compare versions

Comparing version 0.0.0-dev-20220605192656 to 0.0.0-dev-20220714091855

LICENSE

49

dist/index.d.ts

@@ -1,7 +0,42 @@

export * from "./array";
export * from "./events";
export * from "./functions";
export * from "./guard";
export * from "./platform";
export * from "./warning";
//# sourceMappingURL=index.d.ts.map
declare function toArray<T>(v: T | T[] | undefined | null): T[];
declare const fromLength: (length: number) => number[];
declare const first: <T>(v: T[]) => T | undefined;
declare const last: <T>(v: T[]) => T | undefined;
declare const isEmpty: <T>(v: T[]) => boolean;
declare const has: <T>(v: T[], t: any) => boolean;
declare const add: <T>(v: T[], ...items: T[]) => T[];
declare const remove: <T>(v: T[], item: T) => T[];
declare const removeAt: <T>(v: T[], i: number) => T[];
declare function clear<T>(v: T[]): T[];
declare type IndexOptions = {
step?: number;
loop?: boolean;
};
declare function nextIndex<T>(v: T[], idx: number, opts?: IndexOptions): number;
declare function next<T>(v: T[], idx: number, opts?: IndexOptions): T | undefined;
declare function prevIndex<T>(v: T[], idx: number, opts?: IndexOptions): number;
declare function prev<T>(v: T[], index: number, opts?: IndexOptions): T | undefined;
declare const chunk: <T>(v: T[], size: number) => T[][];
declare const runIfFn: <T>(v: T | undefined, ...a: T extends (...a: any[]) => void ? Parameters<T> : never) => T extends (...a: any[]) => void ? NonNullable<ReturnType<T>> : NonNullable<T>;
declare const cast: <T>(v: unknown) => T;
declare const noop: () => void;
declare const callAll: <T extends (...a: any[]) => void>(...fns: (T | undefined)[]) => (...a: Parameters<T>) => void;
declare const uuid: () => string;
declare function merge<T, U>(origin: T, patch: U): T & U;
declare const isDev: () => boolean;
declare const isArray: (v: any) => v is any[];
declare const isBoolean: (v: any) => v is boolean;
declare const isObject: (v: any) => v is Record<string, any>;
declare const isNumber: (v: any) => v is number;
declare const isString: (v: any) => v is string;
declare const isFunction: (v: any) => v is Function;
declare const hasProp: <T extends string>(obj: any, prop: T) => obj is Record<T, any>;
declare function warn(m: string): void;
declare function warn(c: boolean, m: string): void;
declare function invariant(m: string): void;
declare function invariant(c: boolean, m: string): void;
export { IndexOptions, add, callAll, cast, chunk, clear, first, fromLength, has, hasProp, invariant, isArray, isBoolean, isDev, isEmpty, isFunction, isNumber, isObject, isString, last, merge, next, nextIndex, noop, prev, prevIndex, remove, removeAt, runIfFn, toArray, uuid, warn };

111

dist/index.js

@@ -0,1 +1,2 @@

"use strict";
var __defProp = Object.defineProperty;

@@ -29,28 +30,13 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;

fromLength: () => fromLength,
getPlatform: () => getPlatform,
has: () => has,
hasProp: () => hasProp,
invariant: () => invariant,
isApple: () => isApple,
isArray: () => isArray,
isBoolean: () => isBoolean,
isCtrlKey: () => isCtrlKey,
isDev: () => isDev,
isDom: () => isDom,
isEmpty: () => isEmpty,
isFirefox: () => isFirefox,
isFunction: () => isFunction,
isIPhone: () => isIPhone,
isIos: () => isIos,
isLeftClick: () => isLeftClick,
isMac: () => isMac,
isModifiedEvent: () => isModifiedEvent,
isMouseEvent: () => isMouseEvent,
isNumber: () => isNumber,
isObject: () => isObject,
isRightClick: () => isRightClick,
isSafari: () => isSafari,
isString: () => isString,
isTouchDevice: () => isTouchDevice,
isTouchEvent: () => isTouchEvent,
last: () => last,

@@ -61,3 +47,2 @@ merge: () => merge,

noop: () => noop,
pipe: () => pipe,
prev: () => prev,

@@ -68,5 +53,2 @@ prevIndex: () => prevIndex,

runIfFn: () => runIfFn,
supportsMouseEvent: () => supportsMouseEvent,
supportsPointerEvent: () => supportsPointerEvent,
supportsTouchEvent: () => supportsTouchEvent,
toArray: () => toArray,

@@ -136,45 +118,6 @@ uuid: () => uuid,

// src/guard.ts
var isDev = () => void 0 !== "production";
var isDom = () => typeof window !== "undefined";
var isArray = (v) => Array.isArray(v);
var isBoolean = (v) => v === true || v === false;
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
var isNumber = (v) => typeof v === "number" && !Number.isNaN(v);
var isString = (v) => typeof v === "string";
var isFunction = (v) => typeof v === "function";
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
// src/platform.ts
function getPlatform() {
var _a;
const agent = navigator.userAgentData;
return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
}
var pt = (v) => isDom() && v.test(getPlatform());
var ua = (v) => isDom() && v.test(navigator.userAgent);
var vn = (v) => isDom() && v.test(navigator.vendor);
var isTouchDevice = isDom() && !!navigator.maxTouchPoints;
var isMac = () => pt(/^Mac/) && !isTouchDevice;
var isIPhone = () => pt(/^iPhone/);
var isSafari = () => isApple() && vn(/apple/i);
var isFirefox = () => ua(/firefox\//i);
var isApple = () => pt(/mac|iphone|ipad|ipod/i);
var isIos = () => isApple() && !isMac();
// src/events.ts
var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
var supportsTouchEvent = () => isDom() && window.ontouchstart === null;
var supportsMouseEvent = () => isDom() && window.onmousedown === null;
var isMouseEvent = (v) => isObject(v) && hasProp(v, "button");
var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
var isLeftClick = (v) => v.button === 0;
var isRightClick = (v) => v.button === 2;
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
var isCtrlKey = (v) => isMac() ? v.metaKey && !v.ctrlKey : v.ctrlKey && !v.metaKey;
// src/functions.ts
var runIfFn = (v, ...a) => {
const res = typeof v === "function" ? v(...a) : v;
return res != null ? res : void 0;
return res ?? void 0;
};

@@ -184,3 +127,2 @@ var cast = (v) => v;

};
var pipe = (...fns) => (v) => fns.reduce((a, b) => b(a), v);
var callAll = (...fns) => (...a) => {

@@ -215,2 +157,12 @@ fns.forEach(function(fn) {

// src/guard.ts
var isDev = () => process.env.NODE_ENV !== "production";
var isArray = (v) => Array.isArray(v);
var isBoolean = (v) => v === true || v === false;
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
var isNumber = (v) => typeof v === "number" && !Number.isNaN(v);
var isString = (v) => typeof v === "string";
var isFunction = (v) => typeof v === "function";
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
// src/warning.ts

@@ -220,3 +172,3 @@ function warn(...a) {

const c = a.length === 2 ? a[0] : true;
if (c && void 0 !== "production") {
if (c && process.env.NODE_ENV !== "production") {
console.warn(m);

@@ -228,6 +180,39 @@ }

const c = a.length === 2 ? a[0] : true;
if (c && void 0 !== "production") {
if (c && process.env.NODE_ENV !== "production") {
throw new Error(m);
}
}
//# sourceMappingURL=index.js.map
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
add,
callAll,
cast,
chunk,
clear,
first,
fromLength,
has,
hasProp,
invariant,
isArray,
isBoolean,
isDev,
isEmpty,
isFunction,
isNumber,
isObject,
isString,
last,
merge,
next,
nextIndex,
noop,
prev,
prevIndex,
remove,
removeAt,
runIfFn,
toArray,
uuid,
warn
});
{
"name": "@zag-js/utils",
"version": "0.0.0-dev-20220605192656",
"version": "0.0.0-dev-20220714091855",
"description": "",

@@ -28,10 +28,11 @@ "keywords": [

"scripts": {
"build:fast": "zag build",
"start": "zag build --watch",
"build": "zag build --prod",
"build-fast": "tsup src/index.ts --format=esm,cjs",
"start": "pnpm build --watch",
"build": "tsup src/index.ts --format=esm,cjs --dts",
"test": "jest --config ../../../jest.config.js --rootDir . --passWithNoTests",
"lint": "eslint src --ext .ts,.tsx",
"test:ci": "yarn test --ci --runInBand",
"test:watch": "yarn test --watch --updateSnapshot"
"test-ci": "pnpm test --ci --runInBand",
"test-watch": "pnpm test --watch -u",
"typecheck": "tsc --noEmit"
}
}

Sorry, the diff of this file is not supported yet

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