Socket
Socket
Sign inDemoInstall

@chakra-ui/utils

Package Overview
Dependencies
6
Maintainers
4
Versions
257
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.2 to 1.1.0

8

CHANGELOG.md
# Change Log
## 1.1.0
### Minor Changes
- [`8b87406c`](https://github.com/chakra-ui/chakra-ui/commit/8b87406c3132586be3393117eef80d47ec82fc54)
[#3015](https://github.com/chakra-ui/chakra-ui/pull/3015) Thanks
[@with-heart](https://github.com/with-heart)! - Added a `compose` function
## 1.0.2

@@ -4,0 +12,0 @@

55

dist/cjs/dom.js
"use strict";
exports.__esModule = true;
exports.getOwnerWindow = getOwnerWindow;
exports.getOwnerDocument = getOwnerDocument;
exports.canUseDOM = canUseDOM;
exports.normalizeEventKey = normalizeEventKey;
exports.getActiveElement = getActiveElement;
exports.contains = contains;
exports.cx = exports.getDocument = exports.ariaAttr = exports.dataAttr = exports.isBrowser = exports.getWindow = void 0;
var win;
/**
* Note: Accessing "window" in IE11 is somewhat expensive, and calling "typeof window"
* hits a memory leak, whereas aliasing it and calling "typeof win" does not.
* Caching the window value at the file scope lets us minimize the impact.
*
* @see IE11 Memory Leak Issue https://github.com/microsoft/fluentui/pull/9010#issuecomment-490768427
*/
exports.cx = exports.ariaAttr = exports.dataAttr = exports.isBrowser = void 0;
try {
win = window;
} catch (e) {
/* no-op */
function getOwnerWindow(node) {
var _getOwnerDocument$def;
return node instanceof Element ? (_getOwnerDocument$def = getOwnerDocument(node).defaultView) != null ? _getOwnerDocument$def : window : window;
}
/**
* Helper to get the window object. The helper will make sure to use a cached variable
* of "window", to avoid overhead and memory leaks in IE11.
*/
function getOwnerDocument(node) {
var _node$ownerDocument;
var getWindow = function getWindow(node) {
var _node$ownerDocument$d, _node$ownerDocument;
return node instanceof Element ? (_node$ownerDocument = node.ownerDocument) != null ? _node$ownerDocument : document : document;
}
return (_node$ownerDocument$d = node == null ? void 0 : (_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) != null ? _node$ownerDocument$d : win;
};
/**
* Check if we can use the DOM. Useful for SSR purposes
*/
exports.getWindow = getWindow;
function checkIsBrowser() {
var win = getWindow();
return Boolean(typeof win !== "undefined" && win.document && win.document.createElement);
function canUseDOM() {
return !!(typeof window !== "undefined" && window.document && window.document.createElement);
}
var isBrowser = checkIsBrowser();
var isBrowser = canUseDOM();
/**

@@ -73,8 +56,2 @@ * Get the normalized event key across all browsers

var getDocument = function getDocument(node) {
return node != null && node.ownerDocument || isBrowser ? document : null;
};
exports.getDocument = getDocument;
var cx = function cx() {

@@ -91,3 +68,3 @@ for (var _len = arguments.length, classNames = new Array(_len), _key = 0; _key < _len; _key++) {

function getActiveElement(node) {
var doc = getDocument(node);
var doc = getOwnerDocument(node);
return doc == null ? void 0 : doc.activeElement;

@@ -94,0 +71,0 @@ }

@@ -8,3 +8,3 @@ "use strict";

exports.once = once;
exports.error = exports.warn = exports.noop = void 0;
exports.error = exports.warn = exports.noop = exports.compose = void 0;

@@ -46,2 +46,16 @@ var _assertion = require("./assertion");

var compose = function compose(fn1) {
for (var _len4 = arguments.length, fns = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
fns[_key4 - 1] = arguments[_key4];
}
return fns.reduce(function (f1, f2) {
return function () {
return f1(f2.apply(void 0, arguments));
};
}, fn1);
};
exports.compose = compose;
function once(fn) {

@@ -51,4 +65,4 @@ var result;

if (fn) {
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
args[_key4] = arguments[_key4];
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
args[_key5] = arguments[_key5];
}

@@ -55,0 +69,0 @@

@@ -19,7 +19,2 @@ "use strict";

var maxSafeInteger = Number.MAX_SAFE_INTEGER || 9007199254740991;
/**
* Convert a value to number
* @param value the value to convert
*/
exports.maxSafeInteger = maxSafeInteger;

@@ -26,0 +21,0 @@

@@ -66,6 +66,3 @@ "use strict";

for (index = 0; index < key.length; index += 1) {
if (!obj) {
break;
}
if (!obj) break;
obj = obj[key[index]];

@@ -81,2 +78,6 @@ }

var memoizedFn = function memoizedFn(obj, path, fallback, index) {
if (typeof obj === "undefined") {
return fn(obj, path, fallback);
}
if (!cache.has(obj)) {

@@ -113,3 +114,3 @@ cache.set(obj, new Map());

function getWithDefault(path, scale) {
return get(scale, path, path);
return memoizedGet(scale, path, path);
}

@@ -116,0 +117,0 @@

@@ -1,36 +0,15 @@

var win;
/**
* Note: Accessing "window" in IE11 is somewhat expensive, and calling "typeof window"
* hits a memory leak, whereas aliasing it and calling "typeof win" does not.
* Caching the window value at the file scope lets us minimize the impact.
*
* @see IE11 Memory Leak Issue https://github.com/microsoft/fluentui/pull/9010#issuecomment-490768427
*/
export function getOwnerWindow(node) {
var _getOwnerDocument$def;
try {
win = window;
} catch (e) {
/* no-op */
return node instanceof Element ? (_getOwnerDocument$def = getOwnerDocument(node).defaultView) != null ? _getOwnerDocument$def : window : window;
}
/**
* Helper to get the window object. The helper will make sure to use a cached variable
* of "window", to avoid overhead and memory leaks in IE11.
*/
export function getOwnerDocument(node) {
var _node$ownerDocument;
export var getWindow = node => {
var _node$ownerDocument$d, _node$ownerDocument;
return (_node$ownerDocument$d = node == null ? void 0 : (_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) != null ? _node$ownerDocument$d : win;
};
/**
* Check if we can use the DOM. Useful for SSR purposes
*/
function checkIsBrowser() {
var win = getWindow();
return Boolean(typeof win !== "undefined" && win.document && win.document.createElement);
return node instanceof Element ? (_node$ownerDocument = node.ownerDocument) != null ? _node$ownerDocument : document : document;
}
export var isBrowser = checkIsBrowser();
export function canUseDOM() {
return !!(typeof window !== "undefined" && window.document && window.document.createElement);
}
export var isBrowser = canUseDOM();
/**

@@ -52,3 +31,2 @@ * Get the normalized event key across all browsers

export var ariaAttr = condition => condition ? true : undefined;
export var getDocument = node => node != null && node.ownerDocument || isBrowser ? document : null;
export var cx = function cx() {

@@ -62,3 +40,3 @@ for (var _len = arguments.length, classNames = new Array(_len), _key = 0; _key < _len; _key++) {

export function getActiveElement(node) {
var doc = getDocument(node);
var doc = getOwnerDocument(node);
return doc == null ? void 0 : doc.activeElement;

@@ -65,0 +43,0 @@ }

@@ -32,2 +32,11 @@ import { isFunction, __DEV__ } from "./assertion";

}
export var compose = function compose(fn1) {
for (var _len4 = arguments.length, fns = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
fns[_key4 - 1] = arguments[_key4];
}
return fns.reduce((f1, f2) => function () {
return f1(f2(...arguments));
}, fn1);
};
export function once(fn) {

@@ -37,4 +46,4 @@ var result;

if (fn) {
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
args[_key4] = arguments[_key4];
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
args[_key5] = arguments[_key5];
}

@@ -41,0 +50,0 @@

@@ -5,6 +5,2 @@ import { isNotNumber } from "./assertion";

export var maxSafeInteger = Number.MAX_SAFE_INTEGER || 9007199254740991;
/**
* Convert a value to number
* @param value the value to convert
*/

@@ -11,0 +7,0 @@ function toNumber(value) {

@@ -44,6 +44,3 @@ export { default as mergeWith } from "lodash.mergewith";

for (index = 0; index < key.length; index += 1) {
if (!obj) {
break;
}
if (!obj) break;
obj = obj[key[index]];

@@ -58,2 +55,6 @@ }

var memoizedFn = (obj, path, fallback, index) => {
if (typeof obj === "undefined") {
return fn(obj, path, fallback);
}
if (!cache.has(obj)) {

@@ -86,3 +87,3 @@ cache.set(obj, new Map());

export function getWithDefault(path, scale) {
return get(scale, path, path);
return memoizedGet(scale, path, path);
}

@@ -89,0 +90,0 @@

import * as React from "react";
import { Booleanish, EventKeys } from "./types";
/**
* Helper to get the window object. The helper will make sure to use a cached variable
* of "window", to avoid overhead and memory leaks in IE11.
*/
export declare const getWindow: (node?: HTMLElement | null | undefined) => Window | undefined;
export declare function getOwnerWindow(node?: HTMLElement | null): Window & typeof globalThis;
export declare function getOwnerDocument(node?: HTMLElement | null): Document;
export declare function canUseDOM(): boolean;
export declare const isBrowser: boolean;

@@ -16,5 +14,4 @@ /**

export declare const ariaAttr: (condition: boolean | undefined) => true | undefined;
export declare const getDocument: (node?: HTMLElement | null | undefined) => Document | null;
export declare const cx: (...classNames: any[]) => string;
export declare function getActiveElement(node?: HTMLElement): HTMLElement;
export declare function contains(parent: HTMLElement, child: HTMLElement): boolean;

@@ -5,2 +5,3 @@ import { AnyFunction, FunctionArguments } from "./types";

export declare function callAll<T extends AnyFunction>(...fns: (T | undefined)[]): (arg: FunctionArguments<T>[0]) => void;
export declare const compose: <T>(fn1: (...args: T[]) => T, ...fns: ((...args: T[]) => T)[]) => (...args: T[]) => T;
export declare function once(fn?: Function | null): (this: any, ...args: any[]) => any;

@@ -7,0 +8,0 @@ export declare const noop: () => void;

@@ -15,5 +15,5 @@ import type { Dict } from "./types";

export declare function get(obj: object, path: string | number, fallback?: any, index?: number): any;
declare type Handler = (obj: Readonly<object>, path: string | number, fallback?: any, index?: number) => any;
export declare const memoize: (fn: Handler) => Handler;
export declare const memoizedGet: Handler;
declare type Get = (obj: Readonly<object>, path: string | number, fallback?: any, index?: number) => any;
export declare const memoize: (fn: Get) => Get;
export declare const memoizedGet: Get;
/**

@@ -20,0 +20,0 @@ * Get value from deeply nested object, based on path

{
"name": "@chakra-ui/utils",
"version": "1.0.2",
"version": "1.1.0",
"description": "Common utilties and types for Chakra UI",

@@ -53,3 +53,3 @@ "author": "Segun Adebayo <sage@adebayosegun.com>",

"peerDependencies": {
"react": "16.x || 17.x"
"react": ">=16.8.6"
},

@@ -56,0 +56,0 @@ "devDependencies": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc