Skip to content

Commit 2141183

Browse files
author
Antoni Kepinski
committed
Update JSDOC for better DX
1 parent d0855cf commit 2141183

File tree

3 files changed

+41
-9
lines changed

3 files changed

+41
-9
lines changed

src/cashify.ts

+20-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,29 @@ import convert from './convert';
33
import parse from './utils/parser';
44

55
export default class Cashify {
6+
/**
7+
* @constructor
8+
* @param {Object} [options] Conversion options.
9+
*/
610
constructor(public readonly options: Partial<Options>) { }
711

812
/**
9-
* @param amount Amount of money you want to convert.
10-
* @param options Conversion options.
11-
* @return Conversion result.
13+
* Function, which converts currencies based on provided rates.
14+
*
15+
* @param {number | string} amount - Amount of money you want to convert.
16+
* @param {Object} [options] - Conversion options.
17+
* @return {number} Conversion result.
18+
*
19+
* @example
20+
* const rates = {
21+
* GBP: 0.92,
22+
* EUR: 1.00,
23+
* USD: 1.12
24+
* };
25+
*
26+
* const cashify = new Cashify({base: 'EUR', rates});
27+
*
28+
* cashify.convert(10, {from: 'EUR', to: 'GBP'}); //=> 9.2
1229
*/
1330
convert(amount: number | string, options?: Partial<Options>): number {
1431
// If provided `amount` is a string, use parsing

src/convert.ts

+15-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,21 @@ import {Options} from './lib/options';
33
import parse from './utils/parser';
44

55
/**
6-
* @param amount Amount of money you want to convert.
7-
* @param options Conversion options.
8-
* @return Conversion result.
9-
*/
6+
* Function, which converts currencies based on provided rates.
7+
*
8+
* @param {number | string} amount - Amount of money you want to convert.
9+
* @param {Object} options - Conversion options.
10+
* @return {number} Conversion result.
11+
*
12+
* @example
13+
* const rates = {
14+
* GBP: 0.92,
15+
* EUR: 1.00,
16+
* USD: 1.12
17+
* };
18+
*
19+
* convert(10, {from: 'EUR', to: 'GBP', base: 'EUR', rates}); //=> 9.2
20+
*/
1021
export default function convert(amount: number | string, {from, to, base, rates}: Options): number {
1122
// If provided `amount` is a string, use parsing
1223
if (typeof amount === 'string') {

src/utils/parser.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ interface Options {
66

77
/**
88
* Expression parser
9-
* @param expression Expression you want to parse, ex. `10 usd to pln` or `€1.23 eur`
10-
* @return Object with parsing results
9+
*
10+
* @param {string} expression - Expression you want to parse, ex. `10 usd to pln` or `€1.23 eur`
11+
* @return {Object} Object with parsing results
12+
*
13+
* @example
14+
* parse('10 EUR to GBP'); //=> {amount: 10, from: 'EUR', to: 'GBP'}
1115
*/
1216
export default function parse(expression: string): Options {
1317
const amount = Number.parseFloat(expression.replace(/[^\d-.]/g, '')) || undefined;

0 commit comments

Comments
 (0)