@contember/utilities
Advanced tools
Comparing version 1.2.0-rc.17 to 1.2.0-rc.18
@@ -31,2 +31,5 @@ function isNull(value) { | ||
} | ||
function isSingleWordString(value) { | ||
return isNonEmptyString(value) && value.indexOf(" ") === -1; | ||
} | ||
function isNonEmptyString(value) { | ||
@@ -67,2 +70,5 @@ return isString(value) && value.length > 0; | ||
} | ||
function isNonEmptyArray(value) { | ||
return Array.isArray(value) && value.length > 0; | ||
} | ||
function isHTMLElement(value) { | ||
@@ -83,2 +89,3 @@ return value instanceof HTMLElement; | ||
isHTMLElement, | ||
isNonEmptyArray, | ||
isNonEmptyString, | ||
@@ -97,2 +104,3 @@ isNonEmptyTrimmedEndString, | ||
isPlainObject, | ||
isSingleWordString, | ||
isSlugString, | ||
@@ -99,0 +107,0 @@ isString, |
import { AssertionError } from "./assert-types/AssertionError.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 { isArrayOfMembersSatisfyingFactory, isBoolean, isDefined, isFalse, isHTMLElement, isNonEmptyArray, isNonEmptyString, isNonEmptyTrimmedEndString, isNonEmptyTrimmedStartString, isNonEmptyTrimmedString, isNonNegativeNumber, isNotNull, isNotNullish, isNull, isNumber, isNumericString, isObject, isOneOfFactory, isPlainObject, isSingleWordString, isSlugString, isString, isTrue, isUndefined, satisfiesOneOfFactory } from "./assert-types/Predicates.js"; | ||
import { assert } from "./assert-types/assert.js"; | ||
@@ -56,2 +56,3 @@ import { assertNever } from "./assert-types/assertNever.js"; | ||
isHTMLElement, | ||
isNonEmptyArray, | ||
isNonEmptyString, | ||
@@ -71,2 +72,3 @@ isNonEmptyTrimmedEndString, | ||
isScrollable, | ||
isSingleWordString, | ||
isSlugString, | ||
@@ -73,0 +75,0 @@ isString, |
@@ -31,2 +31,5 @@ function isNull(value) { | ||
} | ||
function isSingleWordString(value) { | ||
return isNonEmptyString(value) && value.indexOf(" ") === -1; | ||
} | ||
function isNonEmptyString(value) { | ||
@@ -67,2 +70,5 @@ return isString(value) && value.length > 0; | ||
} | ||
function isNonEmptyArray(value) { | ||
return Array.isArray(value) && value.length > 0; | ||
} | ||
function isHTMLElement(value) { | ||
@@ -83,2 +89,3 @@ return value instanceof HTMLElement; | ||
isHTMLElement, | ||
isNonEmptyArray, | ||
isNonEmptyString, | ||
@@ -97,2 +104,3 @@ isNonEmptyTrimmedEndString, | ||
isPlainObject, | ||
isSingleWordString, | ||
isSlugString, | ||
@@ -99,0 +107,0 @@ isString, |
import { AssertionError } from "./assert-types/AssertionError.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 { isArrayOfMembersSatisfyingFactory, isBoolean, isDefined, isFalse, isHTMLElement, isNonEmptyArray, isNonEmptyString, isNonEmptyTrimmedEndString, isNonEmptyTrimmedStartString, isNonEmptyTrimmedString, isNonNegativeNumber, isNotNull, isNotNullish, isNull, isNumber, isNumericString, isObject, isOneOfFactory, isPlainObject, isSingleWordString, isSlugString, isString, isTrue, isUndefined, satisfiesOneOfFactory } from "./assert-types/Predicates.js"; | ||
import { assert } from "./assert-types/assert.js"; | ||
@@ -56,2 +56,3 @@ import { assertNever } from "./assert-types/assertNever.js"; | ||
isHTMLElement, | ||
isNonEmptyArray, | ||
isNonEmptyString, | ||
@@ -71,2 +72,3 @@ isNonEmptyTrimmedEndString, | ||
isScrollable, | ||
isSingleWordString, | ||
isSlugString, | ||
@@ -73,0 +75,0 @@ isString, |
@@ -12,2 +12,3 @@ import { Predicate, SlugString, UnionOfPredicateTypes } from './types'; | ||
export declare function isSlugString(value: unknown): value is SlugString; | ||
export declare function isSingleWordString(value: unknown): value is string; | ||
export declare function isNonEmptyString(value: unknown): value is string; | ||
@@ -23,2 +24,3 @@ export declare const isNonEmptyTrimmedString: (value: unknown) => value is string; | ||
export declare function isArrayOfMembersSatisfyingFactory<T>(predicate: (value: unknown) => value is T): (value: unknown) => value is Array<T>; | ||
export declare function isNonEmptyArray<T>(value: unknown): value is [T, ...T[]]; | ||
export declare function isHTMLElement(value: unknown): value is HTMLElement; | ||
@@ -25,0 +27,0 @@ export declare function isObject(value: unknown): value is Object; |
@@ -37,2 +37,11 @@ export type PropsOf<C extends keyof JSX.IntrinsicElements | React.JSXElementConstructor<any>> = JSX.LibraryManagedAttributes<C, React.ComponentPropsWithoutRef<C>>; | ||
}; | ||
/** | ||
* A polymorphic component is a component that can be rendered as different | ||
* HTML elements or other React components by specifying the `as` prop. | ||
* This type allows for specifying the component (`C`) and the props (`P`) | ||
* that the component accepts. | ||
*/ | ||
export type PolymorphicComponent<T extends React.ElementType, P = {}> = (<C extends React.ElementType = T>(props: PolymorphicComponentPropsWithRef<C, P>) => React.ReactElement | null) & { | ||
displayName?: string | undefined; | ||
}; | ||
//# sourceMappingURL=PolymorphicRefs.d.ts.map |
{ | ||
"name": "@contember/utilities", | ||
"license": "Apache-2.0", | ||
"version": "1.2.0-rc.17", | ||
"version": "1.2.0-rc.18", | ||
"type": "module", | ||
@@ -6,0 +6,0 @@ "sideEffects": false, |
import { Predicate, SlugString, UnionOfPredicateTypes } from './types' | ||
export function isNull(value: unknown): value is null { | ||
return value === null | ||
return value === null | ||
} | ||
export function isNotNull<T>(value: unknown): value is T { | ||
return value !== null | ||
return value !== null | ||
} | ||
export function isUndefined(value: unknown): value is undefined { | ||
return value === undefined | ||
return value === undefined | ||
} | ||
export function isDefined<T>(value: unknown): value is Exclude<T, undefined> { | ||
return value !== undefined | ||
return value !== undefined | ||
} | ||
export function isNotNullish<T>(value: T): value is Exclude<T, null | undefined> { | ||
return value != null | ||
return value != null | ||
} | ||
export function isBoolean(value: unknown): value is boolean { | ||
return typeof value === 'boolean' | ||
return typeof value === 'boolean' | ||
} | ||
export function isTrue(value: unknown): value is true { | ||
return value === true | ||
return value === true | ||
} | ||
export function isFalse(value: unknown): value is false { | ||
return value === false | ||
return value === false | ||
} | ||
export function isString(value: unknown): value is string { | ||
return typeof value === 'string' | ||
return typeof value === 'string' | ||
} | ||
@@ -33,9 +33,12 @@ export function isSlugString(value: unknown): value is SlugString { | ||
} | ||
export function isSingleWordString(value: unknown): value is string { | ||
return isNonEmptyString(value) && value.indexOf(' ') === -1 | ||
} | ||
export function isNonEmptyString(value: unknown): value is string { | ||
return isString(value) && value.length > 0 | ||
return isString(value) && value.length > 0 | ||
} | ||
function isNonEmptyTrimmedStringFactory(trim: 'trim' | 'trimStart' | 'trimEnd' = 'trim') { | ||
return function isNonEmptyString(value: unknown): value is string { | ||
return isString(value) && value[trim]().length > 0 | ||
} | ||
return function isNonEmptyString(value: unknown): value is string { | ||
return isString(value) && value[trim]().length > 0 | ||
} | ||
} | ||
@@ -46,9 +49,9 @@ export const isNonEmptyTrimmedString = isNonEmptyTrimmedStringFactory() | ||
export function isNumber(value: unknown): value is number { | ||
return typeof value === 'number' && value === value | ||
return typeof value === 'number' && value === value | ||
} | ||
export function isNonNegativeNumber(value: unknown): value is number { | ||
return isNumber(value) && value >= 0 | ||
return isNumber(value) && value >= 0 | ||
} | ||
export function isNumericString(value: string): value is string { | ||
return isString(value) && !isNaN(parseFloat(value)) | ||
return isString(value) && !isNaN(parseFloat(value)) | ||
} | ||
@@ -76,10 +79,13 @@ export function isOneOfFactory<U, T = any>( | ||
} | ||
export function isNonEmptyArray<T>(value: unknown): value is [T, ...T[]] { | ||
return Array.isArray(value) && value.length > 0 | ||
} | ||
export function isHTMLElement(value: unknown): value is HTMLElement { | ||
return value instanceof HTMLElement | ||
return value instanceof HTMLElement | ||
} | ||
export function isObject(value: unknown): value is Object { | ||
return typeof value === 'object' && value !== null | ||
return typeof value === 'object' && value !== null | ||
} | ||
export function isPlainObject<T extends Record<string, unknown>>(value: unknown): value is T { | ||
return isObject(value) && value.constructor === Object | ||
return isObject(value) && value.constructor === Object | ||
} |
@@ -59,1 +59,11 @@ // Source: https://www.benmvp.com/blog/forwarding-refs-polymorphic-react-component-typescript/ | ||
> = PolymorphicComponentProps<C, Props> & { ref?: PolymorphicRef<C> } | ||
/** | ||
* A polymorphic component is a component that can be rendered as different | ||
* HTML elements or other React components by specifying the `as` prop. | ||
* This type allows for specifying the component (`C`) and the props (`P`) | ||
* that the component accepts. | ||
*/ | ||
export type PolymorphicComponent<T extends React.ElementType, P = {}> = | ||
& (<C extends React.ElementType = T>(props: PolymorphicComponentPropsWithRef<C, P>) => React.ReactElement | null) | ||
& { displayName?: string | undefined } |
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
235720
2629