zs-control
Version:
State management inspired by Zustand with strong TypeScript typing.
31 lines (30 loc) • 1.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.clock = exports.day = void 0;
const day = () => {
const date = new Date();
const format = (formatString) => {
const year = date.getFullYear().toString();
const month = (date.getMonth() + 1).toString().padStart(2, "0");
const day = date.getDate().toString().padStart(2, "0");
const hours = date.getHours().toString().padStart(2, "0");
const minutes = date.getMinutes().toString().padStart(2, "0");
const seconds = date.getSeconds().toString().padStart(2, "0");
return formatString
.replace(/Y/g, year)
.replace(/m/g, month)
.replace(/d/g, day)
.replace(/H/g, hours)
.replace(/i/g, minutes)
.replace(/s/g, seconds);
};
return { format };
};
exports.day = day;
const clock = (format) => {
const timerId = setInterval(() => {
(0, exports.day)().format(format);
}, 1000);
return timerId;
};
exports.clock = clock;