cc-expiry
v1.0.0
Published
An NPM package for formatting credit card expiry dates in MM/YY or MM/YYYY formats.
Downloads
13
Readme
cc-expiry
An NPM package for formatting credit card expiry dates in MM/YY or MM/YYYY formats.
Usage
Import the lib:
//With ES6-style imports
import {format} from "cc-expiry";
// With node-style requires:
var format = require("cc-expiry").format;
format(expiry: string, customSeparator?: string, fourDigitYear?: boolean)
console.log(format("12 / 3456")); // '12 / 34'
console.log(format("12 / 345")); // '12 / 34'
console.log(format("12 / 34")); // '12 / 34'
console.log(format("12/34")); // '12 / 34'
console.log(format("1234")); // '12 / 34'
console.log(format("123")); // '12 / 3'
console.log(format("12")); // '12'
console.log(format("1")); // '1'
With a custom separator:
console.log(format("12 / 345", "🍎")); // '12🍎34'
console.log(format("12 / 34", "🍎")); // '12🍎34'
console.log(format("12/34", "🍎")); // '12🍎34'
console.log(format("1234", "🍎")); // '12🍎34'
console.log(format("123", "🍎")); // '12🍎3'
console.log(format("12", "🍎")); // '12'
console.log(format("1", "🍎")); // '1'
With a 4-digit year (MM / YYYY)
console.log(format("12 / 3456", "/", true)); // '12/3456'
console.log(format("12 / 345", "/", true)); // '12/345'
console.log(format("12 / 34", "/", true)); // '12/34'
console.log(format("12/34", "/", true)); // '12/34'
console.log(format("1234", "/", true)); // '12/34'
console.log(format("123", "/", true)); // '12/3'
console.log(format("12", "/", true)); // '12'
console.log(format("1", "/", true)); // '1'