Skip to content

Commit

Permalink
switch to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
dankogai committed Jul 27, 2020
1 parent c53ff28 commit 702af5e
Show file tree
Hide file tree
Showing 10 changed files with 583 additions and 110 deletions.
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
TS=combinatorics.ts
JS=combinatorics.js
MJS=combinatorics.mjs
DTS=combinatorics.d.ts

all: $(JS)

$(JS): $(TS)
tsc -d --target es6 $(TS)

test: $(JS)
mocha --require esm

clean:
-rm $(DTS) $(MJS) $(JS)
158 changes: 158 additions & 0 deletions combinatorics.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/**
* combinatorics.js
*
* Licensed under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
*
* @typedef {(number|bigint)} aint
*
* @author: Dan Kogai <[email protected]>
* References:
* @link: http://www.ruby-doc.org/core-2.0/Array.html#method-i-combination
* @link: http://www.ruby-doc.org/core-2.0/Array.html#method-i-permutation
* @link: http://en.wikipedia.org/wiki/Factorial_number_system
*/
export declare const version = "1.1.1";
/**
* BigInt Workaround
*
* https://github.com/streamich/memfs/issues/275
*/
declare type anyint = number | bigint;
/**
* calculates `P(n, k)`.
*
* @link https://en.wikipedia.org/wiki/Permutation
*/
export declare function permutation(n: anyint, k: anyint): number | bigint;
/**
* calculates `C(n, k)`.
*
* @link https://en.wikipedia.org/wiki/Combination
*/
export declare function combination(n: anyint, k: anyint): number | bigint;
/**
* calculates `n!` === `P(n, n)`.
*
* @link https://en.wikipedia.org/wiki/Factorial
*/
export declare function factorial(n: anyint): number | bigint;
/**
* returns the factoradic representation of `n`, least significant order.
*
* @link https://en.wikipedia.org/wiki/Factorial_number_system
* @param {number} l the number of digits
*/
export declare function factoradic(n: anyint, l?: number): number[];
/**
* Base Class of `js-combinatorics`
*/
declare class _CBase {
/**
* does `new`
* @param args
*/
static make(...args: any[]): any;
/**
* Same as `make` but takes a single array `arg`
*
* cf. https://stackoverflow.com/questions/1606797/use-of-apply-with-new-operator-is-this-possible
*/
static vmake(arg: any): any;
/**
* Common iterator
*/
[Symbol.iterator](): Generator<any[], void, unknown>;
/**
* returns `[...this]`.
*/
toArray(): any[][];
/**
* tells wether you need `BigInt` to access all elements.
*/
get isBig(): boolean;
/**
* tells wether it is safe to work on this instance.
*
* * always `true` unless your platform does not support `BigInt`.
* * if not, `true` iff `.isBig` is `false`.
*/
get isSafe(): boolean;
/**
* check n for nth
*/
_check(n: any): any;
nth(n: anyint): any[];
seed: any[];
size: number;
length: anyint;
}
/**
* Permutation
*/
export declare class Permutation extends _CBase {
/**
*
* @param {Iterable} seed
* @param {Number} size
*/
constructor(seed: any, size?: number);
/**
* @param {anyint} n
*/
nth(n: anyint, nocheck?: boolean): any[];
}
/**
* Combination
*/
export declare class Combination extends _CBase {
/**
*
* @param {Iterable} seed
* @param {Number} size
*/
perm: Permutation;
constructor(seed: Iterable<any>, size?: number);
/**
* @param {anyint} n
*/
nth(n: anyint): any[];
}
/**
* Base N
*/
export declare class BaseN extends _CBase {
base: number;
constructor(seed: Iterable<any>, size?: number);
/**
* @param {anyint} bn
*/
nth(n: anyint): any[];
}
/**
* Power Set
*/
export declare class PowerSet extends _CBase {
/**
* @param {Iterable} seed
*/
constructor(seed: Iterable<any>);
/**
* @param {anyint} n
*/
nth(n: anyint): any[];
}
/**
* Cartesian Product
*/
export declare class CartesianProduct extends _CBase {
/**
* @param {Iterable[]} args
*/
constructor(...args: Iterable<any>[]);
/**
*
*/
nth(n: anyint): any[];
}
export {};
Loading

0 comments on commit 702af5e

Please sign in to comment.