Repository URL to install this package:
|
Version:
3.0.0-beta.3 ▾
|
<!doctype html>
<html lang="en">
<head>
<title>Code coverage report for validators/isValidZipCode.ts</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="../prettify.css" />
<link rel="stylesheet" href="../base.css" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type='text/css'>
.coverage-summary .sorter {
background-image: url(../sort-arrow-sprite.png);
}
</style>
</head>
<body>
<div class='wrapper'>
<div class='pad1'>
<h1>
<a href="../index.html">All files</a> / <a href="index.html">validators</a> isValidZipCode.ts
</h1>
<div class='clearfix'>
<div class='fl pad1y space-right2'>
<span class="strong">84.62% </span>
<span class="quiet">Statements</span>
<span class='fraction'>22/26</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">58.33% </span>
<span class="quiet">Branches</span>
<span class='fraction'>7/12</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">50% </span>
<span class="quiet">Functions</span>
<span class='fraction'>1/2</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">88% </span>
<span class="quiet">Lines</span>
<span class='fraction'>22/25</span>
</div>
</div>
</div>
<div class='status-line high'></div>
<pre><table class="coverage">
<tr><td class="line-count quiet">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43</td><td class="line-coverage quiet"><span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">10x</span>
<span class="cline-any cline-yes">10x</span>
<span class="cline-any cline-yes">10x</span>
<span class="cline-any cline-yes">10x</span>
<span class="cline-any cline-yes">10x</span>
<span class="cline-any cline-yes">10x</span>
<span class="cline-any cline-yes">10x</span>
<span class="cline-any cline-yes">10x</span>
<span class="cline-any cline-yes">10x</span>
<span class="cline-any cline-yes">10x</span>
<span class="cline-any cline-yes">10x</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">10x</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">7x</span>
<span class="cline-any cline-yes">4x</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">3x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">2x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-no"> </span>
<span class="cline-any cline-no"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-no"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">10x</span></td><td class="text"><pre class="prettyprint lang-js">import { isString } from 'exotic'
import { test } from './__match'
const matchUnitedKingdomPostCode = /^[A-Z]{1,2}[0-9RCHNQ][0-9A-Z]?\s?[0-9][ABD-HJLNP-UW-Z]{2}$|^[A-Z]{2}-?[0-9]{4}$/
const matchCanadianPostalCode = /^(?!.*[DFIOQU])[A-VXY][0-9][A-Z]\s?[0-9][A-Z][0-9]$/
const matchUnitedStatesZipCode = /^[0-9]{5}(?:-[0-9A-Za-z\d-]{4})?$/
const matchZipCodeLoosest = /^[0-9a-zA-Z]+$/
const isCanadian = test(matchCanadianPostalCode)
const isUnitedStates = test(matchUnitedStatesZipCode)
const isUnitedKingdom = test(matchUnitedKingdomPostCode)
const _isZipCodeLoosest = test(matchZipCodeLoosest)
// && String(x) !== '000'
// isValidLength(x, 2)<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" ></span></span>
const isZipCodeLoosest = (x: any) => x.length > 2 && _isZipCodeLoosest(x)
/**
* @see https://github.com/chriso/validator.js/blob/master/src/lib/isPostalCode.js
* @see http://formvalidation.io/validators/zipCode/
* @see https://stackoverflow.com/questions/578406/what-is-the-ultimate-postal-code-and-zip-regex
* @note - the conditional branching is intentional
* @see https://gist.github.com/aretecode/9b1765a897554b82da96591372d3c149
*/
function isValidZipCode(zipCode: string | number): boolean {
if (isString(zipCode) === false) {
return false
} else if (isCanadian(zipCode)) {
return true
} else if (isUnitedStates(zipCode)) {
return true
} else if (isUnitedKingdom(zipCode)) {
retur<span class="missing-if-branch" title="else path not taken" >E</span>n true
} else if (isZipCodeLoosest(zipCode)) {
return true
} else <span class="cstat-no" title="statement not covered" >{</span>
retu<span class="cstat-no" title="statement not covered" >rn false</span>
}
}
<span class="cstat-no" title="statement not covered" ></span>
export { isValidZipCode }
export default isValidZipCode
</pre></td></tr>
</table></pre>
<div class='push'></div><!-- for sticky footer -->
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
Code coverage
generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Sat Nov 10 2018 05:28:54 GMT-0800 (Pacific Standard Time)
</div>
</div>
<script src="../prettify.js"></script>
<script>
window.onload = function () {
if (typeof prettyPrint === 'function') {
prettyPrint();
}
};
</script>
<script src="../sorter.js"></script>
</body>
</html>