Snapshot của nosir/cleave.js: 17.9k★ · JavaScript. Format input text content when you are typing...
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
Message: Kindly note that this library has been deprecated. If you are still interested in using Cleave, please explore the new version available at: cleave-zen.
And this is the message from author: https://github.com/nosir/cleave.js/issues/723
Cleave.js
Cleave.js has a simple purpose: to help you format input text content automatically.
Features
Credit card number formatting
Phone number formatting (i18n js lib separated for each country to reduce size)
Date formatting
Numeral formatting
Custom delimiter, prefix and blocks pattern
CommonJS / AMD mode
ReactJS component
AngularJS directive (1.x)
ES Module
TL;DR the demo page
Why?
The idea is to provide an easy way to increase input field readability by formatting your typed data. By using this library, you won't need to write any mind-blowing regular expressions or mask patterns to format input text.
However, this isn't meant to replace any validation or mask library, you should still sanitize and validate your data in backend.
Installation
npm
npm install --save cleave.js
CDN
cleave.js is available on jsDelivr and on cdnjs.com
cleave-phone.{country}.js addon is only required when phone shortcut mode is enabled. See more in documentation: phone lib addon section
Then have a text field
<input class="input-phone" type="text" />
Now in your JavaScript
var cleave = new Cleave('.input-phone', {
phone: true,
phoneRegionCode: '{country}',
})
.input-element here is a unique DOM element. If you want to apply Cleave for multiple elements, you need to give different CSS selectors and apply to each of them, effectively, you might want to create individual instance by a loop, e.g. loop solution
More examples: the demo page
CommonJS
var Cleave = require('cleave.js');
require('cleave.js/dist/addons/cleave-phone.{country}');
var cleave = new Cleave(...)
AMD
require(['cleave.js/dist/cleave.min', 'cleave.js/dist/addons/cleave-phone.{country}'], function (Cleave) {
var cleave = new Cleave(...)
});
ES Module
// Rollup, WebPack
import Cleave from 'cleave.js';
var cleave = new Cleave(...)
// Browser
import Cleave from 'node_modules/cleave.js/dist/cleave-esm.min.js';
var cleave = new Cleave(...)
TypeScript
Types are contributed by the community and are available via npm install --save-dev @types/cleave.js. Once installed, you can import Cleave like the following:
import Cleave = require('cleave.js')
Types for the React-component are also available and can be imported in the same way.
import Cleave = require('cleave.js/react')
ReactJS component usage
import React from 'react'
import ReactDOM from 'react-dom'
import Cleave from 'cleave.js/react'
Then in JSX:
class MyComponent extends React.Component {
constructor(props, context) {
super(props, context)
this.onCreditCardChange = this.onCreditCardChange.bind(this)
this.onCreditCardFocus = this.onCreditCardFocus.bind(this)
}
onCreditCardChange(event) {
// formatted pretty value
console.log(event.target.value)
// raw value
console.log(event.target.rawValue)
}
onCreditCardFocus(event) {
// update some state
}
render() {
return (
<Cleave
placeholder='Enter your credit card number'
options={{ creditCard: true }}
onFocus={this.onCreditCardFocus}
onChange={this.onCreditCardChange}
/>
)
}
}
As you can see, here you simply use <Cleave/> as a normal <input/> field
Attach HTML <input/> attributes
Pass in the custom options prop
Add ReactJS onChange event listener
Advanced usage:
How to pass default value
How to get ref of cleave instance and call methods
How to update raw value
How to get ref of the input field
How to use it with redux form
Usage for Webpack, Browserify and more in documentation: ReactJS component usage
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/nosir/cleave.js là nguồn chính thức.
nosir/cleave.js có bao nhiêu sao?
nosir/cleave.js có 17.9k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/nosir/cleave.js. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
nosir/cleave.js có phải mã nguồn mở không?
Có — nosir/cleave.js phát hành theo license Apache-2.0, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/nosir/cleave.js.
nosir/cleave.js còn đang phát triển không?
Commit gần nhất trên nosir/cleave.js là 2.7 năm trước (theo timestamp GitHub). Repo có 1.6k fork — một chỉ báo về mức độ quan tâm của cộng đồng.
nosir/cleave.js dùng license gì?
nosir/cleave.js phát hành theo license Apache-2.0. Nên mở file LICENSE trên GitHub để xác nhận — license metadata đôi khi lệch với thực tế dự án.
nosir/cleave.js là gì?
nosir/cleave.js (nosir/cleave.js) là dự án JavaScript trên GitHub. Theo mô tả gốc: Format input text content when you are typing...
nosir/cleave.js viết bằng ngôn ngữ gì?
nosir/cleave.js chủ yếu viết bằng JavaScript. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc đầy đủ README ở tab phía trên.
cleave.js có đáng để bạn bỏ thời gian?
ChatGPT, Claude và Perplexity đều đọc được trang này. Hỏi thử xem họ nghĩ gì về cleave.js.