@danielsimonjr/mathts-typed-function 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +105 -0
- package/dist/index.js +80 -0
- package/package.json +56 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
export { TypedFunction, create, default as typed } from 'typed-function';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @danielsimonjr/mathts-typed-function
|
|
5
|
+
*
|
|
6
|
+
* Utility helpers for typed-function integration in MathTS.
|
|
7
|
+
* This package provides type test functions and signature utilities.
|
|
8
|
+
*
|
|
9
|
+
* NOTE: For creating typed functions, use typed-function directly:
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import typed, { create } from 'typed-function';
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Or use @danielsimonjr/mathts-core which provides mathTyped pre-configured with MathTS types:
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { mathTyped } from '@danielsimonjr/mathts-core';
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @packageDocumentation
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Type definition for typed-function
|
|
24
|
+
*/
|
|
25
|
+
interface TypeDef {
|
|
26
|
+
name: string;
|
|
27
|
+
test: (x: unknown) => boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Conversion definition for typed-function
|
|
31
|
+
*/
|
|
32
|
+
interface ConversionDef {
|
|
33
|
+
from: string;
|
|
34
|
+
to: string;
|
|
35
|
+
convert: (value: unknown) => unknown;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Signature map for typed functions
|
|
39
|
+
*/
|
|
40
|
+
type SignatureMap<T = unknown> = {
|
|
41
|
+
[signature: string]: (...args: unknown[]) => T;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Type test function
|
|
45
|
+
*/
|
|
46
|
+
type TypeTest<T> = (x: unknown) => x is T;
|
|
47
|
+
/**
|
|
48
|
+
* Type conversion function
|
|
49
|
+
*/
|
|
50
|
+
type TypeConverter<From, To> = (value: From) => To;
|
|
51
|
+
declare const isNumber: (x: unknown) => x is number;
|
|
52
|
+
declare const isBoolean: (x: unknown) => x is boolean;
|
|
53
|
+
declare const isString: (x: unknown) => x is string;
|
|
54
|
+
declare const isBigInt: (x: unknown) => x is bigint;
|
|
55
|
+
declare const isArray: (x: unknown) => x is unknown[];
|
|
56
|
+
declare const isFunction: (x: unknown) => x is (...args: unknown[]) => unknown;
|
|
57
|
+
declare const isObject: (x: unknown) => x is object;
|
|
58
|
+
declare const isNull: (x: unknown) => x is null;
|
|
59
|
+
declare const isUndefined: (x: unknown) => x is undefined;
|
|
60
|
+
declare const isNullOrUndefined: (x: unknown) => x is null | undefined;
|
|
61
|
+
declare const isFiniteNumber: (x: unknown) => x is number;
|
|
62
|
+
declare const isInteger: (x: unknown) => x is number;
|
|
63
|
+
declare const isPositiveInteger: (x: unknown) => x is number;
|
|
64
|
+
declare const isNonNegativeInteger: (x: unknown) => x is number;
|
|
65
|
+
declare const isNaN: (x: unknown) => x is number;
|
|
66
|
+
declare const isTypedArray: (x: unknown) => x is ArrayBufferView;
|
|
67
|
+
declare const isFloat64Array: (x: unknown) => x is Float64Array;
|
|
68
|
+
declare const isFloat32Array: (x: unknown) => x is Float32Array;
|
|
69
|
+
declare const isInt32Array: (x: unknown) => x is Int32Array;
|
|
70
|
+
declare const isUint32Array: (x: unknown) => x is Uint32Array;
|
|
71
|
+
declare const isArrayBuffer: (x: unknown) => x is ArrayBuffer;
|
|
72
|
+
/**
|
|
73
|
+
* Parse a signature string into component types
|
|
74
|
+
*
|
|
75
|
+
* @param signature - Signature string (e.g., "number, number")
|
|
76
|
+
* @returns Array of type names
|
|
77
|
+
*/
|
|
78
|
+
declare function parseSignature(signature: string): string[];
|
|
79
|
+
/**
|
|
80
|
+
* Build a signature string from type names
|
|
81
|
+
*
|
|
82
|
+
* @param types - Array of type names
|
|
83
|
+
* @returns Signature string
|
|
84
|
+
*/
|
|
85
|
+
declare function buildSignature(...types: string[]): string;
|
|
86
|
+
/**
|
|
87
|
+
* Error thrown when no matching signature is found
|
|
88
|
+
*/
|
|
89
|
+
declare class NoMatchingSignatureError extends Error {
|
|
90
|
+
readonly functionName: string;
|
|
91
|
+
readonly actualTypes: string[];
|
|
92
|
+
readonly availableSignatures: string[];
|
|
93
|
+
constructor(functionName: string, actualTypes: string[], availableSignatures: string[]);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Error thrown when type conversion fails
|
|
97
|
+
*/
|
|
98
|
+
declare class TypeConversionError extends Error {
|
|
99
|
+
readonly fromType: string;
|
|
100
|
+
readonly toType: string;
|
|
101
|
+
readonly originalError?: Error | undefined;
|
|
102
|
+
constructor(fromType: string, toType: string, originalError?: Error | undefined);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export { type ConversionDef, NoMatchingSignatureError, type SignatureMap, TypeConversionError, type TypeConverter, type TypeDef, type TypeTest, buildSignature, isArray, isArrayBuffer, isBigInt, isBoolean, isFiniteNumber, isFloat32Array, isFloat64Array, isFunction, isInt32Array, isInteger, isNaN, isNonNegativeInteger, isNull, isNullOrUndefined, isNumber, isObject, isPositiveInteger, isString, isTypedArray, isUint32Array, isUndefined, parseSignature };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { default as default2, create } from "typed-function";
|
|
3
|
+
var isNumber = (x) => typeof x === "number";
|
|
4
|
+
var isBoolean = (x) => typeof x === "boolean";
|
|
5
|
+
var isString = (x) => typeof x === "string";
|
|
6
|
+
var isBigInt = (x) => typeof x === "bigint";
|
|
7
|
+
var isArray = (x) => Array.isArray(x);
|
|
8
|
+
var isFunction = (x) => typeof x === "function";
|
|
9
|
+
var isObject = (x) => typeof x === "object" && x !== null && !Array.isArray(x);
|
|
10
|
+
var isNull = (x) => x === null;
|
|
11
|
+
var isUndefined = (x) => x === void 0;
|
|
12
|
+
var isNullOrUndefined = (x) => x === null || x === void 0;
|
|
13
|
+
var isFiniteNumber = (x) => typeof x === "number" && isFinite(x);
|
|
14
|
+
var isInteger = (x) => typeof x === "number" && Number.isInteger(x);
|
|
15
|
+
var isPositiveInteger = (x) => typeof x === "number" && Number.isInteger(x) && x > 0;
|
|
16
|
+
var isNonNegativeInteger = (x) => typeof x === "number" && Number.isInteger(x) && x >= 0;
|
|
17
|
+
var isNaN = (x) => typeof x === "number" && Number.isNaN(x);
|
|
18
|
+
var isTypedArray = (x) => ArrayBuffer.isView(x) && !(x instanceof DataView);
|
|
19
|
+
var isFloat64Array = (x) => x instanceof Float64Array;
|
|
20
|
+
var isFloat32Array = (x) => x instanceof Float32Array;
|
|
21
|
+
var isInt32Array = (x) => x instanceof Int32Array;
|
|
22
|
+
var isUint32Array = (x) => x instanceof Uint32Array;
|
|
23
|
+
var isArrayBuffer = (x) => x instanceof ArrayBuffer;
|
|
24
|
+
function parseSignature(signature) {
|
|
25
|
+
return signature.split(",").map((s) => s.trim()).filter((s) => s.length > 0);
|
|
26
|
+
}
|
|
27
|
+
function buildSignature(...types) {
|
|
28
|
+
return types.join(", ");
|
|
29
|
+
}
|
|
30
|
+
var NoMatchingSignatureError = class extends Error {
|
|
31
|
+
constructor(functionName, actualTypes, availableSignatures) {
|
|
32
|
+
super(
|
|
33
|
+
`No matching signature found for ${functionName}(${actualTypes.join(", ")}). Available signatures: ${availableSignatures.join("; ")}`
|
|
34
|
+
);
|
|
35
|
+
this.functionName = functionName;
|
|
36
|
+
this.actualTypes = actualTypes;
|
|
37
|
+
this.availableSignatures = availableSignatures;
|
|
38
|
+
this.name = "NoMatchingSignatureError";
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var TypeConversionError = class extends Error {
|
|
42
|
+
constructor(fromType, toType, originalError) {
|
|
43
|
+
super(
|
|
44
|
+
`Cannot convert from ${fromType} to ${toType}` + (originalError ? `: ${originalError.message}` : "")
|
|
45
|
+
);
|
|
46
|
+
this.fromType = fromType;
|
|
47
|
+
this.toType = toType;
|
|
48
|
+
this.originalError = originalError;
|
|
49
|
+
this.name = "TypeConversionError";
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
export {
|
|
53
|
+
NoMatchingSignatureError,
|
|
54
|
+
TypeConversionError,
|
|
55
|
+
buildSignature,
|
|
56
|
+
create,
|
|
57
|
+
isArray,
|
|
58
|
+
isArrayBuffer,
|
|
59
|
+
isBigInt,
|
|
60
|
+
isBoolean,
|
|
61
|
+
isFiniteNumber,
|
|
62
|
+
isFloat32Array,
|
|
63
|
+
isFloat64Array,
|
|
64
|
+
isFunction,
|
|
65
|
+
isInt32Array,
|
|
66
|
+
isInteger,
|
|
67
|
+
isNaN,
|
|
68
|
+
isNonNegativeInteger,
|
|
69
|
+
isNull,
|
|
70
|
+
isNullOrUndefined,
|
|
71
|
+
isNumber,
|
|
72
|
+
isObject,
|
|
73
|
+
isPositiveInteger,
|
|
74
|
+
isString,
|
|
75
|
+
isTypedArray,
|
|
76
|
+
isUint32Array,
|
|
77
|
+
isUndefined,
|
|
78
|
+
parseSignature,
|
|
79
|
+
default2 as typed
|
|
80
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@danielsimonjr/mathts-typed-function",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Utility helpers for typed-function integration in MathTS",
|
|
5
|
+
"author": "Daniel Simon Jr.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"module": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
23
|
+
"dev": "tsup src/index.ts --format esm --dts --watch",
|
|
24
|
+
"test": "vitest run",
|
|
25
|
+
"test:watch": "vitest",
|
|
26
|
+
"test:coverage": "vitest run --coverage",
|
|
27
|
+
"typecheck": "tsc --noEmit",
|
|
28
|
+
"lint": "eslint src --ext .ts",
|
|
29
|
+
"lint:fix": "eslint src --ext .ts --fix",
|
|
30
|
+
"clean": "rm -rf dist",
|
|
31
|
+
"build:prod": "tsup src/index.ts --format esm --dts --clean --minify --treeshake"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"typed-function": "github:danielsimonjr/typed-function"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"tsup": "^8.0.0",
|
|
38
|
+
"typescript": "^5.3.0",
|
|
39
|
+
"vitest": "^2.0.0"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "https://github.com/danielsimonjr/mathts",
|
|
47
|
+
"directory": "packages/typed-function"
|
|
48
|
+
},
|
|
49
|
+
"keywords": [
|
|
50
|
+
"math",
|
|
51
|
+
"typescript",
|
|
52
|
+
"typed-function",
|
|
53
|
+
"polymorphism",
|
|
54
|
+
"type-dispatch"
|
|
55
|
+
]
|
|
56
|
+
}
|