Skip to content

Commit

Permalink
feat: API contract for formatNumberByParts updated (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarun-khanna authored Jan 10, 2024
1 parent 55218a6 commit 61774b3
Show file tree
Hide file tree
Showing 7 changed files with 383 additions and 84 deletions.
5 changes: 5 additions & 0 deletions .changeset/six-squids-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@razorpay/i18nify-js": minor
---

feat: API contract for formatNumberByParts updated
200 changes: 170 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,64 +230,204 @@ console.log(
locale: "en-US",
})
); /* {
currencySymbol: '$',
integerValue: '12,345',
decimalValue: '67',
separator: '.',
symbolAtFirst: true,
} */
"currency": "$",
"integer": "12,345",
"decimal": ".",
"fraction": "67",
"isPrefixSymbol": true,
"rawParts": [
{
"type": "currency",
"value": "$"
},
{
"type": "integer",
"value": "12"
},
{
"type": "group",
"value": ","
},
{
"type": "integer",
"value": "345"
},
{
"type": "decimal",
"value": "."
},
{
"type": "fraction",
"value": "67"
}
]
} */
console.log(
formatNumberByParts(12345.67, {
currency: "XYZ",
locale: "en-US",
})
); /* {
currencySymbol: 'XYZ',
decimalValue: '67',
integerValue: '12,345',
separator: '.',
symbolAtFirst: true,
} */
"currency": "XYZ",
"integer": "12,345",
"decimal": ".",
"fraction": "67",
"isPrefixSymbol": true,
"rawParts": [
{
"type": "currency",
"value": "XYZ"
},
{
"type": "literal",
"value": " "
},
{
"type": "integer",
"value": "12"
},
{
"type": "group",
"value": ","
},
{
"type": "integer",
"value": "345"
},
{
"type": "decimal",
"value": "."
},
{
"type": "fraction",
"value": "67"
}
]
} */
console.log(
formatNumberByParts(12345.67, {
currency: "EUR",
locale: "fr-FR",
})
); /* {
currencySymbol: '€',
decimalValue: '67',
integerValue: '12 345',
separator: ',',
symbolAtFirst: false,
} */
"integer": "12 345",
"decimal": ",",
"fraction": "67",
"currency": "€",
"isPrefixSymbol": false,
"rawParts": [
{
"type": "integer",
"value": "12"
},
{
"type": "group",
"value": " "
},
{
"type": "integer",
"value": "345"
},
{
"type": "decimal",
"value": ","
},
{
"type": "fraction",
"value": "67"
},
{
"type": "literal",
"value": " "
},
{
"type": "currency",
"value": "€"
}
]
} */
console.log(
formatNumberByParts(12345.67, {
currency: "JPY",
locale: "ja-JP",
})
); /* {
currencySymbol: '¥',
decimalValue: '',
integerValue: '12,346',
separator: '',
symbolAtFirst: true,
} */
"currency": "¥",
"integer": "12,346",
"isPrefixSymbol": true,
"rawParts": [
{
"type": "currency",
"value": "¥"
},
{
"type": "integer",
"value": "12"
},
{
"type": "group",
"value": ","
},
{
"type": "integer",
"value": "346"
}
]
} */
console.log(
formatNumberByParts(12345.67, {
currency: "OMR",
locale: "ar-OM",
})
); /* {
currencySymbol: 'ر.ع.',
decimalValue: '٦٧٠',
integerValue: '١٢٬٣٤٥',
separator: '٫',
symbolAtFirst: false,
} */
"integer": "١٢٬٣٤٥",
"decimal": "٫",
"fraction": "٦٧٠",
"currency": "ر.ع.",
"isPrefixSymbol": false,
"rawParts": [
{
"type": "literal",
"value": " "
},
{
"type": "integer",
"value": "١٢"
},
{
"type": "group",
"value": "٬"
},
{
"type": "integer",
"value": "٣٤٥"
},
{
"type": "decimal",
"value": "٫"
},
{
"type": "fraction",
"value": "٦٧٠"
},
{
"type": "literal",
"value": " "
},
{
"type": "currency",
"value": "ر.ع."
},
{
"type": "literal",
"value": " "
}
]
} */
```

### Module 02: Phone Number
Expand Down
2 changes: 1 addition & 1 deletion src/modules/currency/__tests__/formatNumberByParts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { assertScriptText, injectScript } from '../../../blackbox/utils';

function generateByPartsString(options: string) {
const methodCallStr = `(await formatNumberByParts(${options}))`;
return `${methodCallStr}.currencySymbol + ${methodCallStr}.integerValue + ${methodCallStr}.separator + ${methodCallStr}.decimalValue`;
return `${methodCallStr}.currency + ${methodCallStr}.integer + ${methodCallStr}.decimal + ${methodCallStr}.fraction`;
}

function generateOptionsString(
Expand Down
Loading

0 comments on commit 61774b3

Please sign in to comment.