https://github.com/techlab23/tweetablejs
Short and reusable JS code
https://github.com/techlab23/tweetablejs
es6 javascript js
Last synced: about 1 year ago
JSON representation
Short and reusable JS code
- Host: GitHub
- URL: https://github.com/techlab23/tweetablejs
- Owner: techlab23
- Created: 2018-01-03T13:36:00.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-01-04T14:05:22.000Z (over 8 years ago)
- Last Synced: 2025-01-29T04:19:24.335Z (over 1 year ago)
- Topics: es6, javascript, js
- Language: JavaScript
- Homepage:
- Size: 1.95 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Tweetable JS
### validateACN
Validate the given Australian Company Number (ACN)
```js
const validateACN = acn => {
if (acn.length != 9 || isNaN(parseInt(acn))) return false
const w = [8,7,6,5,4,3,2,1].reduce((acc,itm,idx) => acc + (parseInt(acn.charAt(idx)) * itm),0)
const cd = (10 - (w % 10)) == 10 ? 0 : 10 - (w % 10)
return cd === parseInt(acn[8])
}
```
```js
validateACN('004085616')
```
### validateABN
Validate the given Australian Business Number (ABN)
```js
const validateABN = abn => {
if (abn.length != 11 || isNaN(parseInt(abn))) return false
const w = [10,1,3,5,7,9,11,13,15,17,19].reduce((acc,itm,idx) => acc + (idx===0 ? (parseInt(abn.charAt(idx))-1)*itm : parseInt(abn.charAt(idx))*itm),0)
return (w % 89) === 0
}
```
```js
validateABN('51824753556')
```
### validateMod10v01
Validate the given number with Mod10V01 (Luhn's alogorithm)
```js
const validateMod10v01 = inp => {
if (inp.length>20||isNaN(parseInt(inp))) return false
let w = [...inp].reduceRight((acc,itm,idx) => {
let num = parseInt(itm) * ((idx+1) % 2 == 0 ? 2 : 1)
return acc + (num < 10 ? num : num - 9)
},0)
return (w % 10) === 0
}
```
```js
validateMod10v01('79927398713')
```