├── src ├── main.js ├── filter │ └── persianDigit.js └── app.vue ├── README.md ├── package.json └── npm-debug.log /src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import persianDigit from './filter/persianDigit' 3 | 4 | Vue.config.productionTip = false 5 | 6 | let VPlugin = { 7 | install: function () { 8 | Vue.filter('persianDigit', persianDigit) 9 | } 10 | } 11 | Vue.use(VPlugin) 12 | 13 | export default VPlugin 14 | -------------------------------------------------------------------------------- /src/filter/persianDigit.js: -------------------------------------------------------------------------------- 1 | export default function persianDigit (value) { 2 | const persian = { 3 | 0: '۰', 4 | 1: '۱', 5 | 2: '۲', 6 | 3: '۳', 7 | 4: '۴', 8 | 5: '۵', 9 | 6: '۶', 10 | 7: '۷', 11 | 8: '۸', 12 | 9: '۹' 13 | } 14 | 15 | let result = value.toString() 16 | for (let i = 0; i <= 9; i++) { 17 | result = result.replace(new RegExp(`${i}`, 'g'), persian[i]) 18 | } 19 | value = result 20 | return result 21 | } -------------------------------------------------------------------------------- /src/app.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 17 | 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vue-persian-digit 2 | this filter convert number in the text to persian number 3 | 4 | 5 | ## Installation 6 | 7 | 8 | ### NPM 9 | 10 | ``` 11 | npm install vue-persian-digit --save 12 | ``` 13 | 14 | When used with a module system, you must explicitly install the filters via `Vue.use()`: 15 | 16 | ```js 17 | import Vue from 'vue' 18 | import VuePersianDigit from 'vue-persian-digit' 19 | 20 | // Vue.install(VuePersianDigit); // Vue V1 21 | Vue.use(VuePersianDigit); // Vue V2 22 | ``` 23 | 24 | 25 | ### How To Use? 26 | 27 | + Example: 28 | 29 | ```js 30 | {{ msg | persianDigit }} // 'سلام این متن شامل اعداد بصورت انگلیسی میباشد. برای مثال شما عدد 1234567890 رو در نظر بگیرید.' => 'سلام این متن شامل اعداد بصورت انگلیسی میباشد. برای مثال شما عدد ۱۲۳۴۵۶۷۸۹۰ رو در نظر بگیرید.' 31 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-persian-digit", 3 | "version": "0.0.7", 4 | "description": "> this filter convert number in the text to persian number", 5 | "main": "./src/main.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/behnamjz/vue-persian-digit.git" 12 | }, 13 | "keywords": [ 14 | "Filter", 15 | "Vue Filter", 16 | "Vuejs Filter", 17 | "SSR", 18 | "Web", 19 | "Components", 20 | "Vue", 21 | "VueJS", 22 | "Vue2", 23 | "WebComponents", 24 | "Popper.js", 25 | "Persian", 26 | "Persianjs", 27 | "Persian Numbers Filters", 28 | "Persian Digit Filter" 29 | ], 30 | "author": "behnam jaberi", 31 | "license": "ISC", 32 | "bugs": { 33 | "url": "https://github.com/behnamjz/vue-persian-digit/issues" 34 | }, 35 | "homepage": "https://github.com/behnamjz/vue-persian-digit#readme" 36 | } -------------------------------------------------------------------------------- /npm-debug.log: -------------------------------------------------------------------------------- 1 | 0 info it worked if it ends with ok 2 | 1 verbose cli [ '/usr/local/Cellar/node/7.4.0/bin/node', 3 | 1 verbose cli '/usr/local/bin/npm', 4 | 1 verbose cli 'publish' ] 5 | 2 info using npm@4.0.5 6 | 3 info using node@v7.4.0 7 | 4 verbose publish [ '.' ] 8 | 5 verbose stack Error: Failed to parse json 9 | 5 verbose stack Trailing comma in object at 49:1 10 | 5 verbose stack } 11 | 5 verbose stack ^ 12 | 5 verbose stack at parseError (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:390:11) 13 | 5 verbose stack at parseJson (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:79:23) 14 | 5 verbose stack at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:48:5 15 | 5 verbose stack at /usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:78:16 16 | 5 verbose stack at tryToString (fs.js:426:3) 17 | 5 verbose stack at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:413:12) 18 | 6 verbose cwd /Applications/XAMPP/xamppfiles/htdocs/vue-persian-digit 19 | 7 error Darwin 18.2.0 20 | 8 error argv "/usr/local/Cellar/node/7.4.0/bin/node" "/usr/local/bin/npm" "publish" 21 | 9 error node v7.4.0 22 | 10 error npm v4.0.5 23 | 11 error file /Applications/XAMPP/xamppfiles/htdocs/vue-persian-digit/package.json 24 | 12 error code EJSONPARSE 25 | 13 error Failed to parse json 26 | 13 error Trailing comma in object at 49:1 27 | 13 error } 28 | 13 error ^ 29 | 14 error File: /Applications/XAMPP/xamppfiles/htdocs/vue-persian-digit/package.json 30 | 15 error Failed to parse package.json data. 31 | 15 error package.json must be actual JSON, not just JavaScript. 32 | 15 error 33 | 15 error This is not a bug in npm. 34 | 15 error Tell the package author to fix their package.json file. JSON.parse 35 | 16 verbose exit [ 1, true ] 36 | --------------------------------------------------------------------------------