Gathering detailed insights and metrics for rifm
Gathering detailed insights and metrics for rifm
Gathering detailed insights and metrics for rifm
Gathering detailed insights and metrics for rifm
React Input Format & Mask, tiny (≈800b) component to transform any input component into formatted or masked input. Supports number, date, phone, currency, credit card, etc
npm install rifm
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
1,304 Stars
152 Commits
44 Forks
13 Watching
21 Branches
9 Contributors
Updated on 27 Nov 2024
JavaScript (99.03%)
TypeScript (0.97%)
Cumulative downloads
Total Downloads
Last day
-2.5%
210,692
Compared to previous day
Last week
4.9%
1,052,921
Compared to previous week
Last month
9.2%
4,467,639
Compared to previous month
Last year
-23.8%
55,755,255
Compared to previous year
1
37
Is a tiny (≈ 800b) component (and hook) to transform any input component into formatted or masked input.
Rifm offers both a Render Prop and a Hook API:
1import { Rifm } from 'rifm'; 2import { TextField } from '@material-ui/core'; 3 4const numberFormat = (str: string) => { 5 const r = parseInt(str.replace(/[^\d]+/gi, ''), 10); 6 return r ? r.toLocaleString('en') : ''; 7} 8 9... 10 11 const [value, setValue] = React.useState('') 12 13 <Rifm 14 value={value} 15 onChange={setValue} 16 format={numberFormat} 17 > 18 {({ value, onChange }) => ( 19 <TextField 20 type="tel" 21 value={value} 22 onChange={onChange} 23 /> 24 )} 25 </Rifm> 26 27...
1import { useRifm } from 'rifm'; 2import { TextField } from '@material-ui/core'; 3 4const numberFormat = (str: string) => { 5 const r = parseInt(str.replace(/[^\d]+/gi, ''), 10); 6 return r ? r.toLocaleString('en') : ''; 7} 8 9... 10 11 const [value, setValue] = React.useState('') 12 13 const rifm = useRifm({ 14 value, 15 onChange: setValue, 16 format: numberFormat 17 }) 18 19 <TextField 20 type="tel" 21 value={rifm.value} 22 onChange={rifm.onChange} 23 /> 24 25...
1yarn add rifm
Rifm is based on simple idea (*):
* This is not always true, but we solve some edge cases where it's not.
Imagine you have simple integer number formatter with ` as thousands separator and current input state is 123`4|67 ("|" shows current cursor position).
User press 5 then formatted input must be equal to 1`234`5|67.
The overall order of elements has changed (was 1->2->3->`->4->... became 1->`->2->3->4...) but the order of digits before cursor hasn't changed (was 1->2->3->4 and hasn't changed).
The same is true for float numbers formatting, dates and more. Symbols with preserved order are different and depends on format. We call this kind of symbols - "accepted" symbols.
Rifm solves only one task - find the right place for cursor after formatting.
Knowledge about what symbols are "accepted" and cursor position after any user action is enough to find the final cursor position.
Most operations which are not covered with above idea like case enforcements, masks guides, floating point ","=>"." replacement can be done using simple postprocessing step - replace. This operation works well if you need to change input value without loosing cursor position.
And finaly masks - masks are usually is format with replace editing mode + some small cursor visual hacks.
These are accepted by the Rifm component as props and the useRifm hook as named arguments.
Prop | type | default | Description |
---|---|---|---|
accept | RegExp (optional) | /\d/g | Regular expression to detect "accepted" symbols |
format | string => string | format function | |
value | string | input value | |
onChange | string => void | event fired on input change | |
children | ({ value, onChange }) => Node | value and onChange handler you need to pass to underlying input element | |
mask | boolean (optional) | use replace input mode if true, use cursor visual hacks if prop provided | |
replace | string => string (optional) | format postprocessor allows you to fully replace any/all symbol/s preserving cursor | |
append | string => string (optional) | format postprocessor called only if cursor is in the last position and new symbols added, used for specific use-case to add non accepted symbol when you type |
These will be passed into the children
render prop for the Rifm component as named arguments, and returned from the useRifm hook as an object.
Prop | type | default | Description |
---|---|---|---|
value | string | A formatted string value to pass as a prop to your input element | |
onChange | SyntheticEvent => void | The change handler to pass as a prop to your input element |
See the Demo there are a lot of examples there.
@TrySound for incredible help and support on this
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 10/29 approved changesets -- score normalized to 3
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
79 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More