0.12.0 • Published 2 years ago
pheno v0.12.0
pheno
Simple, lightweight at-runtime type checking functions, with full TypeScript support
Features
- Full TypeScript integration: TypeScript understands that
assertTypeandisOfTypenarrow the types of things, and will refine them accordingly - Simple: Type validators are just functions that return booleans.
- Effective: There's lots of utility functions that help you represent all the various types you'd care about in your code.
- Lightweight: The whole library is 18K minified (4.5K gzipped, 4.1K brotli-ified).
Usage Example
import * as types from "pheno";
function something(first: unknown, second: unknown) {
// Throws an error if `first` is not a string
types.assertType(first, types.string);
// Throws an error if `second` is not `string | number`
types.assertType(second, types.union(types.string, types.number));
// Typescript now knows that `first` is a string and `second` is `string | number`
return first + " " + String(second);
}List of types and type builder functions
andanyanyArrayanyFunctionanyMapanyObjectanySetanyTypeValidatorarray(alias ofarrayOfUnknown)arrayOfarrayOfAnyarrayOfUnknownArray(alias ofarrayOfUnknown)assertType(assert that a value has the provided type, and throw an error message if it doesn't)asType(do a TypeScriptascast to convert the value into the provided type)bigintBigInt(alias ofbigint)booleanBoolean(alias ofboolean)DateErrorexactBigIntexactNumberexactStringexactSymbolfalsefalsyFunction(alias ofunknownFunction)hasClassNamehasToStringTagInfinityinstanceOfintegerintersectionisOfType(return a boolean indicating if a value is of the provided type)map(alias ofunknownMap)Map(alias ofunknownMap)mapOfmappingObjectOfmaybeNaNNegativeInfinitynevernonNullOrUndefinednullnullishvoid(alias ofnullish)number(doesn't include NaN, Infinity, or -Infinity)Number(alias ofnumber)numberIncludingNanAndInfinitiesobject(alias ofunknownObject)Object(alias ofunknownObject)objectOrNullobjectWithOnlyThesePropertiesobjectWithPropertiesoroptionalpartialObjectWithPropertiesrecordRegExpset(alias ofunknownSet)Set(alias ofunknownSet)setOfstringString(alias ofstring)stringifyValue(safe and lightweight value-to-string function, for printing values in error messages)stringMatchingSymbolsymbol(alias ofSymbol)symbolFortruetruthytupleundefinedunionunknownunknownFunctionunknownMapunknownObjectunknownSetunknownTypeValidatorArrayBufferSharedArrayBufferDataViewTypedArrayInt8ArrayUint8ArrayUint8ClampedArrayInt16ArrayUint16ArrayInt32ArrayUint32ArrayFloat32ArrayFloat64Array
Please see the TypeScript types for each of these in either your editor's autocomplete or pheno's source code for more information.
License
MIT
0.12.0
2 years ago
0.10.0
2 years ago
0.11.0
2 years ago
0.10.1
2 years ago
0.9.0
2 years ago
0.8.0
2 years ago
0.9.2
2 years ago
0.9.1
2 years ago
0.7.1
3 years ago
0.7.0
3 years ago
0.6.1
3 years ago
0.5.2
3 years ago
0.6.0
3 years ago
0.5.1
3 years ago
0.5.0
3 years ago
0.4.1
4 years ago
0.4.0
4 years ago
0.4.2
4 years ago
0.3.1
4 years ago
0.3.0
4 years ago
0.2.0
4 years ago
0.1.0
4 years ago
0.0.0
4 years ago