https://github.com/nozzlegear/cc-expiry
An NPM package for formatting credit card expiry dates in MM/YY or MM/YYYY formats.
https://github.com/nozzlegear/cc-expiry
Last synced: about 2 months ago
JSON representation
An NPM package for formatting credit card expiry dates in MM/YY or MM/YYYY formats.
- Host: GitHub
- URL: https://github.com/nozzlegear/cc-expiry
- Owner: nozzlegear
- License: mit
- Created: 2016-04-29T16:29:10.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-04-29T20:07:23.000Z (over 9 years ago)
- Last Synced: 2025-08-09T02:56:55.663Z (2 months ago)
- Language: TypeScript
- Size: 11.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cc-expiry
An NPM package for formatting credit card expiry dates in MM/YY or MM/YYYY formats.## Usage
Install the package from [NPM](https://npmjs.com/packages/cc-expiry):
```bash
npm install cc-expiry --save
```Import the lib:
```js
//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)
```js
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:
```js
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):
```js
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'
```