@sk-web-gui/utils
Advanced tools
Comparing version 0.1.4 to 0.1.5
@@ -7,10 +7,10 @@ "use strict"; | ||
exports.isObject = isObject; | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
// Array assertions | ||
function isArray(value) { | ||
return Array.isArray(value); | ||
} // Object assertions | ||
} | ||
// Object assertions | ||
function isObject(value) { | ||
@@ -20,6 +20,4 @@ var type = typeof value; | ||
} | ||
var __DEV__ = process.env.NODE_ENV !== 'production'; | ||
exports.__DEV__ = __DEV__; | ||
//# sourceMappingURL=assertion.js.map |
@@ -5,9 +5,5 @@ "use strict"; | ||
exports.getValidChildren = getValidChildren; | ||
var React = _interopRequireWildcard(require("react")); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
/** | ||
@@ -14,0 +10,0 @@ * Gets only the valid children of a component, |
@@ -9,7 +9,4 @@ "use strict"; | ||
exports.toRGBA = toRGBA; | ||
var _colorString = _interopRequireDefault(require("color-string")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function hsl2rgb(h, s, l) { | ||
@@ -24,3 +21,2 @@ s = s / 100, l = l / 100; | ||
var b = 0; | ||
if (0 <= h && h < 60) { | ||
@@ -50,5 +46,4 @@ r = c; | ||
b = x; | ||
} // having obtained RGB, convert channels to hex | ||
} | ||
// having obtained RGB, convert channels to hex | ||
r = Math.round((r + m) * 255); | ||
@@ -59,6 +54,4 @@ g = Math.round((g + m) * 255); | ||
} | ||
function hwb2rgb(h, w, b) { | ||
var rgb = hsl2rgb(h, 100, 50); | ||
for (var i = 0; i < 3; ++i) { | ||
@@ -70,12 +63,8 @@ var c = rgb[i] / 255; | ||
} | ||
return rgb; | ||
} | ||
function toRGBA(color) { | ||
var _colorString$get; | ||
if (/^hsla?/.test(color)) { | ||
var colorTuple = _colorString["default"].get.hsl(color); | ||
if (!colorTuple) return; | ||
@@ -85,3 +74,2 @@ return [].concat(hsl2rgb(colorTuple[0], colorTuple[1], colorTuple[2]), [colorTuple[3]]); | ||
var _colorTuple = _colorString["default"].get.rgb(color); | ||
if (!_colorTuple) return; | ||
@@ -91,16 +79,11 @@ return _colorTuple; | ||
var _colorTuple2 = _colorString["default"].get.hwb(color); | ||
if (!_colorTuple2) return; | ||
return [].concat(hwb2rgb(_colorTuple2[0], _colorTuple2[1], _colorTuple2[2]), [_colorTuple2[3]]); | ||
} | ||
return (_colorString$get = _colorString["default"].get(color)) == null ? void 0 : _colorString$get.value; | ||
} | ||
function toRGB(color) { | ||
var _toRGBA; | ||
return (_toRGBA = toRGBA(color)) == null ? void 0 : _toRGBA.slice(0, 3); | ||
} | ||
function toColor(colorStr) { | ||
@@ -107,0 +90,0 @@ var rgba = toRGBA(colorStr); |
@@ -7,9 +7,5 @@ "use strict"; | ||
}; | ||
var _clsx = _interopRequireDefault(require("clsx")); | ||
exports.cx = _clsx["default"]; | ||
var _types = require("./types"); | ||
Object.keys(_types).forEach(function (key) { | ||
@@ -21,5 +17,3 @@ if (key === "default" || key === "__esModule") return; | ||
}); | ||
var _color = require("./color"); | ||
Object.keys(_color).forEach(function (key) { | ||
@@ -31,5 +25,3 @@ if (key === "default" || key === "__esModule") return; | ||
}); | ||
var _assertion = require("./assertion"); | ||
Object.keys(_assertion).forEach(function (key) { | ||
@@ -41,5 +33,3 @@ if (key === "default" || key === "__esModule") return; | ||
}); | ||
var _walkObject = require("./walk-object"); | ||
Object.keys(_walkObject).forEach(function (key) { | ||
@@ -51,5 +41,3 @@ if (key === "default" || key === "__esModule") return; | ||
}); | ||
var _object = require("./object"); | ||
Object.keys(_object).forEach(function (key) { | ||
@@ -61,5 +49,3 @@ if (key === "default" || key === "__esModule") return; | ||
}); | ||
var _children = require("./children"); | ||
Object.keys(_children).forEach(function (key) { | ||
@@ -71,5 +57,3 @@ if (key === "default" || key === "__esModule") return; | ||
}); | ||
var _refs = require("./refs"); | ||
Object.keys(_refs).forEach(function (key) { | ||
@@ -81,5 +65,3 @@ if (key === "default" || key === "__esModule") return; | ||
}); | ||
var _slug = require("./slug"); | ||
Object.keys(_slug).forEach(function (key) { | ||
@@ -91,4 +73,3 @@ if (key === "default" || key === "__esModule") return; | ||
}); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
//# sourceMappingURL=index.js.map |
@@ -7,7 +7,4 @@ "use strict"; | ||
exports.pick = pick; | ||
var _assertion = require("./assertion"); | ||
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
function omit(object, keys) { | ||
@@ -21,3 +18,2 @@ var result = {}; | ||
} | ||
function pick(object, keys) { | ||
@@ -32,3 +28,2 @@ var result = {}; | ||
} | ||
function deepmerge(target, source, options) { | ||
@@ -40,5 +35,3 @@ if (options === void 0) { | ||
} | ||
var output = options.clone ? _extends({}, target) : target; | ||
if ((0, _assertion.isObject)(target) && (0, _assertion.isObject)(source)) { | ||
@@ -50,3 +43,2 @@ Object.keys(source).forEach(function (key) { | ||
} | ||
if ((0, _assertion.isObject)(source[key]) && key in target) { | ||
@@ -60,5 +52,4 @@ // Since `output` is a clone of `target` and we have narrowed `target` in this block we can cast to the same type. | ||
} | ||
return output; | ||
} | ||
//# sourceMappingURL=object.js.map |
@@ -6,12 +6,8 @@ "use strict"; | ||
exports.useForkRef = useForkRef; | ||
var React = _interopRequireWildcard(require("react")); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable @typescript-eslint/ban-ts-comment */ | ||
/* eslint-disable @typescript-eslint/ban-ts-comment */ | ||
function setRef(ref, value) { | ||
@@ -25,3 +21,2 @@ if (typeof ref === 'function') { | ||
} | ||
function useForkRef(refA, refB) { | ||
@@ -32,3 +27,2 @@ return React.useMemo(function () { | ||
} | ||
return function (refValue) { | ||
@@ -35,0 +29,0 @@ setRef(refA, refValue); |
@@ -5,15 +5,12 @@ "use strict"; | ||
exports.toSlug = void 0; | ||
var toSlug = function toSlug(str) { | ||
str = str.replace(/^\s+|\s+$/g, ''); // trim | ||
str = str.toLowerCase(); | ||
str = str.toLowerCase(); // remove accents, swap ñ for n, etc | ||
// remove accents, swap ñ for n, etc | ||
var from = 'åãàáäâẽèéëêìíïîõòóöôùúüûñç·/_,:;'; | ||
var to = 'aaaaaaeeeeeiiiiooooouuuunc------'; | ||
for (var i = 0, l = from.length; i < l; i++) { | ||
str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i)); | ||
} | ||
str = str.replace(/[^a-z0-9 -]/g, '') // remove invalid chars | ||
@@ -25,4 +22,3 @@ .replace(/\s+/g, '-') // collapse whitespace and replace by - | ||
}; | ||
exports.toSlug = toSlug; | ||
//# sourceMappingURL=slug.js.map |
@@ -5,6 +5,5 @@ "use strict"; | ||
exports.walkObject = walkObject; | ||
var _ = require("./"); | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
function walkObject(target, predicate) { | ||
@@ -15,3 +14,2 @@ function inner(value, path) { | ||
} | ||
if ((0, _.isArray)(value)) { | ||
@@ -22,16 +20,13 @@ return value.map(function (item, index) { | ||
} | ||
if ((0, _.isObject)(value)) { | ||
return Object.fromEntries(Object.entries(value).map(function (_ref) { | ||
var key = _ref[0], | ||
child = _ref[1]; | ||
child = _ref[1]; | ||
return [key, inner(child, [].concat(path, [key]))]; | ||
})); | ||
} | ||
return predicate(value, path); | ||
} | ||
return inner(target); | ||
} | ||
//# sourceMappingURL=walk-object.js.map |
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
// Array assertions | ||
export function isArray(value) { | ||
return Array.isArray(value); | ||
} // Object assertions | ||
} | ||
// Object assertions | ||
export function isObject(value) { | ||
@@ -8,0 +10,0 @@ var type = typeof value; |
import * as React from 'react'; | ||
/** | ||
@@ -8,3 +9,2 @@ * Gets only the valid children of a component, | ||
*/ | ||
export function getValidChildren(children) { | ||
@@ -11,0 +11,0 @@ return React.Children.toArray(children).filter(child => /*#__PURE__*/React.isValidElement(child)); |
@@ -11,3 +11,2 @@ import colorString from 'color-string'; | ||
var b = 0; | ||
if (0 <= h && h < 60) { | ||
@@ -37,5 +36,4 @@ r = c; | ||
b = x; | ||
} // having obtained RGB, convert channels to hex | ||
} | ||
// having obtained RGB, convert channels to hex | ||
r = Math.round((r + m) * 255); | ||
@@ -48,3 +46,2 @@ g = Math.round((g + m) * 255); | ||
var rgb = hsl2rgb(h, 100, 50); | ||
for (var i = 0; i < 3; ++i) { | ||
@@ -56,3 +53,2 @@ var c = rgb[i] / 255; | ||
} | ||
return rgb; | ||
@@ -62,3 +58,2 @@ } | ||
var _colorString$get; | ||
if (/^hsla?/.test(color)) { | ||
@@ -70,3 +65,2 @@ var colorTuple = colorString.get.hsl(color); | ||
var _colorTuple = colorString.get.rgb(color); | ||
if (!_colorTuple) return; | ||
@@ -76,7 +70,5 @@ return _colorTuple; | ||
var _colorTuple2 = colorString.get.hwb(color); | ||
if (!_colorTuple2) return; | ||
return [...hwb2rgb(_colorTuple2[0], _colorTuple2[1], _colorTuple2[2]), _colorTuple2[3]]; | ||
} | ||
return (_colorString$get = colorString.get(color)) == null ? void 0 : _colorString$get.value; | ||
@@ -86,3 +78,2 @@ } | ||
var _toRGBA; | ||
return (_toRGBA = toRGBA(color)) == null ? void 0 : _toRGBA.slice(0, 3); | ||
@@ -89,0 +80,0 @@ } |
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
import { isObject } from './assertion'; | ||
@@ -27,5 +26,3 @@ export function omit(object, keys) { | ||
} | ||
var output = options.clone ? _extends({}, target) : target; | ||
if (isObject(target) && isObject(source)) { | ||
@@ -37,3 +34,2 @@ Object.keys(source).forEach(key => { | ||
} | ||
if (isObject(source[key]) && key in target) { | ||
@@ -47,5 +43,4 @@ // Since `output` is a clone of `target` and we have narrowed `target` in this block we can cast to the same type. | ||
} | ||
return output; | ||
} | ||
//# sourceMappingURL=object.js.map |
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable @typescript-eslint/ban-ts-comment */ | ||
@@ -18,3 +17,2 @@ import * as React from 'react'; | ||
} | ||
return refValue => { | ||
@@ -21,0 +19,0 @@ setRef(refA, refValue); |
export var toSlug = str => { | ||
str = str.replace(/^\s+|\s+$/g, ''); // trim | ||
str = str.toLowerCase(); | ||
str = str.toLowerCase(); // remove accents, swap ñ for n, etc | ||
// remove accents, swap ñ for n, etc | ||
var from = 'åãàáäâẽèéëêìíïîõòóöôùúüûñç·/_,:;'; | ||
var to = 'aaaaaaeeeeeiiiiooooouuuunc------'; | ||
for (var i = 0, l = from.length; i < l; i++) { | ||
str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i)); | ||
} | ||
str = str.replace(/[^a-z0-9 -]/g, '') // remove invalid chars | ||
@@ -14,0 +12,0 @@ .replace(/\s+/g, '-') // collapse whitespace and replace by - |
@@ -8,7 +8,5 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
} | ||
if (isArray(value)) { | ||
return value.map((item, index) => inner(item, [...path, String(index)])); | ||
} | ||
if (isObject(value)) { | ||
@@ -20,8 +18,6 @@ return Object.fromEntries(Object.entries(value).map(_ref => { | ||
} | ||
return predicate(value, path); | ||
} | ||
return inner(target); | ||
} | ||
//# sourceMappingURL=walk-object.js.map |
import type { Dict } from './types'; | ||
export declare function omit<T extends Dict, K extends keyof T>(object: T, keys: K[]): Omit<T, K>; | ||
export declare function pick<T extends Dict, K extends keyof T>(object: T, keys: K[]): { [P in K]: T[P]; }; | ||
export declare function deepmerge<T1, T2>(target: Partial<T1>, source: Partial<T2>, options?: { | ||
export declare function deepmerge<T1, T2>(target: Partial<T1> & any, source: Partial<T2> & any, options?: { | ||
clone: boolean; | ||
}): Partial<T1>; | ||
}): any; |
import * as React from 'react'; | ||
declare type ReactRef<T> = React.Ref<T> | React.RefObject<T> | React.MutableRefObject<T>; | ||
type ReactRef<T> = React.Ref<T> | React.RefObject<T> | React.MutableRefObject<T>; | ||
export declare function setRef<T = any>(ref: ReactRef<T> | undefined, value: T): void; | ||
export declare function useForkRef<T = any>(refA: ReactRef<T> | undefined, refB: ReactRef<T> | undefined): ((refValue: T) => void) | null; | ||
export {}; |
@@ -1,3 +0,3 @@ | ||
export declare type Dict<T = any> = Record<string, T>; | ||
export declare type CSSMap = Dict<{ | ||
export type Dict<T = any> = Record<string, T>; | ||
export type CSSMap = Dict<{ | ||
value: string; | ||
@@ -7,8 +7,8 @@ var: string; | ||
}>; | ||
export declare type WithCSSVar<T> = T & { | ||
export type WithCSSVar<T> = T & { | ||
__cssVars: Dict; | ||
__cssMap: CSSMap; | ||
}; | ||
export declare type DeepPartial<T> = { | ||
export type DeepPartial<T> = { | ||
[P in keyof T]?: DeepPartial<T[P]>; | ||
}; |
@@ -1,5 +0,5 @@ | ||
export declare type WalkObjectPredicate<Leaf = unknown> = (value: unknown, path: string[]) => Leaf; | ||
export declare type MappedLeavesObject<Obj, LeafType> = { | ||
export type WalkObjectPredicate<Leaf = unknown> = (value: unknown, path: string[]) => Leaf; | ||
export type MappedLeavesObject<Obj, LeafType> = { | ||
[Prop in keyof Obj]: Obj[Prop] extends Array<any> ? MappedLeavesObject<Obj[Prop][number], LeafType>[] : Obj[Prop] extends object ? MappedLeavesObject<Obj[Prop], LeafType> : LeafType; | ||
}; | ||
export declare function walkObject<Target, LeafType>(target: Target, predicate: WalkObjectPredicate<LeafType>): MappedLeavesObject<Target, ReturnType<WalkObjectPredicate<LeafType>>>; |
{ | ||
"name": "@sk-web-gui/utils", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"sideEffects": false, | ||
@@ -47,3 +47,3 @@ "license": "MIT", | ||
}, | ||
"gitHead": "7f394c9a25f1bd8bcd43d4b259ad025c146b1527" | ||
"gitHead": "3a72018bb2de73c6e1db1a461cbed02b37e4827e" | ||
} |
@@ -0,0 +0,0 @@ ## Installation |
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
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
65256
588