Skip to content

Commit

Permalink
feat(isfloat): added type check parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
LCluber committed Aug 9, 2019
1 parent dee8ae5 commit d4bbc2b
Show file tree
Hide file tree
Showing 14 changed files with 328 additions and 240 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ isObject(object: any): boolean {}

isArray(array: any): boolean {}

isAscii(code: any, extended: boolean): boolean {}
isAscii(code: any, extended: boolean = false): boolean {}

isInteger(number: any, typeCheck: boolean = true): boolean {}

isFloat(number: any): boolean {}
isFloat(number: any, typeCheck: boolean = true): boolean {}

isNumber(number: any): boolean {}

Expand Down
4 changes: 2 additions & 2 deletions dist/ch.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ declare function isJson(str: any): boolean;
declare function isFunction(func: any): boolean;
declare function isObject(object: any): boolean;
declare function isArray(array: any): boolean;
declare function isAscii(code: any, extended: boolean): boolean;
declare function isAscii(code: any, extended?: boolean): boolean;
declare function isInteger(number: any, typeCheck?: boolean): boolean;
declare function isFloat(number: any): boolean;
declare function isFloat(number: any, typeCheck?: boolean): boolean;
declare function isNumber(number: any): boolean;
declare function isString(string: any): boolean;
declare function isHtmlElement(htmlElement: any): boolean;
Expand Down
7 changes: 5 additions & 2 deletions dist/ch.iife.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var Ch = (function (exports) {
return array !== null && array.constructor === Array;
}
function isAscii(code, extended) {
if (extended === void 0) { extended = true; }
if (isInteger(code)) {
return (extended && code >= 0 && code <= 255) || (code >= 0 && code <= 127);
}
Expand All @@ -52,8 +53,10 @@ var Ch = (function (exports) {
var int = parseInt(number, 10);
return typeCheck ? number === int : number == int;
}
function isFloat(number) {
return Number(number) === number && number % 1 !== 0;
function isFloat(number, typeCheck) {
if (typeCheck === void 0) { typeCheck = true; }
var moduloCheck = number % 1 !== 0;
return typeCheck ? Number(number) === number && moduloCheck : Number(number) == number && moduloCheck;
}
function isNumber(number) {
return isInteger(number) || isFloat(number);
Expand Down
2 changes: 1 addition & 1 deletion dist/ch.iife.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions dist/ch.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function isArray(array) {
return array !== null && array.constructor === Array;
}
function isAscii(code, extended) {
if (extended === void 0) { extended = true; }
if (isInteger(code)) {
return (extended && code >= 0 && code <= 255) || (code >= 0 && code <= 127);
}
Expand All @@ -49,8 +50,10 @@ function isInteger(number, typeCheck) {
var int = parseInt(number, 10);
return typeCheck ? number === int : number == int;
}
function isFloat(number) {
return Number(number) === number && number % 1 !== 0;
function isFloat(number, typeCheck) {
if (typeCheck === void 0) { typeCheck = true; }
var moduloCheck = number % 1 !== 0;
return typeCheck ? Number(number) === number && moduloCheck : Number(number) == number && moduloCheck;
}
function isNumber(number) {
return isInteger(number) || isFloat(number);
Expand Down
9 changes: 6 additions & 3 deletions src/ts/ch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function isArray(array: any): boolean {
return array !== null && array.constructor === Array;
}

function isAscii(code: any, extended: boolean): boolean {
function isAscii(code: any, extended: boolean = true): boolean {
if (isInteger(code)) {
return (extended && code >= 0 && code <= 255) || (code >= 0 && code <= 127);
}
Expand All @@ -45,8 +45,11 @@ function isInteger(number: any, typeCheck: boolean = true): boolean {
return typeCheck ? number === int : number == int;
}

function isFloat(number: any): boolean {
return Number(number) === number && number % 1 !== 0;
function isFloat(number: any, typeCheck: boolean = true): boolean {
const moduloCheck = number % 1 !== 0;
return typeCheck
? Number(number) === number && moduloCheck
: Number(number) == number && moduloCheck;
}

function isNumber(number: any): boolean {
Expand Down
55 changes: 29 additions & 26 deletions tests/coverage/clover.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<coverage generated="1565299483549" clover="3.2.0">
<project timestamp="1565299483549" name="All files">
<metrics statements="36" coveredstatements="36" conditionals="130" coveredconditionals="100" methods="18" coveredmethods="18" elements="184" coveredelements="154" complexity="0" loc="36" ncloc="36" packages="1" files="1" classes="1"/>
<coverage generated="1565380687233" clover="3.2.0">
<project timestamp="1565380687233" name="All files">
<metrics statements="39" coveredstatements="39" conditionals="138" coveredconditionals="108" methods="18" coveredmethods="18" elements="195" coveredelements="165" complexity="0" loc="39" ncloc="39" packages="1" files="1" classes="1"/>
<file name="ch.js" path="/Users/lcluber/Projects/github/Ch.js/dist/ch.js">
<metrics statements="36" coveredstatements="36" conditionals="130" coveredconditionals="100" methods="18" coveredmethods="18"/>
<metrics statements="39" coveredstatements="39" conditionals="138" coveredconditionals="108" methods="18" coveredmethods="18"/>
<line num="14" count="19" type="stmt"/>
<line num="17" count="19" type="cond" truecount="2" falsecount="0"/>
<line num="18" count="16" type="stmt"/>
Expand All @@ -18,28 +18,31 @@
<line num="36" count="19" type="cond" truecount="3" falsecount="0"/>
<line num="39" count="24" type="cond" truecount="2" falsecount="0"/>
<line num="42" count="30" type="cond" truecount="2" falsecount="0"/>
<line num="43" count="14" type="cond" truecount="5" falsecount="0"/>
<line num="45" count="16" type="stmt"/>
<line num="48" count="131" type="cond" truecount="2" falsecount="0"/>
<line num="49" count="131" type="stmt"/>
<line num="50" count="131" type="cond" truecount="2" falsecount="0"/>
<line num="53" count="47" type="cond" truecount="2" falsecount="0"/>
<line num="56" count="38" type="cond" truecount="2" falsecount="0"/>
<line num="59" count="38" type="stmt"/>
<line num="62" count="19" type="cond" truecount="2" falsecount="0"/>
<line num="63" count="16" type="cond" truecount="1" falsecount="1"/>
<line num="71" count="3" type="stmt"/>
<line num="74" count="21" type="cond" truecount="45" falsecount="28"/>
<line num="147" count="1" type="stmt"/>
<line num="149" count="20" type="stmt"/>
<line num="153" count="19" type="cond" truecount="2" falsecount="0"/>
<line num="154" count="16" type="cond" truecount="1" falsecount="1"/>
<line num="161" count="3" type="stmt"/>
<line num="164" count="19" type="cond" truecount="2" falsecount="0"/>
<line num="167" count="19" type="cond" truecount="4" falsecount="0"/>
<line num="170" count="19" type="cond" truecount="2" falsecount="0"/>
<line num="173" count="19" type="cond" truecount="4" falsecount="0"/>
<line num="176" count="19" type="cond" truecount="2" falsecount="0"/>
<line num="43" count="30" type="cond" truecount="2" falsecount="0"/>
<line num="44" count="14" type="cond" truecount="5" falsecount="0"/>
<line num="46" count="16" type="stmt"/>
<line num="49" count="135" type="cond" truecount="2" falsecount="0"/>
<line num="50" count="135" type="stmt"/>
<line num="51" count="135" type="cond" truecount="2" falsecount="0"/>
<line num="54" count="57" type="cond" truecount="2" falsecount="0"/>
<line num="55" count="57" type="stmt"/>
<line num="56" count="57" type="cond" truecount="6" falsecount="0"/>
<line num="59" count="38" type="cond" truecount="2" falsecount="0"/>
<line num="62" count="38" type="stmt"/>
<line num="65" count="19" type="cond" truecount="2" falsecount="0"/>
<line num="66" count="16" type="cond" truecount="1" falsecount="1"/>
<line num="74" count="3" type="stmt"/>
<line num="77" count="21" type="cond" truecount="45" falsecount="28"/>
<line num="150" count="1" type="stmt"/>
<line num="152" count="20" type="stmt"/>
<line num="156" count="19" type="cond" truecount="2" falsecount="0"/>
<line num="157" count="16" type="cond" truecount="1" falsecount="1"/>
<line num="164" count="3" type="stmt"/>
<line num="167" count="19" type="cond" truecount="2" falsecount="0"/>
<line num="170" count="19" type="cond" truecount="4" falsecount="0"/>
<line num="173" count="19" type="cond" truecount="2" falsecount="0"/>
<line num="176" count="19" type="cond" truecount="4" falsecount="0"/>
<line num="179" count="19" type="cond" truecount="2" falsecount="0"/>
</file>
</project>
</coverage>
2 changes: 1 addition & 1 deletion tests/coverage/coverage-final.json

Large diffs are not rendered by default.

33 changes: 21 additions & 12 deletions tests/coverage/lcov-report/ch.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ <h1>
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
<span class="quiet">Statements</span>
<span class='fraction'>37/37</span>
<span class='fraction'>42/42</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">76.92% </span>
<span class="strong">78.26% </span>
<span class="quiet">Branches</span>
<span class='fraction'>100/130</span>
<span class='fraction'>108/138</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
Expand All @@ -37,7 +37,7 @@ <h1>
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
<span class="quiet">Lines</span>
<span class='fraction'>36/36</span>
<span class='fraction'>39/39</span>
</div>
</div>
<p class="quiet">
Expand Down Expand Up @@ -224,7 +224,10 @@ <h1>
<a name='L176'></a><a href='#L176'>176</a>
<a name='L177'></a><a href='#L177'>177</a>
<a name='L178'></a><a href='#L178'>178</a>
<a name='L179'></a><a href='#L179'>179</a></td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
<a name='L179'></a><a href='#L179'>179</a>
<a name='L180'></a><a href='#L180'>180</a>
<a name='L181'></a><a href='#L181'>181</a>
<a name='L182'></a><a href='#L182'>182</a></td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
Expand Down Expand Up @@ -266,17 +269,20 @@ <h1>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">30x</span>
<span class="cline-any cline-yes">30x</span>
<span class="cline-any cline-yes">14x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">16x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">131x</span>
<span class="cline-any cline-yes">131x</span>
<span class="cline-any cline-yes">131x</span>
<span class="cline-any cline-yes">135x</span>
<span class="cline-any cline-yes">135x</span>
<span class="cline-any cline-yes">135x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">47x</span>
<span class="cline-any cline-yes">57x</span>
<span class="cline-any cline-yes">57x</span>
<span class="cline-any cline-yes">57x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">38x</span>
Expand Down Expand Up @@ -443,6 +449,7 @@ <h1>
return array !== null &amp;&amp; array.constructor === Array;
}
function isAscii(code, extended) {
if (extended === void 0) { extended = true; }
if (isInteger(code)) {
return (extended &amp;&amp; code &gt;= 0 &amp;&amp; code &lt;= 255) || (code &gt;= 0 &amp;&amp; code &lt;= 127);
}
Expand All @@ -453,8 +460,10 @@ <h1>
var int = parseInt(number, 10);
return typeCheck ? number === int : number == int;
}
function isFloat(number) {
return Number(number) === number &amp;&amp; number % 1 !== 0;
function isFloat(number, typeCheck) {
if (typeCheck === void 0) { typeCheck = true; }
var moduloCheck = number % 1 !== 0;
return typeCheck ? Number(number) === number &amp;&amp; moduloCheck : Number(number) == number &amp;&amp; moduloCheck;
}
function isNumber(number) {
return isInteger(number) || isFloat(number);
Expand Down Expand Up @@ -586,7 +595,7 @@ <h1>
</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 Thu Aug 08 2019 23:24:43 GMT+0200 (Central European Summer Time)
generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Fri Aug 09 2019 21:58:07 GMT+0200 (Central European Summer Time)
</div>
</div>
<script src="prettify.js"></script>
Expand Down
18 changes: 9 additions & 9 deletions tests/coverage/lcov-report/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ <h1>
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
<span class="quiet">Statements</span>
<span class='fraction'>37/37</span>
<span class='fraction'>42/42</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">76.92% </span>
<span class="strong">78.26% </span>
<span class="quiet">Branches</span>
<span class='fraction'>100/130</span>
<span class='fraction'>108/138</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
Expand All @@ -37,7 +37,7 @@ <h1>
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
<span class="quiet">Lines</span>
<span class='fraction'>36/36</span>
<span class='fraction'>39/39</span>
</div>
</div>
<p class="quiet">
Expand Down Expand Up @@ -65,13 +65,13 @@ <h1>
<td class="file high" data-value="ch.js"><a href="ch.js.html">ch.js</a></td>
<td data-value="100" class="pic high"><div class="chart"><div class="cover-fill cover-full" style="width: 100%;"></div><div class="cover-empty" style="width:0%;"></div></div></td>
<td data-value="100" class="pct high">100%</td>
<td data-value="37" class="abs high">37/37</td>
<td data-value="76.92" class="pct medium">76.92%</td>
<td data-value="130" class="abs medium">100/130</td>
<td data-value="42" class="abs high">42/42</td>
<td data-value="78.26" class="pct medium">78.26%</td>
<td data-value="138" class="abs medium">108/138</td>
<td data-value="100" class="pct high">100%</td>
<td data-value="18" class="abs high">18/18</td>
<td data-value="100" class="pct high">100%</td>
<td data-value="36" class="abs high">36/36</td>
<td data-value="39" class="abs high">39/39</td>
</tr>

</tbody>
Expand All @@ -80,7 +80,7 @@ <h1>
</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 Thu Aug 08 2019 23:24:43 GMT+0200 (Central European Summer Time)
generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Fri Aug 09 2019 21:58:07 GMT+0200 (Central European Summer Time)
</div>
</div>
<script src="prettify.js"></script>
Expand Down
Loading

0 comments on commit d4bbc2b

Please sign in to comment.