mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-07 00:07:07 +00:00
Types 2.0 - Fix JS-quantities (#12739)
* Enable strict null checking per readme FAQ. * Add tslint.json. * Improve test file with project spec. * Fix js-quantities d.ts, with adjustment of test. * Add trailing newline to tslint. * Simplify functional interface per linter. * js-quantities: add readme examples to tests * js-quantities: fix & clean declaration
This commit is contained in:
Vendored
+63
-69
@@ -1,79 +1,73 @@
|
||||
// Type definitions for JS-quantities
|
||||
// Type definitions for JS-quantities 1.6
|
||||
// Project: http://gentooboontoo.github.io/js-quantities/
|
||||
// Definitions by: William Comartin <https://github.com/wcomartin>
|
||||
// Definitions by: William Rummler <https://github.com/wrummler>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare var Qty: QtyModule.QtyStatic;
|
||||
|
||||
declare namespace QtyModule {
|
||||
interface QtyStatic {
|
||||
(value: string): Qty;
|
||||
(value: number): Qty;
|
||||
(value: number, unit: string): Qty;
|
||||
(value: Qty): Qty;
|
||||
}
|
||||
|
||||
interface Qty {
|
||||
version: string;
|
||||
|
||||
scalar: number;
|
||||
baseScalar: number;
|
||||
|
||||
parse(value: string): Qty;
|
||||
|
||||
swiftConverter(srcUnits:string, dstUnits:string): (value:number) => number;
|
||||
|
||||
getkinds(): string[];
|
||||
|
||||
getUnits(kind:string): string[];
|
||||
|
||||
getAliases(unitName:string): string[];
|
||||
|
||||
formatter(scalar:number, units:string):string;
|
||||
|
||||
toFloat(): number;
|
||||
|
||||
isUnitless(): boolean;
|
||||
|
||||
isCompatible(other:string|Qty): boolean;
|
||||
|
||||
isInverse(other:string|Qty): boolean
|
||||
|
||||
kind(): string;
|
||||
|
||||
isBase(): boolean;
|
||||
|
||||
toBase(): Qty;
|
||||
declare const Qty: Qty.Type;
|
||||
|
||||
declare interface Qty {
|
||||
readonly numerator: string[];
|
||||
readonly denominator: string[];
|
||||
readonly scalar: number;
|
||||
readonly baseScalar: number;
|
||||
readonly initValue: string;
|
||||
units(): string;
|
||||
|
||||
eq(other:Qty): boolean;
|
||||
lt(other:Qty): boolean;
|
||||
lte(other:Qty): boolean;
|
||||
gt(other:Qty): boolean;
|
||||
gte(other:Qty): boolean;
|
||||
|
||||
toPrec(precQuantity: Qty|string|number): Qty;
|
||||
|
||||
toString(targetUnitsOrMaxDecimalsOrPrec?:number|string|Qty, maxDecimals?: number): string;
|
||||
|
||||
format(targetUnits?:string, formatter?:(scalar:number, units:string) => string): string;
|
||||
|
||||
compareTo(other:Qty|string): number;
|
||||
|
||||
same(other: Qty): boolean;
|
||||
|
||||
isCompatible(value: Qty.UnitSource): boolean;
|
||||
kind(): string;
|
||||
isUnitless(): boolean;
|
||||
isBase(): boolean;
|
||||
toBase(): Qty;
|
||||
toFloat(): number;
|
||||
to(value: Qty.UnitSource): Qty;
|
||||
inverse(): Qty;
|
||||
eq(value: Qty.UnitSource): boolean;
|
||||
same(value: Qty.UnitSource): boolean;
|
||||
lt(value: Qty.UnitSource): boolean;
|
||||
lte(value: Qty.UnitSource): boolean;
|
||||
gt(value: Qty.UnitSource): boolean;
|
||||
gte(value: Qty.UnitSource): boolean;
|
||||
compareTo(value: Qty): Qty.ComparisonResult;
|
||||
add(value: Qty.Source): Qty;
|
||||
sub(value: Qty.Source): Qty;
|
||||
mul(value: Qty.Source): Qty;
|
||||
div(value: Qty.Source): Qty;
|
||||
toPrec(value: Qty.Source): Qty;
|
||||
toString(valueOrPrecision?: Qty.Source): string;
|
||||
toString(value: string, precision: number): string;
|
||||
format(formatter?: Qty.Formatter): string;
|
||||
format(value: string, formatter?: Qty.Formatter): string;
|
||||
}
|
||||
|
||||
isDegrees(): boolean;
|
||||
declare namespace Qty {
|
||||
|
||||
isTemperature(): boolean;
|
||||
interface Type {
|
||||
(value: Source): Qty;
|
||||
(value: number, unit: string): Qty;
|
||||
new (value: Source): Qty;
|
||||
new (value: number, unit: string): Qty;
|
||||
parse(value: string): Qty;
|
||||
getKinds(): string[];
|
||||
getUnits(kind?: string): string[];
|
||||
getAliases(unit: string): string[];
|
||||
swiftConverter(sourceUnit: string, targetUnit: string): Converter;
|
||||
formatter: Formatter;
|
||||
readonly Error: any;
|
||||
mulSafe(n1: number, n2: number): number;
|
||||
divSafe(n1: number, n2: number): number;
|
||||
}
|
||||
|
||||
to(other:string|Qty): Qty;
|
||||
interface Converter {
|
||||
(sourceValue: number): number;
|
||||
(sourceValues: number[]): number[];
|
||||
}
|
||||
|
||||
add(other:string|Qty): Qty;
|
||||
sub(other:string|Qty): Qty;
|
||||
mul(other:number|string|Qty): Qty;
|
||||
div(other:number|string|Qty): Qty;
|
||||
}
|
||||
}
|
||||
type Formatter = (scalar: number, unit: string) => string;
|
||||
|
||||
type ComparisonResult = -1 | 0 | 1;
|
||||
|
||||
type Source = UnitSource | number;
|
||||
|
||||
type UnitSource = Qty | string;
|
||||
}
|
||||
|
||||
export default Qty;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -3,7 +3,7 @@
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": false,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
@@ -16,4 +16,4 @@
|
||||
"index.d.ts",
|
||||
"js-quantities-tests.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "../tslint.json"
|
||||
}
|
||||
Reference in New Issue
Block a user