@axah/js-utils
Advanced tools
Comparing version
@@ -1,2 +0,2 @@ | ||
export declare const getAge: (dateString: string, today?: Date) => number; | ||
export declare const getAge: (birthDate: string | Date, today?: Date) => number; | ||
export declare function isChild(age: number): boolean; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isChild = exports.getAge = void 0; | ||
const getAge = (dateString, today = new Date()) => { | ||
const birthDate = new Date(dateString); | ||
let age = today.getFullYear() - birthDate.getFullYear(); | ||
const month = today.getMonth() - birthDate.getMonth(); | ||
if (month < 0 || (month === 0 && today.getDate() < birthDate.getDate())) { | ||
const getAge = (birthDate, today = new Date()) => { | ||
let birthDateToUse; | ||
if (typeof birthDate === 'string') { | ||
birthDateToUse = new Date(birthDate); | ||
} | ||
else { | ||
birthDateToUse = birthDate; | ||
} | ||
let age = today.getFullYear() - birthDateToUse.getFullYear(); | ||
const month = today.getMonth() - birthDateToUse.getMonth(); | ||
if (month < 0 || (month === 0 && today.getDate() < birthDateToUse.getDate())) { | ||
age -= 1; | ||
@@ -10,0 +16,0 @@ } |
{ | ||
"name": "@axah/js-utils", | ||
"version": "1.8.2", | ||
"version": "1.8.3", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is not supported yet
61664
0.42%867
0.7%