Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rifm

Package Overview
Dependencies
Maintainers
2
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rifm

Tiny react input formatter and mask

  • 0.12.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
992K
increased by7.55%
Maintainers
2
Weekly downloads
 
Created

What is rifm?

The 'rifm' (React Input Format and Mask) package is a lightweight library for formatting and masking input fields in React applications. It provides a simple way to format user input in real-time, such as phone numbers, credit card numbers, dates, and more.

What are rifm's main functionalities?

Basic Formatting

This feature allows you to format input fields in real-time. The example shows how to format a phone number input.

import { Rifm } from 'rifm';

function App() {
  return (
    <Rifm
      value={value}
      onChange={setValue}
      format={(str) => str.replace(/\D+/g, '').replace(/(\d{3})(\d{3})(\d{4})/, '($1) $2-$3')}
    >
      {({ value, onChange }) => <input value={value} onChange={onChange} />}
    </Rifm>
  );
}

Custom Masking

This feature allows you to apply custom masks to input fields. The example shows how to format a credit card number input.

import { Rifm } from 'rifm';

function App() {
  return (
    <Rifm
      value={value}
      onChange={setValue}
      format={(str) => str.replace(/\D+/g, '').replace(/(\d{4})(\d{4})(\d{4})(\d{4})/, '$1 $2 $3 $4')}
    >
      {({ value, onChange }) => <input value={value} onChange={onChange} />}
    </Rifm>
  );
}

Date Formatting

This feature allows you to format date inputs. The example shows how to format a date input in MM/DD/YYYY format.

import { Rifm } from 'rifm';

function App() {
  return (
    <Rifm
      value={value}
      onChange={setValue}
      format={(str) => str.replace(/\D+/g, '').replace(/(\d{2})(\d{2})(\d{4})/, '$1/$2/$3')}
    >
      {({ value, onChange }) => <input value={value} onChange={onChange} />}
    </Rifm>
  );
}

Other packages similar to rifm

FAQs

Package last updated on 26 Nov 2021

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