Comparing version 1.0.1 to 1.0.2
"use strict"; | ||
exports.__esModule = true; | ||
exports.readTableWithHeader = exports.readTable = exports.getValueByProperty = exports.getFieldName = void 0; | ||
exports.readTableWithHeader = exports.readTable = exports.getFieldName = void 0; | ||
require("cheerio"); | ||
@@ -62,6 +62,2 @@ var locationValue = function (location) { | ||
exports.getFieldName = getFieldName; | ||
function getValueByProperty($, prop, value) { | ||
return $("[" + prop + "='" + value + "']").text().trim(); | ||
} | ||
exports.getValueByProperty = getValueByProperty; | ||
function readTable($, table) { | ||
@@ -68,0 +64,0 @@ var rows = $("tr", table).toArray(); |
{ | ||
"name": "aus-abr", | ||
"version": "1.0.1", | ||
"description": "NodeJS package to retrieve ABN or ACN from https://abr.business.gov.au/", | ||
"version": "1.0.2", | ||
"description": "NodeJS package to retrieve ABN or ACN from https://abr.business.gov.au/ using html parse to extract information", | ||
"main": "lib/index.js", | ||
@@ -6,0 +6,0 @@ "scripts": { |
@@ -10,3 +10,6 @@ # aus-abr | ||
[![Coverage Status](https://coveralls.io/repos/github/samuraitruong/aus-abr/badge.svg?branch=master)](https://coveralls.io/github/samuraitruong/aus-abr?branch=master) | ||
This library will make request to public website to retrive and parse data , If you required to use more data, please consider to use ACIS official api | ||
To use official webservice please visit https://abr.business.gov.au/Tools/WebServices | ||
# Install | ||
@@ -47,7 +50,9 @@ | ||
```js | ||
const ausAbr = require("aus-abr"); | ||
(async () => { | ||
const ausAbr = require("aus-abr"); | ||
const details = await ausAbr.lookupABN("61006912563"); | ||
const details = await ausAbr.lookupABN("61006912563"); | ||
console.log(details); | ||
console.log(details); | ||
})(); | ||
``` | ||
@@ -54,0 +59,0 @@ |
@@ -61,3 +61,3 @@ import "cheerio"; | ||
export function readTable($: CheerioStatic, table: CheerioElement) { | ||
export function readTable<T>($: CheerioStatic, table: CheerioElement) { | ||
const rows = $("tr", table).toArray(); | ||
@@ -72,6 +72,6 @@ const text = (el) => $(el).text().trim(); | ||
}); | ||
return result; | ||
return result as T; | ||
} | ||
export function readTableWithHeader( | ||
export function readTableWithHeader<T>( | ||
$: CheerioStatic, | ||
@@ -94,4 +94,4 @@ table: CheerioElement, | ||
}); | ||
return item; | ||
return item as T; | ||
}); | ||
} |
@@ -24,2 +24,7 @@ import { lookup } from "dns"; | ||
}); | ||
it("should return null for abn=61006912566", async () => { | ||
const data = await lookupABN("61006912566"); | ||
expect(data).toBe(null); | ||
}); | ||
}); | ||
@@ -43,2 +48,6 @@ | ||
); | ||
it("should return null for abn=61006912566", async () => { | ||
const data = await getHistory("61006912566"); | ||
expect(data).toBe(null); | ||
}); | ||
}); | ||
@@ -58,2 +67,7 @@ | ||
); | ||
it("should return empty list when nothing match with search condition ", async () => { | ||
const data = await searchActive("nothingwillmatchthissearch"); | ||
expect(data).toHaveLength(0); | ||
}); | ||
}); |
@@ -5,2 +5,3 @@ import axios from "axios"; | ||
import { TableNames } from "./enum"; | ||
import { ISearchItem, IBusinessName, IABNDetail } from "./intefaces"; | ||
@@ -19,2 +20,7 @@ async function fetch(url) { | ||
} | ||
/** | ||
* Get current details for giving abn | ||
* @param abn the particular abn/acn to get information | ||
*/ | ||
export async function lookupABN(abn: string) { | ||
@@ -25,6 +31,8 @@ const stripped = abn.replace(/\s/gi, ""); | ||
const { $, parseTable } = await fetch(url); | ||
if (!parseTable[TableNames.ABN_DETAILS]) { | ||
return null; | ||
} | ||
return { | ||
details: readTable($, parseTable[TableNames.ABN_DETAILS]), | ||
tradingNames: readTableWithHeader( | ||
details: readTable<IABNDetail>($, parseTable[TableNames.ABN_DETAILS]), | ||
tradingNames: readTableWithHeader<IBusinessName>( | ||
$, | ||
@@ -34,3 +42,6 @@ parseTable[TableNames.TRADING_NAME], | ||
), | ||
businessNames: readTableWithHeader($, parseTable[TableNames.BUSINESS_NAME]), | ||
businessNames: readTableWithHeader<IBusinessName>( | ||
$, | ||
parseTable[TableNames.BUSINESS_NAME] | ||
), | ||
}; | ||
@@ -43,3 +54,6 @@ } | ||
const { tables, $ } = await fetch(url); | ||
const { parseTable, $ } = await fetch(url); | ||
if (!parseTable[TableNames.ABN_DETAILS]) { | ||
return null; | ||
} | ||
@@ -67,2 +81,7 @@ const result: any = {}; | ||
/** | ||
* Find list of all business name or entity name that match with the input keywork | ||
* @param keyword entty name or business name to search | ||
* @returns {ISearchItem[]} list of all business that match with condition search | ||
*/ | ||
export async function searchActive(keyword: string) { | ||
@@ -74,3 +93,3 @@ const url = `https://abr.business.gov.au/Search/ResultsActive?SearchText=${decodeURIComponent( | ||
return readTableWithHeader($, parseTable["Matching names"]); | ||
return readTableWithHeader<ISearchItem>($, parseTable["Matching names"]); | ||
} |
@@ -8,3 +8,4 @@ { | ||
"sourceMap": true, | ||
"rootDir": "src" | ||
"rootDir": "src", | ||
"declaration": true | ||
}, | ||
@@ -11,0 +12,0 @@ "include": ["src"], |
Sorry, the diff of this file is not supported yet
144970
22
546
264