-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
be61e6e
commit a3e01a6
Showing
18 changed files
with
9,044 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module.exports = { | ||
root: true, | ||
|
||
env: { | ||
node: true, | ||
}, | ||
|
||
extends: ['plugin:vue/vue3-essential', '@vue/standard'], | ||
|
||
parserOptions: { | ||
parser: '@babel/eslint-parser', | ||
}, | ||
|
||
overrides: [ | ||
{ | ||
files: [ | ||
'**/__tests__/*.{j,t}s?(x)', | ||
'**/tests/unit/**/*.spec.{j,t}s?(x)', | ||
], | ||
env: { | ||
jest: true, | ||
}, | ||
}, | ||
], | ||
|
||
rules: { | ||
'no-console': 'off', | ||
'no-debugger': 'off', | ||
// custom | ||
semi: [2, 'always'], | ||
'space-before-function-paren': [2, 'always'], | ||
'keyword-spacing': [2, { before: true, after: true }], | ||
'space-before-blocks': [2, 'always'], | ||
'comma-dangle': [2, 'always-multiline'], | ||
'no-multi-str': 'off', | ||
curly: 1, | ||
'no-undef': 'off', | ||
'vue/multi-word-component-names': 'off', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
.DS_Store | ||
node_modules | ||
/dist | ||
|
||
|
||
# local env files | ||
.env.local | ||
.env.*.local | ||
|
||
# Log files | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
|
||
# Editor directories and files | ||
.idea | ||
.vscode | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,123 @@ | ||
# 💸 Money Component 💰 | ||
|
||
Vue.js 2 component for displaying hindu arabic money figures | ||
## Installation | ||
|
||
## Usage | ||
Install the @ossph/money package using npm or yarn: | ||
|
||
```bash | ||
npm install @ossph/money | ||
|
||
``` | ||
or | ||
|
||
```bash | ||
yarn add @ossph/money | ||
|
||
``` | ||
|
||
## Money Component | ||
|
||
### Importing the Component | ||
|
||
To use the **Money** component, import it as follows: | ||
|
||
```js | ||
import { Money } from '@ossph/money'; | ||
``` | ||
|
||
### Example Usage | ||
|
||
Use the **Money** component in your Vue templates as follows: | ||
|
||
```html | ||
<money :value="100" show-symbol /> // ₱100.00 | ||
<money :value="1000" show-symbol /> // ₱1,000.00 | ||
<money :value="1000" /> // 1,000.00 | ||
<template> | ||
<div> | ||
<Money :input="123456.78" /> | ||
</div> | ||
</template> | ||
|
||
// Using $ as symbol | ||
<script> | ||
import { Money } from '@ossph/money'; | ||
<money :value="1000" symbol="$" show-symbol /> // $1,000.00 | ||
export default { | ||
components: { | ||
Money | ||
} | ||
}; | ||
</script> | ||
|
||
``` | ||
|
||
### Props API | ||
|
||
The `Money` component accepts the following props: | ||
|
||
| Prop Name | Type | Default | Description | | ||
|----------------|---------------------|---------|----------------------------------------------------| | ||
| `input` | Number/String | | The input money value to be formatted. | | ||
| `symbol` | String | '$' | The currency symbol. | | ||
| `symbolStyles` | Object | {} | CSS styles for the currency symbol. | | ||
| `symbolClasses`| Array | [] | CSS classes for the currency symbol. | | ||
| `textStyle` | Object | {} | CSS styles for the text. | | ||
| `showSymbol` | Boolean | | Whether to show the currency symbol. | | ||
| `showFractional` | Boolean | | Whether to show the fractional part of the money value. | | ||
|
||
|
||
|
||
## Money Composable | ||
|
||
### Importing the Composable | ||
|
||
To use the **useMoney** composable, import it as follows: | ||
|
||
```js | ||
import { useMoney } from '@ossph/money'; | ||
``` | ||
|
||
## The component | ||
### Example Usage | ||
|
||
Use the useMoney composable in your Vue composition functions as follows: | ||
|
||
```vue | ||
```js | ||
<template> | ||
<span :style="textStyle"> | ||
<span v-if="showSymbol">{{ symbol }}</span><span>{{ value | money }}</span> | ||
</span> | ||
<div> | ||
<p>Formatted Money Value: {{ formattedMoney }}</p> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { useMoney } from '@ossph/money'; | ||
|
||
export default { | ||
filters: { | ||
money (num) { | ||
const [characteristic, mantissa] = Number.parseFloat(num).toFixed(2).split('.'); | ||
const integer = parseInt(characteristic).toLocaleString(); | ||
const fractional = mantissa; | ||
return [integer, fractional].join('.'); | ||
}, | ||
}, | ||
props: { | ||
value: { | ||
type: Number, | ||
default: 0, | ||
}, | ||
symbol: { | ||
type: String, | ||
default: '₱', | ||
}, | ||
textStyle: { | ||
type: Object, | ||
default: () => ({}), | ||
}, | ||
showSymbol: Boolean, | ||
}, | ||
setup() { | ||
const { moneyValue } = useMoney(123456.78); | ||
|
||
return { | ||
formattedMoney: moneyValue | ||
}; | ||
} | ||
}; | ||
</script> | ||
``` | ||
|
||
Code snippet by [Joff Tiquez](https://twitter.com/jrtiquez) | ||
### Composable API | ||
|
||
The `useMoney` composable takes the following parameters: | ||
|
||
| Prop Name | Type | Default | Description | | ||
|------------|--------------------|--------------------------------------------------|----------------------------------------------------| | ||
| `value` | Number/String | | The input money value to be formatted. | | ||
| `options` | Object | `{ showFractional: true, showSymbol: true, symbol: '$' }` | Formatting options for money value. | | ||
| `showFractional` | Boolean | `true` | Whether to show the fractional part of the money value. | | ||
| `showSymbol` | Boolean | `true` | Whether to show the currency symbol. | | ||
| `symbol` | String | `'$'` | The currency symbol. | | ||
|
||
|
||
It returns an object with the following properties: | ||
|
||
| Property | Type | Description | | ||
|--------------------|--------|----------------------------------------------------| | ||
| `moneyValue` | String | The formatted integer part of the money value. | | ||
| `moneyFractional` | String | The original fractional part. | | ||
| `moneySymbol` | String | The currency symbol. | | ||
| `moneyConcatenated`| String | The concatenated value with the currency symbol. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
presets: [ | ||
'@vue/cli-plugin-babel/preset', | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
preset: '@vue/cli-plugin-unit-jest', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"module": "esnext", | ||
"baseUrl": "./", | ||
"moduleResolution": "node", | ||
"paths": { | ||
"@/*": [ | ||
"src/*" | ||
] | ||
}, | ||
"lib": [ | ||
"esnext", | ||
"dom", | ||
"dom.iterable", | ||
"scripthost" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{ | ||
"name": "@ossph/use-money", | ||
"version": "0.1.0", | ||
"description": "A Vue 3 composition API for formatting money", | ||
"author": "Joff Tiquez", | ||
"main": "dist/use-money.common.js", | ||
"module": "dist/use-money.umd.min.js", | ||
"scripts": { | ||
"serve": "vue-cli-service serve", | ||
"test": "vue-cli-service test:unit", | ||
"build": "npm run build:lib", | ||
"build:lib": "vue-cli-service build --target lib --name use-money src/index.js", | ||
"lint": "vue-cli-service lint --fix" | ||
}, | ||
"dependencies": { | ||
"core-js": "^3.8.3", | ||
"vue": "^3.2.13" | ||
}, | ||
"files": [ | ||
"dist/*.{js,css}" | ||
], | ||
"devDependencies": { | ||
"@babel/core": "^7.12.16", | ||
"@babel/eslint-parser": "^7.12.16", | ||
"@vue/cli-plugin-babel": "~5.0.0", | ||
"@vue/cli-plugin-eslint": "~5.0.0", | ||
"@vue/cli-plugin-unit-jest": "~5.0.0", | ||
"@vue/cli-service": "~5.0.0", | ||
"@vue/eslint-config-standard": "^6.1.0", | ||
"@vue/test-utils": "^2.4.1", | ||
"@vue/vue3-jest": "^27.0.0-alpha.1", | ||
"babel-jest": "^27.0.6", | ||
"eslint": "^7.32.0", | ||
"eslint-plugin-import": "^2.25.3", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-promise": "^5.1.0", | ||
"eslint-plugin-vue": "^8.0.3", | ||
"jest": "^27.0.5" | ||
}, | ||
"eslintConfig": { | ||
"root": true, | ||
"env": { | ||
"node": true | ||
}, | ||
"extends": [ | ||
"plugin:vue/vue3-essential", | ||
"eslint:recommended" | ||
], | ||
"parserOptions": { | ||
"parser": "@babel/eslint-parser" | ||
}, | ||
"rules": {} | ||
}, | ||
"browserslist": [ | ||
"> 1%", | ||
"last 2 versions", | ||
"not dead", | ||
"not ie 11" | ||
] | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<html lang=""> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width,initial-scale=1.0"> | ||
<link rel="icon" href="<%= BASE_URL %>favicon.ico"> | ||
<title><%= htmlWebpackPlugin.options.title %></title> | ||
</head> | ||
<body> | ||
<noscript> | ||
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong> | ||
</noscript> | ||
<div id="app"></div> | ||
<!-- built files will be auto injected --> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<template> | ||
<div style="display: flex; flex-direction: column;"> | ||
<money input="1000" /> | ||
<money show-symbol input="1000" /> | ||
<money show-symbol show-fractional input="1000" /> | ||
<money show-symbol show-fractional symbol="$" input="123123123123" /> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import Money from './components/Money'; | ||
export default { | ||
components: { | ||
Money, | ||
}, | ||
setup () { | ||
return { | ||
// ... | ||
}; | ||
}, | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { mount } from '@vue/test-utils'; | ||
import Money from '../components/Money'; | ||
|
||
describe('Money.vue', () => { | ||
it('renders money value and symbol correctly', () => { | ||
const propsData = { | ||
input: 1000, | ||
symbol: '$', | ||
showSymbol: true, | ||
}; | ||
|
||
const wrapper = mount(Money, { | ||
propsData, | ||
}); | ||
|
||
const moneySymbol = wrapper.find('[data-testid="money-symbol"]'); | ||
const moneyValue = wrapper.find('[data-testid="money-value"]'); | ||
|
||
expect(moneySymbol.exists()).toBe(true); | ||
expect(moneySymbol.text()).toBe('$'); | ||
|
||
expect(moneyValue.exists()).toBe(true); | ||
expect(moneyValue.text()).toBe('1,000'); | ||
}); | ||
|
||
// Add more test cases as needed | ||
}); |
Oops, something went wrong.