New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

age2

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

age2

🎂 Lightweight and documented age object for converting date of birth to age

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Quality Package Template

Light and fully documented Age object for TS and JS

Test Status Downloads last commit codecov GitHub age2 Known Vulnerabilities Quality npm license MIT Size

📦 Installation

  • Using npm
    npm i age2
    
  • Using Yarn
    yarn add age2
    
  • Using pnpm
    pnpm add age2
    

⚙️ Usage

How to import

  1. ES Modules
    import { Age } from "age2";
    
  2. Common JS
    const { Age } = require("age2");
    

How to construct

Age constructor is exactly the same as Date's Cause age is determined by underlying date.

Ways to construct

  1. Date string
    const age = new Age("1970-01-01 11:25:04");
    
  2. Milliseconds since 1st of jan. 1970
    const age = new Age(19504000);
    
  3. By passing a date object
    const age = new Age(new Date("1970-01-01 11:25:04"));
    
  4. By passing each date part separately
    const age = new Age(
      1970, // year
      0, // month (january)
      0, // Optional: day of the mons
      0, // Optional: hours
      0, // Optional: minutes
      0, // Optional: seconds
      0 // Optional: milliseconds
    );
    

Properties

  1. value
    console.log(age.value); // 52
    
  2. dateOfBirth
    console.log(age.dateOfBirth.toISOString()); // "1970-01-01T08:25:04.000Z"
    
  3. dayOfBirth
    console.log(age.dateOfBirth.toISOString()); // "1970-01-01T00:00:00.000Z"
    
  4. isBirthday(date?)
    console.log(age.isBirthday(/* default: now */)); // false
    console.log(age.isBirthday("2021-01-01")); // true
    console.log(age.isBirthday("2021-01-02")); // false
    

Serialization

Date object serializes as a number

console.log(age.value); // 52
console.log(age.valueOf); // 52
console.log(+age); // 52
console.log(String(age)); // 52
console.log(JSON.stringify(age)); // 52

Keywords

FAQs

Package last updated on 15 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc