@aceandtate/clicktoaddress
Advanced tools
Comparing version 0.1.11 to 0.1.12
@@ -1,2 +0,2 @@ | ||
import { RetrieveResponseResult, RetrieveArgs } from './types'; | ||
import { RetrieveResponseResult, RetrieveArgs } from "./types"; | ||
export default function mapRetrievedResult(args: RetrieveArgs, result: RetrieveResponseResult): RetrieveResponseResult; |
@@ -18,5 +18,8 @@ "use strict"; | ||
if (isNumeric(result.building_name) && !result.building_number) { | ||
return __assign(__assign({}, result), { building_name: '', building_number: result.building_name }); | ||
return __assign(__assign({}, result), { building_name: "", building_number: result.building_name }); | ||
} | ||
return result; | ||
}, | ||
US: function (result) { | ||
return __assign(__assign({}, result), { postal_code: result.postal_code.split("-")[0] }); | ||
} | ||
@@ -23,0 +26,0 @@ }; |
{ | ||
"name": "@aceandtate/clicktoaddress", | ||
"version": "0.1.11", | ||
"version": "0.1.12", | ||
"description": "A clicktoaddress client", | ||
@@ -10,3 +10,3 @@ "main": "dist/index.js", | ||
"develop": "tsc -w", | ||
"prepublish": "npm run -s test && npm run -s build" | ||
"prepublishOnly": "npm run -s test && npm run -s build" | ||
}, | ||
@@ -13,0 +13,0 @@ "repository": { |
@@ -1,10 +0,12 @@ | ||
import { RetrieveArgs, RetrieveResponseResult } from './types'; | ||
import mapRetrievedResult from './mapRetrievedResult'; | ||
import { RetrieveArgs, RetrieveResponseResult } from "./types"; | ||
import mapRetrievedResult from "./mapRetrievedResult"; | ||
describe('mapRetrievedResult', () => { | ||
it('should return same result if no mapper is required', () => { | ||
const responseResult = { building_name: 'BUILDING NAME' } as RetrieveResponseResult; | ||
describe("mapRetrievedResult", () => { | ||
it("should return same result if no mapper is required", () => { | ||
const responseResult = { | ||
building_name: "BUILDING NAME" | ||
} as RetrieveResponseResult; | ||
const result = mapRetrievedResult( | ||
{ country: 'NL' } as RetrieveArgs, | ||
responseResult, | ||
{ country: "NL" } as RetrieveArgs, | ||
responseResult | ||
); | ||
@@ -14,23 +16,41 @@ expect(result).toBe(responseResult); | ||
it('should map Spain address\' building number and name', () => { | ||
it("should map Spain address' building number and name", () => { | ||
const result = mapRetrievedResult( | ||
{ country: 'ES' } as RetrieveArgs, | ||
{ building_name: '1', building_number: '' } as RetrieveResponseResult, | ||
{ country: "ES" } as RetrieveArgs, | ||
{ building_name: "1", building_number: "" } as RetrieveResponseResult | ||
); | ||
expect(result).toEqual({ | ||
building_number: '1', | ||
building_name: '' | ||
building_number: "1", | ||
building_name: "" | ||
}); | ||
}); | ||
it('should skip mapping Spain address\' when data seems valid', () => { | ||
it("should skip mapping Spain address' when data seems valid", () => { | ||
const result = mapRetrievedResult( | ||
{ country: 'ES' } as RetrieveArgs, | ||
{ building_name: 'x', building_number: '1' } as RetrieveResponseResult, | ||
{ country: "ES" } as RetrieveArgs, | ||
{ building_name: "x", building_number: "1" } as RetrieveResponseResult | ||
); | ||
expect(result).toEqual({ | ||
building_number: '1', | ||
building_name: 'x' | ||
building_number: "1", | ||
building_name: "x" | ||
}); | ||
}); | ||
}) | ||
it("should format the post code in US without a second parameter", () => { | ||
const result = mapRetrievedResult( | ||
{ country: "US" } as RetrieveArgs, | ||
{ postal_code: "30328-6228" } as RetrieveResponseResult | ||
); | ||
expect(result).toEqual({ postal_code: "30328" }); | ||
}); | ||
it("should not format the post code in another coutry", () => { | ||
const result = mapRetrievedResult( | ||
{ country: "NL" } as RetrieveArgs, | ||
{ postal_code: "30328-6228" } as RetrieveResponseResult | ||
); | ||
expect(result).toEqual({ postal_code: "30328-6228" }); | ||
}); | ||
}); |
@@ -1,2 +0,2 @@ | ||
import { RetrieveResponseResult, RetrieveArgs } from './types'; | ||
import { RetrieveResponseResult, RetrieveArgs } from "./types"; | ||
@@ -6,3 +6,5 @@ const isNumeric = (str: string) => !isNaN(parseFloat(str)); | ||
interface CountryMappers { | ||
[countryCode: string]: (result: RetrieveResponseResult) => RetrieveResponseResult; | ||
[countryCode: string]: ( | ||
result: RetrieveResponseResult | ||
) => RetrieveResponseResult; | ||
} | ||
@@ -15,12 +17,20 @@ | ||
...result, | ||
building_name: '', | ||
building_number: result.building_name, | ||
} | ||
building_name: "", | ||
building_number: result.building_name | ||
}; | ||
} | ||
return result; | ||
}, | ||
US(result: RetrieveResponseResult) { | ||
return { | ||
...result, | ||
postal_code: result.postal_code.split("-")[0] | ||
}; | ||
} | ||
} as const; | ||
export default function mapRetrievedResult(args: RetrieveArgs, result: RetrieveResponseResult) { | ||
export default function mapRetrievedResult( | ||
args: RetrieveArgs, | ||
result: RetrieveResponseResult | ||
) { | ||
const countryCode = args.country as keyof typeof countryMappers; | ||
@@ -27,0 +37,0 @@ const mapper = countryMappers[`${countryCode}`.toUpperCase()]; |
Sorry, the diff of this file is not supported yet
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
90109
29
1024
1