mirror of
https://github.com/bigskysoftware/htmx.git
synced 2025-10-02 15:25:26 +00:00
Updating ParseInterval
- add tests - try replacement function
This commit is contained in:
parent
20436f243c
commit
354be034d2
18
src/htmx.js
18
src/htmx.js
@ -62,7 +62,7 @@ return (function () {
|
||||
//====================================================================
|
||||
// Utilities
|
||||
//====================================================================
|
||||
function parseInterval(str) {
|
||||
/*function parseInterval(str) {
|
||||
if (str == null || str === "null" || str === "false" || str === "") {
|
||||
return null;
|
||||
} else if (str.lastIndexOf("ms") === str.length - 2) {
|
||||
@ -72,7 +72,21 @@ return (function () {
|
||||
} else {
|
||||
return parseFloat(str);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
function parseInterval(str) {
|
||||
|
||||
if (str == undefined) {
|
||||
return undefined
|
||||
}
|
||||
if (str.slice(-2) == "ms") {
|
||||
return parseFloat(str.slice(0,-2)) || undefined
|
||||
}
|
||||
if (str.slice(-1) == "s") {
|
||||
return (parseFloat(str.slice(0,-1)) * 1000) || undefined
|
||||
}
|
||||
return parseFloat(str) || undefined
|
||||
}
|
||||
|
||||
function getRawAttribute(elt, name) {
|
||||
return elt.getAttribute && elt.getAttribute(name);
|
||||
|
@ -1,3 +1,5 @@
|
||||
const { should } = require("chai");
|
||||
|
||||
describe("Core htmx internals Tests", function() {
|
||||
|
||||
it("makeFragment works with janky stuff", function(){
|
||||
@ -20,4 +22,18 @@ describe("Core htmx internals Tests", function() {
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest
|
||||
})
|
||||
|
||||
it("handles parseInterval correctly", function() {
|
||||
htmx._("parseInterval")("1ms").should.equal(1);
|
||||
htmx._("parseInterval")("300ms").should.equal(300);
|
||||
htmx._("parseInterval")("1s").should.equal(1000)
|
||||
htmx._("parseInterval")("1.5s").should.equal(1500)
|
||||
htmx._("parseInterval")("2s").should.equal(2000)
|
||||
|
||||
/* should(htmx.parseInterval(null)).be.undefined
|
||||
should(htmx.parseInterval("")).be.undefined
|
||||
should(htmx.parseInterval("false")).be.undefined
|
||||
should(htmx.parseInterval("true")).be.undefined
|
||||
*/
|
||||
})
|
||||
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user