npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

femtofiber

v0.0.1

Published

A lightweight immutable date library.

Downloads

4

Readme

femtofiber

femtofiber is immutable date library for JavaScript.

How to install

Without Node.js(for browsers)

Download a zip file from GitHub release page, and unzip it. Then you can see femtofiber.min.js in build directory. Copy femtofiber.min.js file to your project directory.

Import the file in your HTML as following:

<script src="femtofiber.min.js"></script>
<script>
  // Write your code here!
</script>

With Node.js(for server)

Run npm install.

npm install femtofiber --save 

And import it.

import { Femto, Duration } from 'femtofiber';

Basic Usage

Creating Femto

You can create a Femto object in several ways.

const femto1 = new Femto(2018, 6, 22);                  // from numbers
const femto2 = new Femto(2018, 6, 22, 21, 54, 31, 500); // from numbers with time
const femto3 = Femto.fromDate(new Date());              // from Date
const femto4 = Femto.now();                             // from current date
const femto5 = Femto.fromEpochTime(1529590253022);      // from epoch time

A Femto object is immutable, so once created, its value does not change.

Properties

To get values, use properties.

const femto = Femto.now();
console.log(femto.year);
console.log(femto.month); // January is 1, and December is 12
console.log(femto.day);
console.log(femto.hour);
console.log(femto.minute);
console.log(femto.second);
console.log(femto.millisecond);

Formatting string

A Femto object also can output formatted string.

const femto = Femto.now();
console.log(femto.toFormatString('YYYY/MM/DD'));   // "2018/06/22"
console.log(femto.toFormatString('HH:mm:ss:SSS')); // "18:23:27:758"

Calculation

A Femto object has manipulating methods. You can manipulate date with Duration objects.

const tomorrow = Femto.now().add(new Duration({days: 1}));
const yesterday = Femto.now().sub(new Duration({days: 1}));

To create a Duration object, pass values to Duration's constructor.

const duration = new Duration({
  days: 4,
  hours: 7,
  minutes: 13,
  seconds: 6,
  milliseconds: 219
});

Comparison

You can also compare two Femtos.

const current = 1529665309363;
const femto1 = Femto.fromEpochTime(current);
const femto2 = Femto.fromEpochTime(current);

// These methods return boolean.
femto1.isSame(femto2);
femto1.isBefore(femto2);
femto1.isAfter(femto2);
femto1.isSameOrBefore(femto2);
femto1.isSameOrAfter(femto2);

Femto.now().isBetween(femto1, femto2);
Femto.now().isBetween(femto1, femto2, {
  includesFrom: true,
  includesTo: true
});

API document

For more information, see API Document.

License

MIT License. See LICENSE.md.