Skip to content

Commit 5b24cf5

Browse files
refactor: use newer readonly array syntax (#21)
BREAKING CHANGE: now requires Typescript 3.4.1 or higher as of v4.0.2 of this library.
1 parent 9536b17 commit 5b24cf5

File tree

7 files changed

+19
-19
lines changed

7 files changed

+19
-19
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@
4545
},
4646
"devDependencies": {
4747
"@types/fs-extra": "^5.0.5",
48-
"@types/node": "^11.12.1",
48+
"@types/node": "^11.12.2",
4949
"@types/object-hash": "^1.2.0",
5050
"@types/uuid": "^3.4.4",
5151
"@types/xmldom": "^0.1.29",
5252
"fs-extra": "^7.0.1",
5353
"rollup": "^1.7.4",
5454
"rollup-plugin-commonjs": "^9.2.2",
5555
"rollup-plugin-typescript2": "^0.20.1",
56-
"semantic-release": "^15.13.8",
56+
"semantic-release": "^15.13.3",
5757
"ts-node": "^8.0.3",
5858
"tslint": "^5.14.0",
5959
"tslint-immutable": "^5.5.2",

src/config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ export interface IIPScannerConfig {
1313
* 255 addresses to scan (0...255)
1414
* ex: ['10.211.55', '44.55.11']
1515
*/
16-
readonly PREFIXES: ReadonlyArray<string>
16+
readonly PREFIXES: readonly string[]
1717

1818
/**
1919
* List of ip address to scan
2020
* This will be in addition to the defailt gateway devices
2121
* found on the local machine
2222
* ex: ['10.211.55.10', '44.55.11.15']
2323
*/
24-
readonly IP_ADDRESSES: ReadonlyArray<string>
24+
readonly IP_ADDRESSES: readonly string[]
2525
}
2626

2727
/**
@@ -31,7 +31,7 @@ export interface IProbeConfig {
3131
/**
3232
* Ports to broadcast to.
3333
*/
34-
readonly PORTS: ReadonlyArray<number>
34+
readonly PORTS: readonly number[]
3535

3636
/**
3737
* IP based scanning
@@ -62,7 +62,7 @@ export interface IProbeConfig {
6262
/**
6363
* ONVIF device types to check for.
6464
*/
65-
readonly ONVIF_DEVICES: ReadonlyArray<string>
65+
readonly ONVIF_DEVICES: readonly string[]
6666

6767
/**
6868
* An object the conforms to the W3C DOMParser spec. This helps parse respnse XML.

src/device.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export interface IONVIFDevice {
66
readonly metadataVersion: string
77
readonly deviceServiceUri: string
88
readonly ip: string
9-
readonly profiles: ReadonlyArray<string>
10-
readonly xaddrs: ReadonlyArray<string>
11-
readonly scopes: ReadonlyArray<string>
9+
readonly profiles: readonly string[]
10+
readonly xaddrs: readonly string[]
11+
readonly scopes: readonly string[]
1212
}

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ export { IONVIFDevice }
1414
export { DEFAULT_CONFIG }
1515

1616
const uniqueObjects =
17-
(arr: ReadonlyArray<any>) =>
17+
(arr: readonly any[]) =>
1818
arr.filter((object, index) => index === arr.findIndex(obj => JSON.stringify(obj) === JSON.stringify(object)))
1919

20-
type ProbeStream = Observable<ReadonlyArray<IONVIFDevice>>
20+
type ProbeStream = Observable<readonly IONVIFDevice[]>
2121

2222
export const probeONVIFDevices = () => reader<Partial<IProbeConfig>, ProbeStream>(partialConfig => {
2323
const config: IProbeConfig = { ...DEFAULT_CONFIG, ...partialConfig }
@@ -50,7 +50,7 @@ export const probeONVIFDevices = () => reader<Partial<IProbeConfig>, ProbeStream
5050
map(xmlResponse => xmlResponse
5151
.map(xmlString => config.DOM_PARSER.parseFromString(xmlString, 'application/xml'))
5252
.map(xmlDoc => parseXmlResponse(xmlDoc)(config))),
53-
mergeScan<IMaybe<IONVIFDevice>, ReadonlyArray<IONVIFDevice>>((acc, curr) => {
53+
mergeScan<IMaybe<IONVIFDevice>, readonly IONVIFDevice[]>((acc, curr) => {
5454
return forkJoin([...acc, curr.valueOrUndefined() as IONVIFDevice].filter(Boolean).map(device => ping(device.ip)()(config.PROBE_NETWORK_TIMEOUT_MS).pipe(
5555
map(v => v.isOk()
5656
? { include: true, device }

src/ipscan.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const getIpPrefixListFromNetworkInterfaces = (family: 'IPv4' | 'IPv6' = '
1212
const interfaceDict = networkInterfaces()
1313

1414
return Object.keys(interfaceDict)
15-
.reduce((acc: ReadonlyArray<NetworkInterfaceInfo>, curr) => [...acc, ...interfaceDict[curr]], [])
15+
.reduce((acc: readonly NetworkInterfaceInfo[], curr) => [...acc, ...interfaceDict[curr]], [])
1616
.filter(a => a.family === family && !a.internal)
1717
.map(c => c.address.split('.').slice(0, 3).join('.'))
1818
}
@@ -21,8 +21,8 @@ export const getIpPrefixListFromNetworkInterfaces = (family: 'IPv4' | 'IPv6' = '
2121
export const combined = (...args: string[][]) => args.reduce((acc, curr) => [...acc, ...curr], [])
2222

2323
export const ipscan =
24-
(ipAddressPrefixes: ReadonlyArray<string> = []) =>
25-
(ipAddresses: ReadonlyArray<string> = []) => {
24+
(ipAddressPrefixes: readonly string[] = []) =>
25+
(ipAddresses: readonly string[] = []) => {
2626
const standard = getIpPrefixListFromNetworkInterfaces().map(getIpRangeFromPrefix())
2727
const pref = ipAddressPrefixes.map(getIpRangeFromPrefix())
2828
// tslint:disable-next-line:readonly-array

src/parse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const parseXmlResponse = (doc: Document) => (config: IProbeConfig): IONVI
1818
const parseProbeDiscoveryElements = parseProbeElements(SCHEMAS.discovery)
1919
const parseProbeAddressingElements = parseProbeElements(SCHEMAS.addressing)
2020

21-
const scopeParser = (scopes: ReadonlyArray<string>) => (pattern: string) =>
21+
const scopeParser = (scopes: readonly string[]) => (pattern: string) =>
2222
maybe(scopes.find(a => a.toLowerCase().includes(`onvif://www.onvif.org/${pattern}`.toLocaleLowerCase()))).flatMapAuto(a => a.split('/').pop())
2323

2424
const scopes = parseProbeDiscoveryElements('Scopes').flatMapAuto(a => a.textContent).map(a => a.split(' ')).valueOr([])

0 commit comments

Comments
 (0)