Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@contember/utilities

Package Overview
Dependencies
Maintainers
5
Versions
109
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@contember/utilities - npm Package Compare versions

Comparing version 1.2.0-beta.3 to 1.2.0-rc.0

dist/development/dom/stateDataAttributes.js

24

dist/development/assert-types/Predicates.js

@@ -28,2 +28,5 @@ function isNull(value) {

}
function isSlugString(value) {
return isNonEmptyString(value) && /^[a-z0-9_-]+$/.test(value);
}
function isNonEmptyString(value) {

@@ -49,7 +52,17 @@ return isString(value) && value.length > 0;

}
function isOneOfFactory(options) {
return function isOneOfProduct(value) {
return options.includes(value);
function isOneOfFactory(members) {
return function isOneOfFactoryProduct(value) {
return members.includes(value);
};
}
function satisfiesOneOfFactory(...predicates) {
return (value) => {
return predicates.some((predicate) => predicate(value));
};
}
function isArrayOfMembersSatisfyingFactory(predicate) {
return function isArrayOfMembersSatisfyingProduct(value) {
return Array.isArray(value) && value.every(predicate);
};
}
function isHTMLElement(value) {

@@ -65,2 +78,3 @@ return value instanceof HTMLElement;

export {
isArrayOfMembersSatisfyingFactory,
isBoolean,

@@ -83,6 +97,8 @@ isDefined,

isPlainObject,
isSlugString,
isString,
isTrue,
isUndefined
isUndefined,
satisfiesOneOfFactory
};
//# sourceMappingURL=Predicates.js.map

9

dist/development/class-name/stateClassName.js

@@ -1,8 +0,5 @@

const UPPER_CASE_REG_EXP = /([A-Z])/g;
function toKebabCase(value) {
return value.replace(UPPER_CASE_REG_EXP, "-$1").toLowerCase();
}
function stateClassName(state = null, glue = "-") {
import { toKebabCase } from "../string-utilities/kebabCase.js";
function stateClassName(state = null, { glue = "-", removeFalsy = true } = {}) {
const entries = Object.entries(state ?? []).map(
([className, value]) => value || value === 0 ? value === true ? toKebabCase(className) : `${toKebabCase(className)}${glue}${value}` : ""
([className, value]) => value || value === 0 || !removeFalsy ? value === true ? toKebabCase(className) : `${toKebabCase(className)}${glue}${value}` : ""
).filter(Boolean);

@@ -9,0 +6,0 @@ return entries;

import { AssertionError } from "./assert-types/AssertionError.js";
import { isBoolean, isDefined, isFalse, isHTMLElement, isNonEmptyString, isNonEmptyTrimmedEndString, isNonEmptyTrimmedStartString, isNonEmptyTrimmedString, isNonNegativeNumber, isNotNull, isNotNullish, isNull, isNumber, isNumericString, isObject, isOneOfFactory, isPlainObject, isString, isTrue, isUndefined } from "./assert-types/Predicates.js";
import { isArrayOfMembersSatisfyingFactory, isBoolean, isDefined, isFalse, isHTMLElement, isNonEmptyString, isNonEmptyTrimmedEndString, isNonEmptyTrimmedStartString, isNonEmptyTrimmedString, isNonNegativeNumber, isNotNull, isNotNullish, isNull, isNumber, isNumericString, isObject, isOneOfFactory, isPlainObject, isSlugString, isString, isTrue, isUndefined, satisfiesOneOfFactory } from "./assert-types/Predicates.js";
import { assert } from "./assert-types/assert.js";

@@ -16,6 +16,9 @@ import { assertNever } from "./assert-types/assertNever.js";

import { parseTransformMatrix } from "./dom/parseTransformMatrix.js";
import { stateDataAttributes } from "./dom/stateDataAttributes.js";
import { svgSizeProps } from "./dom/svgSizeProps.js";
import { omit } from "./functional/omit.js";
import { pick } from "./functional/pick.js";
import { setHasOneOf } from "./functional/setHasOneOf.js";
import { capitalize } from "./string-utilities/capitalize.js";
import { toKebabCase } from "./string-utilities/kebabCase.js";
import { trimString } from "./string-utilities/trimString.js";

@@ -31,2 +34,3 @@ export {

getSizeFromResizeObserverEntryFactory,
isArrayOfMembersSatisfyingFactory,
isBoolean,

@@ -50,2 +54,3 @@ isDefined,

isScrollable,
isSlugString,
isString,

@@ -55,8 +60,12 @@ isTrue,

listClassName,
omit,
parseTransformMatrix,
pick,
px,
satisfiesOneOfFactory,
setHasOneOf,
stateClassName,
stateDataAttributes,
svgSizeProps,
toKebabCase,
trimString,

@@ -63,0 +72,0 @@ useClassName,

@@ -28,2 +28,5 @@ function isNull(value) {

}
function isSlugString(value) {
return isNonEmptyString(value) && /^[a-z0-9_-]+$/.test(value);
}
function isNonEmptyString(value) {

@@ -49,7 +52,17 @@ return isString(value) && value.length > 0;

}
function isOneOfFactory(options) {
return function isOneOfProduct(value) {
return options.includes(value);
function isOneOfFactory(members) {
return function isOneOfFactoryProduct(value) {
return members.includes(value);
};
}
function satisfiesOneOfFactory(...predicates) {
return (value) => {
return predicates.some((predicate) => predicate(value));
};
}
function isArrayOfMembersSatisfyingFactory(predicate) {
return function isArrayOfMembersSatisfyingProduct(value) {
return Array.isArray(value) && value.every(predicate);
};
}
function isHTMLElement(value) {

@@ -65,2 +78,3 @@ return value instanceof HTMLElement;

export {
isArrayOfMembersSatisfyingFactory,
isBoolean,

@@ -83,6 +97,8 @@ isDefined,

isPlainObject,
isSlugString,
isString,
isTrue,
isUndefined
isUndefined,
satisfiesOneOfFactory
};
//# sourceMappingURL=Predicates.js.map

@@ -1,8 +0,5 @@

const UPPER_CASE_REG_EXP = /([A-Z])/g;
function toKebabCase(value) {
return value.replace(UPPER_CASE_REG_EXP, "-$1").toLowerCase();
}
function stateClassName(state = null, glue = "-") {
import { toKebabCase } from "../string-utilities/kebabCase.js";
function stateClassName(state = null, { glue = "-", removeFalsy = true } = {}) {
const entries = Object.entries(state ?? []).map(
([className, value]) => value || value === 0 ? value === true ? toKebabCase(className) : `${toKebabCase(className)}${glue}${value}` : ""
([className, value]) => value || value === 0 || !removeFalsy ? value === true ? toKebabCase(className) : `${toKebabCase(className)}${glue}${value}` : ""
).filter(Boolean);

@@ -9,0 +6,0 @@ return entries;

import { AssertionError } from "./assert-types/AssertionError.js";
import { isBoolean, isDefined, isFalse, isHTMLElement, isNonEmptyString, isNonEmptyTrimmedEndString, isNonEmptyTrimmedStartString, isNonEmptyTrimmedString, isNonNegativeNumber, isNotNull, isNotNullish, isNull, isNumber, isNumericString, isObject, isOneOfFactory, isPlainObject, isString, isTrue, isUndefined } from "./assert-types/Predicates.js";
import { isArrayOfMembersSatisfyingFactory, isBoolean, isDefined, isFalse, isHTMLElement, isNonEmptyString, isNonEmptyTrimmedEndString, isNonEmptyTrimmedStartString, isNonEmptyTrimmedString, isNonNegativeNumber, isNotNull, isNotNullish, isNull, isNumber, isNumericString, isObject, isOneOfFactory, isPlainObject, isSlugString, isString, isTrue, isUndefined, satisfiesOneOfFactory } from "./assert-types/Predicates.js";
import { assert } from "./assert-types/assert.js";

@@ -16,6 +16,9 @@ import { assertNever } from "./assert-types/assertNever.js";

import { parseTransformMatrix } from "./dom/parseTransformMatrix.js";
import { stateDataAttributes } from "./dom/stateDataAttributes.js";
import { svgSizeProps } from "./dom/svgSizeProps.js";
import { omit } from "./functional/omit.js";
import { pick } from "./functional/pick.js";
import { setHasOneOf } from "./functional/setHasOneOf.js";
import { capitalize } from "./string-utilities/capitalize.js";
import { toKebabCase } from "./string-utilities/kebabCase.js";
import { trimString } from "./string-utilities/trimString.js";

@@ -31,2 +34,3 @@ export {

getSizeFromResizeObserverEntryFactory,
isArrayOfMembersSatisfyingFactory,
isBoolean,

@@ -50,2 +54,3 @@ isDefined,

isScrollable,
isSlugString,
isString,

@@ -55,8 +60,12 @@ isTrue,

listClassName,
omit,
parseTransformMatrix,
pick,
px,
satisfiesOneOfFactory,
setHasOneOf,
stateClassName,
stateDataAttributes,
svgSizeProps,
toKebabCase,
trimString,

@@ -63,0 +72,0 @@ useClassName,

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

export declare function assert<In, Out extends In>(that: string | undefined, value: In, predicate: (value: In) => value is Out): asserts value is Out;
import { Predicate } from './types';
export declare function assert<In, Out extends In>(that: string | undefined, value: In, predicate: Predicate<In, Out>): asserts value is Out;
//# sourceMappingURL=assert.d.ts.map

@@ -5,2 +5,3 @@ export * from './AssertionError';

export * from './assertNever';
export * from './types';
//# sourceMappingURL=index.d.ts.map

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

import { Predicate, SlugString, UnionOfPredicateTypes } from './types';
export declare function isNull(value: unknown): value is null;

@@ -10,2 +11,3 @@ export declare function isNotNull<T>(value: unknown): value is T;

export declare function isString(value: unknown): value is string;
export declare function isSlugString(value: unknown): value is SlugString;
export declare function isNonEmptyString(value: unknown): value is string;

@@ -18,3 +20,5 @@ export declare const isNonEmptyTrimmedString: (value: unknown) => value is string;

export declare function isNumericString(value: string): value is string;
export declare function isOneOfFactory<U, T = any>(options: T extends Array<U> | ReadonlyArray<U> ? T : never): (value: unknown) => value is U;
export declare function isOneOfFactory<U, T = any>(members: T extends Array<U> | ReadonlyArray<U> ? T : never): (value: unknown) => value is U;
export declare function satisfiesOneOfFactory<T extends Array<Predicate<any, any>>>(...predicates: T): Predicate<unknown, UnionOfPredicateTypes<T>>;
export declare function isArrayOfMembersSatisfyingFactory<T>(predicate: (value: unknown) => value is T): (value: unknown) => value is Array<T>;
export declare function isHTMLElement(value: unknown): value is HTMLElement;

@@ -21,0 +25,0 @@ export declare function isObject(value: unknown): value is Object;

import { ClassNameStateMap } from './Types';
export interface StateClassNameOptions {
glue?: string;
removeFalsy?: boolean;
}
/**

@@ -9,6 +13,8 @@ * Combines a state map of class names into a single string

* @param state - State map object with class names as keys and literals as values.
* @param glue - Glue to use between the class name and the value, default is '-'. Set to '' to disable.
* @param options - Options object
* @param options.glue - Glue to use between the class name and the value, default is '-'. Set to '' to disable.
* @param options.removeFalsy - Whether to remove falsy class names, default is true.
* @returns Combined class names as string
*/
export declare function stateClassName(state?: ClassNameStateMap | null, glue?: string): string[];
export declare function stateClassName(state?: ClassNameStateMap | null, { glue, removeFalsy }?: StateClassNameOptions): string[];
//# sourceMappingURL=stateClassName.d.ts.map

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

import { PropsWithChildren } from 'react';
export type NestedClassName = string | false | null | undefined | (string | false | null | undefined)[] | NestedClassName[];

@@ -5,2 +6,6 @@ export type ClassNameStateMap = {

};
export type ComponentClassNameProps = PropsWithChildren<{
className?: NestedClassName;
componentClassName?: string | string[];
}>;
//# sourceMappingURL=Types.d.ts.map

@@ -6,3 +6,4 @@ export * from './dataAttribute';

export * from './parseTransformMatrix';
export * from './stateDataAttributes';
export * from './svgSizeProps';
//# sourceMappingURL=index.d.ts.map

@@ -0,3 +1,4 @@

export * from './omit';
export * from './pick';
export * from './setHasOneOf';
//# sourceMappingURL=index.d.ts.map

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

export declare function pick<T extends Object, K extends keyof T>(object: T, properties: K[]): Pick<T, K>;
export declare function pick<T extends Object, K extends keyof T>(object: T, properties: ReadonlyArray<K>): Pick<T, K>;
//# sourceMappingURL=pick.d.ts.map

@@ -7,3 +7,3 @@ export * from './assert-types';

export * from './string-utilities';
export * from './typescript-utilities';
export * from './types';
//# sourceMappingURL=index.d.ts.map
export * from './capitalize';
export * from './kebabCase';
export * from './trimString';
//# sourceMappingURL=index.d.ts.map
{
"name": "@contember/utilities",
"license": "Apache-2.0",
"version": "1.2.0-beta.3",
"version": "1.2.0-rc.0",
"type": "module",

@@ -38,3 +38,6 @@ "sideEffects": false,

},
"dependencies": {
"type-fest": "^3.12.0"
},
"stableVersion": "0.0.0"
}
import { AssertionError } from './AssertionError'
import { Predicate } from './types'

@@ -9,3 +10,3 @@ export function assert<

value: In,
predicate: (value: In) => value is Out,
predicate: Predicate<In, Out>, // (value: In) => value is Out,
): asserts value is Out {

@@ -12,0 +13,0 @@ if (!predicate(value)) {

@@ -5,1 +5,2 @@ export * from './AssertionError'

export * from './assertNever'
export * from './types'

@@ -0,1 +1,3 @@

import { Predicate, SlugString, UnionOfPredicateTypes } from './types'
export function isNull(value: unknown): value is null {

@@ -28,2 +30,5 @@ return value === null

}
export function isSlugString(value: unknown): value is SlugString {
return isNonEmptyString(value) && /^[a-z0-9_-]+$/.test(value)
}
export function isNonEmptyString(value: unknown): value is string {

@@ -49,7 +54,23 @@ return isString(value) && value.length > 0

}
export function isOneOfFactory<U, T = any>(options: T extends Array<U> | ReadonlyArray<U> ? T : never): (value: unknown) => value is U {
return function isOneOfProduct(value: unknown): value is U {
return options.includes(value as U)
}
export function isOneOfFactory<U, T = any>(
members: T extends Array<U> | ReadonlyArray<U> ? T : never,
): (value: unknown) => value is U {
return function isOneOfFactoryProduct(value: unknown): value is U {
return members.includes(value as U)
}
}
export function satisfiesOneOfFactory<T extends Array<Predicate<any, any>>>(
...predicates: T
): Predicate<unknown, UnionOfPredicateTypes<T>> {
return (value: any): value is UnionOfPredicateTypes<T> => {
return predicates.some(predicate => predicate(value))
}
}
export function isArrayOfMembersSatisfyingFactory<T>(
predicate: (value: unknown) => value is T,
): (value: unknown) => value is Array<T> {
return function isArrayOfMembersSatisfyingProduct(value: unknown): value is Array<T> {
return Array.isArray(value) && value.every(predicate)
}
}
export function isHTMLElement(value: unknown): value is HTMLElement {

@@ -56,0 +77,0 @@ return value instanceof HTMLElement

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

import { toKebabCase } from '../string-utilities'
import { ClassNameStateMap } from './Types'
const UPPER_CASE_REG_EXP = /([A-Z])/g
function toKebabCase(value: string) {
return value.replace(UPPER_CASE_REG_EXP, '-$1').toLowerCase()
export interface StateClassNameOptions {
glue?: string;
removeFalsy?: boolean;
}

@@ -16,8 +16,13 @@

* @param state - State map object with class names as keys and literals as values.
* @param glue - Glue to use between the class name and the value, default is '-'. Set to '' to disable.
* @param options - Options object
* @param options.glue - Glue to use between the class name and the value, default is '-'. Set to '' to disable.
* @param options.removeFalsy - Whether to remove falsy class names, default is true.
* @returns Combined class names as string
*/
export function stateClassName(state: ClassNameStateMap | null = null, glue = '-'): string[] {
export function stateClassName(
state: ClassNameStateMap | null = null,
{ glue = '-', removeFalsy = true }: StateClassNameOptions = {},
): string[] {
const entries = Object.entries(state ?? []).map(
([className, value]) => value || value === 0
([className, value]) => value || value === 0 || !removeFalsy
? (value === true ? toKebabCase(className) : `${toKebabCase(className)}${glue}${value}`)

@@ -24,0 +29,0 @@ : '',

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

import { PropsWithChildren } from 'react'
export type NestedClassName = string | false | null | undefined | (string | false | null | undefined)[] | NestedClassName[]
export type ClassNameStateMap = { [key: string]: string | number | boolean | null | undefined }
export type ComponentClassNameProps = PropsWithChildren<{
className?: NestedClassName;
componentClassName?: string | string[];
}>

@@ -6,2 +6,3 @@ export * from './dataAttribute'

export * from './parseTransformMatrix'
export * from './stateDataAttributes'
export * from './svgSizeProps'

@@ -1,3 +0,1 @@

import { SVGProps } from 'react'
export interface SvgSizeProps {

@@ -4,0 +2,0 @@ width: number;

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

export * from './omit'
export * from './pick'
export * from './setHasOneOf'

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

export function pick<T extends Object, K extends keyof T>(object: T, properties: K[]): Pick<T, K> {
export function pick<T extends Object, K extends keyof T>(object: T, properties: ReadonlyArray<K>): Pick<T, K> {
const next: Partial<Pick<T, K>> = {}

@@ -3,0 +3,0 @@

@@ -7,2 +7,2 @@ export * from './assert-types'

export * from './string-utilities'
export * from './typescript-utilities'
export * from './types'
export * from './capitalize'
export * from './kebabCase'
export * from './trimString'

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

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc