Skip to content

Commit 7cf24e7

Browse files
committed
Add namespace Typescript definition
1 parent f2fbe8f commit 7cf24e7

File tree

3 files changed

+232
-0
lines changed

3 files changed

+232
-0
lines changed
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2021 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
// TypeScript Version: 2.0
20+
21+
/* tslint:disable:max-line-length */
22+
/* tslint:disable:max-file-line-count */
23+
24+
import complx = require( '@stdlib/complex/cmplx' );
25+
import conj = require( '@stdlib/complex/conj' );
26+
import Complex64 = require( '@stdlib/complex/float32' );
27+
import Complex128 = require( '@stdlib/complex/float64' );
28+
import imag = require( '@stdlib/complex/imag' );
29+
import real = require( '@stdlib/complex/real' );
30+
import reim = require( '@stdlib/complex/reim' );
31+
import reviveComplex = require( '@stdlib/complex/reviver' );
32+
import reviveComplex64 = require( '@stdlib/complex/reviver-float32' );
33+
import reviveComplex128 = require( '@stdlib/complex/reviver-float64' );
34+
35+
/**
36+
* Interface describing the `complex` namespace.
37+
*/
38+
interface COMPLEX {
39+
/**
40+
* Creates a complex number.
41+
*
42+
* @param real - real component
43+
* @param imag - imaginary component
44+
* @param dtype - data type (default: 'float64')
45+
* @returns complex number
46+
*
47+
* @example
48+
* var z = complex( 5.0, 3.0, 'float64' );
49+
* // returns <Complex128>
50+
*/
51+
complex: typeof complx;
52+
53+
/**
54+
* Returns the complex conjugate of a complex number.
55+
*
56+
* @param z - complex number
57+
* @returns complex conjugate
58+
*
59+
* @example
60+
* var Complex128 = require( `@stdlib/complex/float64` );
61+
*
62+
* var z = new Complex128( 5.0, 3.0 );
63+
*
64+
* var v = conj( z );
65+
* // returns <Complex128>
66+
*/
67+
conj: typeof conj;
68+
69+
/**
70+
* 64-bit complex number.
71+
*/
72+
Complex64: typeof Complex64;
73+
74+
/**
75+
* 128-bit complex number.
76+
*/
77+
Complex128: typeof Complex128;
78+
79+
/**
80+
* Returns the imaginary component of a complex number.
81+
*
82+
* @param z - complex number
83+
* @returns imaginary component
84+
*
85+
* @example
86+
* var Complex128 = require( `@stdlib/complex/float64` );
87+
*
88+
* var z = new Complex128( 5.0, 3.0 );
89+
*
90+
* var im = imag( z );
91+
* // returns 3.0
92+
*/
93+
imag: typeof imag;
94+
95+
/**
96+
* Returns the real component of a complex number.
97+
*
98+
* @param z - complex number
99+
* @returns real component
100+
*
101+
* @example
102+
* var Complex128 = require( `@stdlib/complex/float64` );
103+
*
104+
* var z = new Complex128( 5.0, 3.0 );
105+
*
106+
* var re = real( z );
107+
* // returns 5.0
108+
*/
109+
real: typeof real;
110+
111+
/**
112+
* Returns the real and imaginary components of a complex number.
113+
*
114+
* @param z - complex number
115+
* @returns real and imaginary components
116+
*
117+
* @example
118+
* var Complex128 = require( `@stdlib/complex/float64` );
119+
*
120+
* var z = new Complex128( 5.0, 3.0 );
121+
*
122+
* var out = reim( z );
123+
* // returns <Float64Array>[ 5.0, 3.0 ]
124+
*
125+
* @example
126+
* var Complex64 = require( `@stdlib/complex/float32` );
127+
*
128+
* var z = new Complex64( 5.0, 3.0 );
129+
*
130+
* var out = reim( z );
131+
* // returns <Float32Array>[ 5.0, 3.0 ]
132+
*/
133+
reim: typeof reim;
134+
135+
/**
136+
* Revives a JSON-serialized complex number.
137+
*
138+
* @param key - key
139+
* @param value - value
140+
* @returns value or complex number
141+
*
142+
* @example
143+
* var parseJSON = require( `@stdlib/utils/parse-json` );
144+
*
145+
* var str = '{"type":"Complex128","re":5,"im":3}';
146+
*
147+
* var z = parseJSON( str, reviver );
148+
* // returns <Complex128>
149+
*/
150+
reviveComplex: typeof reviveComplex;
151+
152+
/**
153+
* Revives a JSON-serialized 64-bit complex number.
154+
*
155+
* @param key - key
156+
* @param value - value
157+
* @returns value or 64-bit complex number
158+
*
159+
* @example
160+
* var parseJSON = require( `@stdlib/utils/parse-json` );
161+
*
162+
* var str = '{"type":"Complex64","re":5,"im":3}';
163+
*
164+
* var z = parseJSON( str, reviver );
165+
* // returns <Complex64>
166+
*/
167+
reviveComplex64: typeof reviveComplex64;
168+
169+
/**
170+
* Revives a JSON-serialized 128-bit complex number.
171+
*
172+
* @param key - key
173+
* @param value - value
174+
* @returns value or 128-bit complex number
175+
*
176+
* @example
177+
* var parseJSON = require( `@stdlib/utils/parse-json` );
178+
*
179+
* var str = '{"type":"Complex128","re":5,"im":3}';
180+
*
181+
* var z = parseJSON( str, reviver );
182+
* // returns <Complex128>
183+
*/
184+
reviveComplex128: typeof reviveComplex128;
185+
}
186+
187+
/**
188+
* Complex numbers.
189+
*/
190+
declare var complex: COMPLEX;
191+
192+
193+
// EXPORTS //
194+
195+
export = complex;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2021 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/* tslint:disable:no-unused-expression */
20+
21+
import complex = require( './index' );
22+
23+
24+
// TESTS //
25+
26+
// The exported object has the expected function interfaces...
27+
{
28+
complex.complex; // $ExpectType (real: number, imag: number, dtype?: "float64" | "float32" | undefined) => Complex
29+
complex.conj; // $ExpectType (z: Complex) => Complex
30+
complex.imag; // $ExpectType (z: ComplexLike) => number
31+
complex.real; // $ExpectType (z: ComplexLike) => number
32+
complex.reim; // $ExpectType (z: ComplexLike) => Float64Array | Float32Array
33+
complex.reviveComplex; // $ExpectType (key: string, value: any) => any
34+
complex.reviveComplex64; // $ExpectType (key: string, value: any) => any
35+
complex.reviveComplex128; // $ExpectType (key: string, value: any) => any
36+
}

lib/node_modules/@stdlib/complex/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"lib": "./lib",
2020
"test": "./test"
2121
},
22+
"types": "./docs/types",
2223
"scripts": {},
2324
"homepage": "https://github.com/stdlib-js/stdlib",
2425
"repository": {

0 commit comments

Comments
 (0)