I now know about toArray() but I got caught out today when iterate() didn't return an iterable suitable for Array.from()
@home:~/src$ cat test.js
const moment = require("moment")
const twix = require("./lib/twix.min.js")
let start = new Date("2018-01-01");
let end = new Date("2018-06-01");
console.log(moment(start).twix(end).toArray("days").length);
console.log(Array.from(moment(start).twix(end).iterate("days")).length);
console.log(Array.from(moment(start).twix(end).iterate("days")));
Yeah, the iterable does not actually implement the Iterable protocol (and predates its implementation, IIRC). It could though! I'd take a PR making that true.
Hey,
I now know about toArray() but I got caught out today when iterate() didn't return an iterable suitable for Array.from()
Array.from() should expand the iterable:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from
so I guess the object returned from iterate is not truly 'iterable' in the way required by the spec.
Nice library though.. saved me a bunch of time elsewhere so I'm still net positive on time-savings thanks to twix. :-)