Skip to content

Commit

Permalink
optimized distributions
Browse files Browse the repository at this point in the history
fixed some type declarations
  • Loading branch information
muratgozel committed Apr 17, 2023
1 parent 4c047fa commit 7457edd
Show file tree
Hide file tree
Showing 16 changed files with 560 additions and 584 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ There are exports for **es6**, **cjs** and **umd** environments:
// cjs
const {monval} = require('monval')

// or es
// es
import {monval} from 'monval'
```
and injection with script tag + `window.monval` global:
```html
<script src="https://cdn.jsdelivr.net/npm/monval@2/dist/browser/iife/index.js" type="text/javascript"></script>

// script tag, window.monval
<script src="https://cdn.jsdelivr.net/npm/monval@2/dist/monval.iife.js" type="text/javascript"></script>
```

## Usage
Expand Down
1 change: 0 additions & 1 deletion dist/browser/cjs/index.js.map

This file was deleted.

1 change: 0 additions & 1 deletion dist/browser/es/index.js.map

This file was deleted.

3 changes: 0 additions & 3 deletions dist/browser/es/package.json

This file was deleted.

1 change: 0 additions & 1 deletion dist/browser/iife/index.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/browser/iife/index.js.map

This file was deleted.

1 change: 0 additions & 1 deletion dist/browser/cjs/index.js → dist/monval.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,3 @@ exports.Account = Account;
exports.Monval = Monval;
exports.currencyCodes = currencyCodes;
exports.monval = monval;
//# sourceMappingURL=index.js.map
1 change: 0 additions & 1 deletion dist/browser/es/index.js → dist/monval.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,4 +309,3 @@ var Account = /*#__PURE__*/function () {
var monval = new Monval();

export { Account, Monval, currencyCodes, monval };
//# sourceMappingURL=index.js.map
2 changes: 2 additions & 0 deletions dist/monval.iife.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/monval.iife.js.map

Large diffs are not rendered by default.

1,015 changes: 492 additions & 523 deletions package-lock.json

Large diffs are not rendered by default.

23 changes: 8 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
{
"name": "monval",
"version": "v2.4.4",
"version": "v2.4.5",
"description": "Precise and simple money utility with exchange rates support.",
"imports": {
"#src/*": "./build/*"
},
"exports": {
".": {
"import": "./dist/browser/es/index.js",
"require": "./dist/browser/cjs/index.js"
},
"./browser": {
"import": "./dist/browser/es/index.js",
"require": "./dist/browser/cjs/index.js"
}
"import": "./dist/monval.es.js",
"require": "./dist/monval.cjs.js",
"default": "./dist/monval.cjs.js"
},
"main": "./dist/browser/cjs/index.js",
"module": "./dist/browser/es/index.js",
"types": "./types/index.d.ts",
"main": "./dist/monval.cjs.js",
"module": "./dist/monval.es.js",
"types": "types",
"type": "module",
"scripts": {
"precompile": "rm -rf build/*",
"compile": "tsc -p tsconfig.json",
"prebuild": "rm -rf dist/*",
"build": "rollup --config rollup.config.js",
"test": "NODE_OPTIONS=--experimental-vm-modules jest"
},
Expand Down
24 changes: 6 additions & 18 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import commonjs from '@rollup/plugin-commonjs'
import babel from '@rollup/plugin-babel'
import terser from '@rollup/plugin-terser'
import json from '@rollup/plugin-json'
import alias from '@rollup/plugin-alias'

const babelPlugins=[]

Expand All @@ -23,22 +22,16 @@ export default [
output: [
{
format: 'cjs',
file: 'dist/browser/cjs/index.js',
sourcemap: true
file: 'dist/monval.cjs.js',
sourcemap: false
},
{
format: 'es',
file: 'dist/browser/es/index.js',
sourcemap: true
file: 'dist/monval.es.js',
sourcemap: false
}
],
plugins: [
alias({
entries: [{
find: /^#src\/(.*)/,
replacement: 'build/$1.js'
}]
}),
nodeResolve({preferBuiltins: false}),
commonjs({sourceMap: true}),
json(),
Expand All @@ -62,19 +55,14 @@ export default [
{
format: 'iife',
name: 'monval',
file: 'dist/browser/iife/index.js',
file: 'dist/monval.iife.js',
sourcemap: true,
globals: {
monval: 'monval'
}
}
],
plugins: [
alias({
entries: [{
find: /^#src\/(.*)/,
replacement: 'build/$1.js'
}]
}),
nodeResolve({preferBuiltins: false}),
commonjs({sourceMap: true}),
json(),
Expand Down
14 changes: 7 additions & 7 deletions src/monval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class Monval {
reOnlyNumbers = /^[0-9]+((.|,)[0-9]+)?((.|,)[0-9]+)?/
reRate = /%[0-9]+((.|,)[0-9]+)?/

isValidInput(input: string | number | Money) {
isValidInput(input: string | number | Money): boolean {
if (this.isMoney(input)) return true

if (typeof input === 'string' && this.reNumberWithCurrency.test(input)) {
Expand All @@ -29,7 +29,7 @@ export class Monval {
return false
}

create(input: string | number | Money, currency?: CurrencyCode) {
create(input: string | number | Money, currency?: CurrencyCode): Account {
const cur = currency || this.defaultCurrency

if (this.isMoney(input)) {
Expand Down Expand Up @@ -58,7 +58,7 @@ export class Monval {
throw new Error('Bad input. Valid kinds of inputs are create("EUR 1.23"), create("1.23", "EUR"), create("1.23") or create({number: 1.23, currency: \'EUR\'}).')
}

exchange(money: Money, target: CurrencyCode) {
exchange(money: Money, target: CurrencyCode): Money {
if (!Object.hasOwn(this.exchangeRates, this.exchangeRatesBaseCurrency)) {
throw new Error('Exchange rates not found.')
}
Expand All @@ -84,7 +84,7 @@ export class Monval {
return currency
}

round(n: number, d: number, algorithm = 'GAUSSIAN') {
round(n: number, d: number, algorithm = 'GAUSSIAN'): number {
switch (algorithm) {
case 'GAUSSIAN': {
const x = n * Math.pow(10, d)
Expand Down Expand Up @@ -243,15 +243,15 @@ export class Account {
return str
}

toFloat() {
toFloat(): number {
return this.money.number
}

toObject() {
toObject(): Money {
return this.money
}

pretty(decilen?: number) {
pretty(decilen?: number): string {
const _decilen = decilen || this.monval.decilen
return this.monval.getCurrencySymbol(this.money.currency) + ' ' + this.toFixed(_decilen)
}
Expand Down
5 changes: 1 addition & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
"typeRoots": [
"node_modules/@types",
"types"
],
"paths": {
"#src/*": ["src/*"]
}
]
},
"include": [
"src/**/*",
Expand Down
42 changes: 39 additions & 3 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
declare module 'monval' {
export type CurrencyCode = import('../src/currencies').CurrencyCode
export type {CurrencyCode} from '../src/currencies'

export const currencyCodes: CurrencyCode[]

Expand All @@ -12,8 +12,44 @@ declare module 'monval' {
number: number
}

export type Account = import('../src/monval').Account
export type Monval = import('../src/monval').Monval
export interface Account {
monval: Monval
money: Money
new(monval: Monval, money: Money): void
add(numberOrRate: number | string, currency?: CurrencyCode): this
addMoney(money: Money): this
addRate(rate: number): this
subtract(numberOrRate: number | string, currency?: CurrencyCode): this
subtractMoney(money: Money): this
subtractRate(rate: number): this
exchange(target: CurrencyCode): this
toFixed(decilen?: number): string
toFloat(): number
toObject(): Money
pretty(decilen?: number): string
}

export interface Monval {
reRate: RegExp
reOnlyNumbers: RegExp
reNumberWithCurrency: RegExp
decilen: number
currencySymbolUnicodeMap: {[index: string]: string}
exchangeRatesBaseCurrency: CurrencyCode
exchangeRates: ExchangeRatesObject
defaultCurrency: CurrencyCode
currencyCodes: CurrencyCode[]
isValidInput(input: string | number | Money): boolean
create(input: string | number | Money, currency?: CurrencyCode): Account
exchange(money: Money, target: CurrencyCode): Money
getCurrencySymbol(currency: CurrencyCode): string
round(n: number, d: number, algorithm = 'GAUSSIAN'): number
isRate(v: unknown): v is string
isNumber(v: unknown): v is number
isCurrency(v: unknown): v is CurrencyCode
isObject(v: unknown): v is object
isMoney(v: unknown): v is Money
}

export const monval: Monval
}

0 comments on commit 7457edd

Please sign in to comment.