[@types/wnumb] Update types to wNumb version 1.2.0 (#41909)

* [@types/wnumb] Update types to wNumb version 1.2.0

This change corrects the types and exports them.

* Update tests

* Update index.d.ts

* Update wnumb-tests.ts

* Update wnumb-tests.ts

* Update index.d.ts

* Update nouislider-tests.ts

* Update nouislider-tests.ts

* Update nouislider-tests.ts

* Update index.d.ts

* Update index.d.ts

* Update wnumb-tests.ts
This commit is contained in:
Jamie Neubert Pedersen 2020-02-05 17:46:03 +01:00 committed by GitHub
parent 141c76f567
commit 8a75816499
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 82 additions and 73 deletions

View File

@ -1,4 +1,5 @@
import noUiSlider = require("nouislider");
import wNumb from 'wnumb';
var testHtmlElement = document.getElementById('test');

View File

@ -1,3 +1,5 @@
import wNumb from 'wnumb';
//basic
var basicSlider = $("<div/>").noUiSlider({
start: 80,

View File

@ -1,4 +1,5 @@
var testHtmlElement = document.getElementById('test');
import wNumb from 'wnumb';
/**
* Basic

139
types/wnumb/index.d.ts vendored
View File

@ -1,78 +1,79 @@
// Type definitions for wnumb 1.0
// Type definitions for wnumb 1.2
// Project: https://github.com/leongersen/wnumb
// Definitions by: Corey Jepperson <https://github.com/acoreyj>
// Jamie Neubert Pedersen <https://github.com/eikooc>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export default wNumb;
export as namespace wNumb;
/**
* Create a wNumb
*/
declare function wNumb(options?: wNumb.Options): wNumb.Instance;
declare function wNumb(options?: Options): Instance;
declare namespace wNumb {
interface Options {
/** The number of decimals to include in the result. Limited to 7. */
decimals?: number;
/**
* The decimal separator.
* Defaults to '.' if thousand isn't already set to '.'.
*/
mark?: string;
/**
* Separator for large numbers. For example: ' ' would result in a formatted number of 1 000 000.
*/
thousand?: string;
/**
* A string to prepend to the number. Use cases include prefixing with money symbols such as '$' or '€'.
*/
prefix?: string;
/**
* A number to append to a number. For example: ',-'.
*/
postfix?: string;
/**
* The prefix for negative values. Defaults to '-' if negativeBefore isn't set.
*/
negative?: string;
/**
* The prefix for a negative number. Inserted before prefix.
*/
negativeBefore?: string;
/**
* This is a powerful option to manually modify the slider output.
*
* For example, to show a number in another currency:
* function( value ){
* return value * 1.32;
* }
*/
encoder?: (value: number) => number;
/**
* Reverse the operations set in encoder.
* Use this option to undo modifications made while encoding the value.
* function( value ){
* return value / 1.32;
* }
*/
decoder?: (value: number) => number;
/**
* Similar to encoder, but applied after all other formatting options are applied.
*/
edit?: (value: number) => number;
/**
* Similar to decoder and the reverse for edit.
* Applied before all other formatting options are applied.
*/
undo?: (value: number) => number;
}
interface Instance {
/**
* format to string
*/
to(val: number): string;
/**
* get number from formatted string
*/
from(val: string): number;
}
export interface Options {
/** The number of decimals to include in the result. Limited to 7. */
decimals?: number;
/**
* The decimal separator.
* Defaults to '.' if thousand isn't already set to '.'.
*/
mark?: string;
/**
* Separator for large numbers. For example: ' ' would result in a formatted number of 1 000 000.
*/
thousand?: string;
/**
* A string to prepend to the number. Use cases include prefixing with money symbols such as '$' or '€'.
*/
prefix?: string;
/**
* A number to append to a number. For example: ',-'.
*/
suffix?: string;
/**
* The prefix for negative values. Defaults to '-' if negativeBefore isn't set.
*/
negative?: string;
/**
* The prefix for a negative number. Inserted before prefix.
*/
negativeBefore?: string;
/**
* This is a powerful option to manually modify the slider output.
* For example, to show a number in another currency:
* function( value ){
* return value * 1.32;
* }
*/
encoder?: (value: number) => number;
/**
* Reverse the operations set in encoder.
* Use this option to undo modifications made while encoding the value.
* function( value ){
* return value / 1.32;
* }
*/
decoder?: (value: number) => number;
/**
* Similar to encoder, but applied after all other formatting options are applied.
*/
edit?: (value: number) => number;
/**
* Similar to decoder and the reverse for edit.
* Applied before all other formatting options are applied.
*/
undo?: (value: number) => number;
}
export interface Instance {
/**
* format to string
*/
to(val: number): string;
/**
* get number from formatted string
*/
from(val: string): number;
}

View File

@ -1,9 +1,13 @@
const moneyFormat = wNumb({
import wNumb from 'wnumb';
const options: wNumb.Options = {
mark: '.',
thousand: ',',
prefix: '$ ',
postfix: ' p.p.'
});
suffix: ' p.p.'
};
const moneyFormat: wNumb.Instance = wNumb(options);
moneyFormat.to(301980.62);
@ -23,7 +27,7 @@ Format = wNumb({
Format = wNumb({
prefix: '$',
postfix: ',-',
suffix: ',-',
thousand: ','
});