Skip to content

Commit

Permalink
Fix JSDoc syntax: empty @examples breaks doc generation (#713)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic committed Nov 15, 2023
1 parent a50ea4c commit 9145983
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
1 change: 0 additions & 1 deletion src/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ export async function authorizeEntry(
* {@link Operation.invokeHostFunction}
*
* @see authorizeEntry
* @example
*/
export function authorizeInvocation(
signer,
Expand Down
43 changes: 26 additions & 17 deletions src/soroban.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
/**

Check warning on line 1 in src/soroban.js

View workflow job for this annotation

GitHub Actions / build (16)

JSDoc syntax error

Check warning on line 1 in src/soroban.js

View workflow job for this annotation

GitHub Actions / build (16)

JSDoc syntax error

Check warning on line 1 in src/soroban.js

View workflow job for this annotation

GitHub Actions / build (18)

JSDoc syntax error

Check warning on line 1 in src/soroban.js

View workflow job for this annotation

GitHub Actions / build (18)

JSDoc syntax error

Check warning on line 1 in src/soroban.js

View workflow job for this annotation

GitHub Actions / build (20)

JSDoc syntax error

Check warning on line 1 in src/soroban.js

View workflow job for this annotation

GitHub Actions / build (20)

JSDoc syntax error
* Soroban helper class
* formatting, parsing, and etc
* @class Soroban
* Soroban helper class to assist with formatting and parsing token amounts.
*/
export class Soroban {
/**
* All arithmetic inside the contract is performed on integers to
* avoid potential precision and consistency issues of floating-point
* Given a whole number smart contract amount of a token and an amount of
* decimal places (if the token has any), it returns a "display" value.
*
* This function takes the smart contract value and its decimals (if the token has any) and returns a display value
* @param {string} amount - the token amount you want to display
* @param {number} decimals - specify how many decimal places a token has
* @returns {string} - display value
* All arithmetic inside the contract is performed on integers to avoid
* potential precision and consistency issues of floating-point.
*
* @param {string} amount the token amount you want to display
* @param {number} decimals specify how many decimal places a token has
*
* @returns {string} the display value
* @throws {TypeError} if the given amount has a decimal point already
* @example
* formatTokenAmount("123000", 4) === "12.3";
*/
static formatTokenAmount(amount, decimals) {
let formatted = amount;

if (amount.includes('.')) {
throw new Error('No decimal is allowed');
throw new TypeError('No decimals are allowed');
}

let formatted = amount;
if (decimals > 0) {
if (decimals > formatted.length) {
formatted = ['0', formatted.toString().padStart(decimals, '0')].join(
Expand All @@ -38,19 +42,24 @@ export class Soroban {
}

/**
* parse token amount to use it on smart contract
* Parse a token amount to use it on smart contract
*
* This function takes the display value and its decimals (if the token has
* any) and returns a string that'll be used within the smart contract.
* @param {string} value - the token amount you want to use it on smart contract
* @param {number} decimals - specify how many decimal places a token has
* @returns {string} - smart contract value
*
* @param {string} value the token amount you want to use it on smart
* contract which you've been displaying in a UI
* @param {number} decimals the number of decimal places expected in the
* display value (different than the "actual" number, because suffix zeroes
* might not be present)
*
* @returns {string} the whole number token amount represented by the display
* value with the decimal places shifted over
*
* @example
* const displayValueAmount = "123.4560"
* const parsedAmountForSmartContract = parseTokenAmount("123.4560", 5);
* parsedAmountForSmartContract === "12345600"
* const parsedAmtForSmartContract = parseTokenAmount(displayValueAmount, 5);
* parsedAmtForSmartContract === "12345600"
*/
static parseTokenAmount(value, decimals) {
const [whole, fraction, ...rest] = value.split('.').slice();
Expand Down

0 comments on commit 9145983

Please sign in to comment.