is-valid-acn
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -8,19 +8,19 @@ var weights = [8, 7, 6, 5, 4, 3, 2, 1]; | ||
var acn = rawAcn.toString().replace(/[^a-zA-Z\d]/gi, ''); // check length is 9 digits | ||
var acn = rawAcn.toString().replace(/[^a-z\d]/gi, ''); // check if length is 9 digits | ||
if (acn.length === 9) { | ||
// apply ato check method | ||
var sum = 0; | ||
if (acn.length !== 9) { | ||
return false; | ||
} // apply ato check method | ||
for (var position = 0; position < weights.length; position += 1) { | ||
var weight = weights[position]; | ||
var digit = parseInt(acn[position], 10); | ||
sum += weight * digit; | ||
} | ||
var checksum = (10 - sum % 10) % 10; | ||
return checksum === parseInt(acn[8], 10); | ||
var sum = 0; | ||
for (var position = 0; position < weights.length; position += 1) { | ||
var weight = weights[position]; | ||
var digit = parseInt(acn[position], 10); | ||
sum += weight * digit; | ||
} | ||
return false; | ||
var checksum = (10 - sum % 10) % 10; | ||
return checksum === parseInt(acn[8], 10); | ||
} |
@@ -15,19 +15,19 @@ "use strict"; | ||
var acn = rawAcn.toString().replace(/[^a-zA-Z\d]/gi, ''); // check length is 9 digits | ||
var acn = rawAcn.toString().replace(/[^a-z\d]/gi, ''); // check if length is 9 digits | ||
if (acn.length === 9) { | ||
// apply ato check method | ||
var sum = 0; | ||
if (acn.length !== 9) { | ||
return false; | ||
} // apply ato check method | ||
for (var position = 0; position < weights.length; position += 1) { | ||
var weight = weights[position]; | ||
var digit = parseInt(acn[position], 10); | ||
sum += weight * digit; | ||
} | ||
var checksum = (10 - sum % 10) % 10; | ||
return checksum === parseInt(acn[8], 10); | ||
var sum = 0; | ||
for (var position = 0; position < weights.length; position += 1) { | ||
var weight = weights[position]; | ||
var digit = parseInt(acn[position], 10); | ||
sum += weight * digit; | ||
} | ||
return false; | ||
var checksum = (10 - sum % 10) % 10; | ||
return checksum === parseInt(acn[8], 10); | ||
} |
{ | ||
"name": "is-valid-acn", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Check if a number is a valid Australian Company Number (ACN)", | ||
@@ -9,2 +9,6 @@ "main": "dist/umd/index.js", | ||
"sideEffects": false, | ||
"type": "module", | ||
"exports": { | ||
"default": "./dist/esm/index.js" | ||
}, | ||
"scripts": { | ||
@@ -14,5 +18,6 @@ "build": "yarn build-esm && yarn build-umd", | ||
"build-umd": "BABEL_ENV=production-umd babel src -d dist/umd --ignore **/*.spec.js", | ||
"clean": "rimraf dist", | ||
"jest": "jest", | ||
"lint": "eslint src/ --ext .jsx,.js", | ||
"prepublishOnly": "yarn build", | ||
"prepack": "yarn clean && yarn build", | ||
"test": "yarn lint && yarn jest" | ||
@@ -30,18 +35,25 @@ }, | ||
"devDependencies": { | ||
"@babel/cli": "^7.0.0", | ||
"@babel/core": "^7.0.0", | ||
"@babel/preset-env": "^7.4.0", | ||
"babel-jest": "^24.8.0", | ||
"eslint": "^5.16.0", | ||
"eslint-config-airbnb-base": "^13.2.0", | ||
"eslint-plugin-import": "^2.18.0", | ||
"jest": "^24.8.0" | ||
"@babel/cli": "^7.15.0", | ||
"@babel/core": "^7.15.0", | ||
"@babel/preset-env": "^7.15.0", | ||
"eslint": "^8.5.0", | ||
"eslint-config-wojtekmaj": "^0.6.5", | ||
"husky": "^8.0.0", | ||
"jest": "^27.0.0", | ||
"prettier": "^2.5.0", | ||
"pretty-quick": "^3.1.0", | ||
"rimraf": "^3.0.0" | ||
}, | ||
"resolutions": { | ||
"semver@7.0.0": "^7.0.0" | ||
}, | ||
"files": [ | ||
"LICENSE", | ||
"README.md", | ||
"dist/", | ||
"src/" | ||
"dist", | ||
"src" | ||
], | ||
"repository": "https://github.com/DemystData/is-valid-acn.git" | ||
} | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/DemystData/is-valid-acn.git" | ||
}, | ||
"packageManager": "yarn@3.1.0" | ||
} |
@@ -1,11 +0,17 @@ | ||
[![npm](https://img.shields.io/npm/v/is-valid-acn.svg)](https://www.npmjs.com/package/is-valid-acn) ![downloads](https://img.shields.io/npm/dt/is-valid-acn.svg) [![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://github.com/facebook/jest) | ||
[![npm](https://img.shields.io/npm/v/is-valid-acn.svg)](https://www.npmjs.com/package/is-valid-acn) ![downloads](https://img.shields.io/npm/dt/is-valid-acn.svg) [![CI](https://github.com/DemystData/is-valid-acn/workflows/CI/badge.svg)](https://github.com/DemystData/is-valid-acn/actions) [![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://github.com/facebook/jest) | ||
# is-valid-acn | ||
# Is-Valid-ACN | ||
Check if a number is a valid Australian Company Number (ACN). | ||
## tl;dr | ||
* Install by executing `npm install is-valid-acn` or `yarn add is-valid-acn`. | ||
* Import by adding `import isValidACN from 'is-valid-acn'`. | ||
* Use it by writing `const valid = isValidACN('010499966')` | ||
- Install by executing `npm install is-valid-acn` or `yarn add is-valid-acn`. | ||
- Import by adding `import isValidACN from 'is-valid-acn'`. | ||
- Use it by writing `const valid = isValidACN('010499966')` | ||
## See also | ||
- [is-valid-abn](https://github.com/DemystData/is-valid-abn): Check if a number is a valid Australian Business Number (ABN). | ||
## Examples | ||
@@ -38,5 +44,5 @@ | ||
<a href="mailto:kontakt@wojtekmaj.pl">kontakt@wojtekmaj.pl</a><br /> | ||
<a href="http://wojtekmaj.pl">http://wojtekmaj.pl</a> | ||
<a href="https://wojtekmaj.pl">https://wojtekmaj.pl</a> | ||
</td> | ||
</tr> | ||
</table> |
@@ -9,19 +9,20 @@ const weights = [8, 7, 6, 5, 4, 3, 2, 1]; | ||
// strip non-alphanumeric characters | ||
const acn = rawAcn.toString().replace(/[^a-zA-Z\d]/gi, ''); | ||
const acn = rawAcn.toString().replace(/[^a-z\d]/gi, ''); | ||
// check length is 9 digits | ||
if (acn.length === 9) { | ||
// apply ato check method | ||
let sum = 0; | ||
for (let position = 0; position < weights.length; position += 1) { | ||
const weight = weights[position]; | ||
const digit = parseInt(acn[position], 10); | ||
sum += weight * digit; | ||
} | ||
// check if length is 9 digits | ||
if (acn.length !== 9) { | ||
return false; | ||
} | ||
const checksum = (10 - (sum % 10)) % 10; | ||
return checksum === parseInt(acn[8], 10); | ||
// apply ato check method | ||
let sum = 0; | ||
for (let position = 0; position < weights.length; position += 1) { | ||
const weight = weights[position]; | ||
const digit = parseInt(acn[position], 10); | ||
sum += weight * digit; | ||
} | ||
return false; | ||
const checksum = (10 - (sum % 10)) % 10; | ||
return checksum === parseInt(acn[8], 10); | ||
} |
@@ -22,2 +22,8 @@ import isValidACN from './index'; | ||
it('returns false for partially numeric input', () => { | ||
const result = isValidACN('010499966FOX'); | ||
expect(result).toBe(false); | ||
}); | ||
it('returns false for invalid input with invalid length', () => { | ||
@@ -34,2 +40,3 @@ const result = isValidACN('123'); | ||
}); | ||
it('returns true for valid numeric input', () => { | ||
@@ -36,0 +43,0 @@ const result = isValidACN(143526096); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
10429
9
189
48
0
Yes
10