mirror of
https://github.com/chenasraf/DefinitelyTyped.git
synced 2026-05-18 01:49:01 +00:00
🤖 Merge PR #63801 [parse-decimal-number] Add types by @ciaran1344
* [parse-decimal-number] Add types * [parse-decimal-number] Add types using namespaces
This commit is contained in:
56
types/parse-decimal-number/index.d.ts
vendored
Normal file
56
types/parse-decimal-number/index.d.ts
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
// Type definitions for parse-decimal-number 1.0
|
||||
// Project: https://github.com/AndreasPizsa/parse-decimal-number
|
||||
// Definitions by: Ciarán Ingle <https://github.com/ciaran1344>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare namespace parseDecimalNumber {
|
||||
type ArrayOptions = [thousands: string, decimal: string];
|
||||
|
||||
interface HashOptions {
|
||||
/**
|
||||
* Decimal point character.
|
||||
* Default: ".".
|
||||
*/
|
||||
decimal: string;
|
||||
/**
|
||||
* Thousands separator character.
|
||||
* Default: ",".
|
||||
*/
|
||||
thousands: string;
|
||||
}
|
||||
|
||||
type Options = ArrayOptions | HashOptions | string;
|
||||
|
||||
/**
|
||||
* Has the same effect as `parseDecimalNumber.setOptions({ thousands: ",", decimal: "." })`.
|
||||
*/
|
||||
function factoryReset(): void;
|
||||
/**
|
||||
* Set the default thousands and decimal characters that are used when no options are passed to
|
||||
* {@link parseDecimalNumber}.
|
||||
*/
|
||||
function setOptions(hash: HashOptions): void;
|
||||
/**
|
||||
* Returns a function that will take a string as an argument and return a float or `NaN`,
|
||||
* just like {@link parseDecimalNumber}.
|
||||
*/
|
||||
function withOptions(options: Options, enforceGroupSize?: boolean): (string: string) => number;
|
||||
}
|
||||
|
||||
declare function parseDecimalNumber(
|
||||
/**
|
||||
* A string that is supposed to contain a number.
|
||||
*/
|
||||
string: string,
|
||||
/**
|
||||
* A string, array or hash with thousands and decimal separators.
|
||||
*/
|
||||
options?: parseDecimalNumber.Options,
|
||||
/**
|
||||
* A boolean indicating whether to support that individual groups between the thousands
|
||||
* character are exactly 3 digits.
|
||||
*/
|
||||
enforceGroupSize?: boolean,
|
||||
): number;
|
||||
|
||||
export = parseDecimalNumber;
|
||||
16
types/parse-decimal-number/parse-decimal-number-tests.ts
Normal file
16
types/parse-decimal-number/parse-decimal-number-tests.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import parseDecimalNumber = require('parse-decimal-number');
|
||||
|
||||
parseDecimalNumber('12,345,678.90'); // $ExpectType number
|
||||
|
||||
parseDecimalNumber('12.345.678,90', '.,'); // $ExpectType number
|
||||
parseDecimalNumber('12.345.678,90', ['.', ',']); // $ExpectType number
|
||||
parseDecimalNumber('12.345.678,90', { thousands: '.', decimal: ',' }); // $ExpectType number
|
||||
|
||||
parseDecimalNumber('12.345.678,90', '.,', true); // $ExpectType number
|
||||
|
||||
parseDecimalNumber.factoryReset(); // $ExpectType void
|
||||
|
||||
parseDecimalNumber.setOptions({ thousands: '.', decimal: ',' }); // $ExpectType void
|
||||
|
||||
parseDecimalNumber.withOptions({ thousands: '.', decimal: ',' })('12.345.678,90'); // $ExpectType number
|
||||
parseDecimalNumber.withOptions({ thousands: '.', decimal: ',' }, true)('12.345.678,90'); // $ExpectType number
|
||||
23
types/parse-decimal-number/tsconfig.json
Normal file
23
types/parse-decimal-number/tsconfig.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"parse-decimal-number-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/parse-decimal-number/tslint.json
Normal file
1
types/parse-decimal-number/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "@definitelytyped/dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user