is-valid-acn
Advanced tools
Comparing version 1.2.0 to 1.3.0
var weights = [8, 7, 6, 5, 4, 3, 2, 1]; | ||
export default function isValidACN(rawAcn) { | ||
if (!rawAcn) { | ||
return false; | ||
} // strip non-alphanumeric characters | ||
var acn = rawAcn.toString().replace(/[^a-z\d]/gi, ''); // check if length is 9 digits | ||
if (acn.length !== 9) { | ||
return false; | ||
} // apply ato check method | ||
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; | ||
} | ||
var checksum = (10 - sum % 10) % 10; | ||
return checksum === parseInt(acn[8], 10); | ||
} | ||
if (!rawAcn) { | ||
return false; | ||
} | ||
// strip non-alphanumeric characters | ||
var acn = rawAcn.toString().replace(/[^a-z\d]/gi, ''); | ||
// check if length is 9 digits | ||
if (acn.length !== 9) { | ||
return false; | ||
} | ||
// apply ato check method | ||
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; | ||
} | ||
var checksum = (10 - (sum % 10)) % 10; | ||
return checksum === parseInt(acn[8], 10); | ||
} |
{ | ||
"name": "is-valid-acn", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Check if a number is a valid Australian Company Number (ACN)", | ||
"main": "dist/umd/index.js", | ||
"main": "dist/cjs/index.js", | ||
"module": "dist/esm/index.js", | ||
"source": "src/index.js", | ||
"source": "src/index.ts", | ||
"types": "src/index.ts", | ||
"sideEffects": false, | ||
@@ -14,10 +15,12 @@ "type": "module", | ||
"scripts": { | ||
"build": "yarn build-esm && yarn build-umd", | ||
"build-esm": "BABEL_ENV=production-esm babel src -d dist/esm --ignore **/*.spec.js", | ||
"build-umd": "BABEL_ENV=production-umd babel src -d dist/umd --ignore **/*.spec.js", | ||
"build": "yarn build-esm && yarn build-cjs", | ||
"build-esm": "tsc --project tsconfig.build.json --outDir dist/esm --module esnext", | ||
"build-cjs": "tsc --project tsconfig.build.json --outDir dist/cjs --module commonjs", | ||
"clean": "rimraf dist", | ||
"jest": "jest", | ||
"lint": "eslint src/ --ext .jsx,.js", | ||
"lint": "eslint src --ext .js,.ts", | ||
"prepack": "yarn clean && yarn build", | ||
"test": "yarn lint && yarn jest" | ||
"prettier": "prettier --check . --cache", | ||
"test": "yarn lint && yarn tsc && yarn prettier && yarn jest", | ||
"tsc": "tsc --noEmit" | ||
}, | ||
@@ -34,12 +37,16 @@ "keywords": [ | ||
"devDependencies": { | ||
"@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", | ||
"@babel/preset-typescript": "^7.18.6", | ||
"@types/jest": "^29.0.0", | ||
"@typescript-eslint/eslint-plugin": "^5.41.0", | ||
"@typescript-eslint/parser": "^5.44.0", | ||
"eslint": "^8.26.0", | ||
"eslint-config-wojtekmaj": "^0.7.1", | ||
"husky": "^8.0.0", | ||
"jest": "^27.0.0", | ||
"prettier": "^2.5.0", | ||
"jest": "^29.0.0", | ||
"prettier": "^2.7.0", | ||
"pretty-quick": "^3.1.0", | ||
"rimraf": "^3.0.0" | ||
"rimraf": "^3.0.0", | ||
"typescript": "^4.9.4" | ||
}, | ||
@@ -55,5 +62,6 @@ "resolutions": { | ||
"type": "git", | ||
"url": "https://github.com/DemystData/is-valid-acn.git" | ||
"url": "https://github.com/wojtekmaj/is-valid-acn.git" | ||
}, | ||
"funding": "https://github.com/wojtekmaj/is-valid-acn?sponsor=1", | ||
"packageManager": "yarn@3.1.0" | ||
} |
@@ -1,2 +0,2 @@ | ||
[![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) | ||
[![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/wojtekmaj/is-valid-acn/workflows/CI/badge.svg)](https://github.com/wojtekmaj/is-valid-acn/actions) [![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://github.com/facebook/jest) | ||
@@ -15,3 +15,3 @@ # Is-Valid-ACN | ||
- [is-valid-abn](https://github.com/DemystData/is-valid-abn): Check if a number is a valid Australian Business Number (ABN). | ||
- [is-valid-abn](https://github.com/wojtekmaj/is-valid-abn): Check if a number is a valid Australian Business Number (ABN). | ||
@@ -18,0 +18,0 @@ ## Examples |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
7830
14
112
1