Gathering detailed insights and metrics for react-easy-linkify
Gathering detailed insights and metrics for react-easy-linkify
Gathering detailed insights and metrics for react-easy-linkify
Gathering detailed insights and metrics for react-easy-linkify
npm install react-easy-linkify
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
4 Stars
11 Commits
2 Watching
1 Branches
1 Contributors
Updated on 21 Feb 2022
JavaScript (57.5%)
TypeScript (37.65%)
HTML (4.05%)
CSS (0.8%)
Cumulative downloads
Total Downloads
Last day
-16.1%
26
Compared to previous day
Last week
4.8%
238
Compared to previous week
Last month
-1.6%
973
Compared to previous month
Last year
7.8%
17,092
Compared to previous year
React Easy Linkify is a Component of React for finding URL/mentions/hashtags and converting them to Links.
This package is based on Linkifyjs. I rewrote its scanner
, React Component, and Plugin Module, make them more flexible.
Very importantly, I made it be supported i18n. You can customize extended characters.
NPM
1npm i react-easy-linkify
Or Yarn
1yarn add react-easy-linkify
Import the Linkify
component from react-easy-linkify
, and just use it to wrap your elements.
1import React from 'react'; 2import './App.css'; 3import { Linkify } from 'react-easy-linkify'; 4 5const App: React.FC = () => { 6 return ( 7 <div className="App"> 8 <Linkify> 9 google.com 10 https://google.com 11 https://google.com/search?q=helloä½ å¥½ 12 </Linkify> 13 </div> 14 ); 15} 16 17export default App;
1const App: React.FC = () => { 2 return ( 3 <div className="App"> 4 <Linkify options={{ className: 'test' }}> 5 google.com 6 https://google.com 7 https://google.com/search?q=helloä½ å¥½ 8 </Linkify> 9 </div> 10 ); 11}
The options extend from Linkifyjs
's options, currently, they all work properly.
You can check them at Linkifyjs Options.
The following mainly introduces the newly added and important option items in this library.
formatHref
Type: formatHref?: ((href: string, type: LinkEntityType) => string) | Partial<Record<LinkEntityType, (href: string) => string>> | null;
This is useful when finding hashtags and mentions. By formatHref
, You can change the default href
of <a>
.
Useage:
1<Linkify 2 options={{ 3 formatHref: { 4 mention: (href) => '/user' + href, 5 hashtag: (href) => '/tag' + href.substring(1), 6 } 7 }} 8></Linkfiy>
The LinkEntityType
type has values of url
, email
, hashtag
, and mention
.
format
Type: format?: ((value: string, type: LinkEntityType) => string) | Partial<Record<LinkEntityType, (value: string) => string>> | null;
Like formatHref
, Format the text displayed. e.g... cutoff a long URL.
1<Linkify 2 options={{ 3 format: { 4 url: (value) => value.substr(0, 20), 5 } 6 }} 7></Linkfiy>
linkWrapper
When you need to customize the elements of the link, or You want to add some element in the link's parent. It's very useful.
Option's attributes
, className
is all of HTML element's attribute, not React node's props.
By this param, It can replace most other params (e.g... attributes
, className
, target
), And make it programable.
Type
1type LinkWrapperType<EXTRA> = React.FC<{ 2 options: IOptionsData<EXTRA>; 3 key: string; 4 href: string; 5 className?: string; 6 target?: string; 7 type: LinkEntityType; 8 [key: string]: any; 9}>; 10 11linkWrapper?: LinkWrapperType<EXTRA> | Partial<Record<LinkEntityType, LinkWrapperType<EXTRA>>>;
Useage:
1const App: React.FC = () => { 2 return ( 3 <div className="App"> 4 <Linkify options={{ 5 className: 'test', 6 linkWrapper: (props) => ( 7 <div className='wrapper'> 8 <a {...props}>{props.children}</a> 9 </div> 10 ), 11 }} 12 > 13 google.com 14 https://google.com 15 https://google.com/search?q=helloä½ å¥½ 16 </Linkify> 17 </div> 18 ); 19}
Or setting of a specific type:
1const App: React.FC = () => { 2 return ( 3 <div className="App"> 4 <Linkify options={{ 5 linkWrapper: { 6 mention: (props) => ( 7 <div className='wrapper'> 8 <a {...props}>{props.children}</a> 9 </div> 10 ) 11 }, 12 }} 13 > 14 </Linkify> 15 </div> 16 ); 17}
The package build-in three plugins:
@
)#
)&
)You can find and enable them by LinkifyCore.PluginManager
.
If you want to change them, LinkifyCore.PluginManager
provided the original objects of them.
To enable the Mention plugin, you just should call LinkifyCore.PluginManager.enableMention()
.
1import React from 'react'; 2import './App.css'; 3import { Linkify, LinkifyCore } from 'react-easy-linkify'; 4 5LinkifyCore.PluginManager.enableMention(); 6 7const App: React.FC = () => { 8 return ( 9 <div className="App"> 10 <Linkify> 11 @hello @username1 @123hello 12 </Linkify> 13 </div> 14 ); 15} 16 17export default App;
Like the mention plugin:
1import React from 'react'; 2import './App.css'; 3import { Linkify, LinkifyCore } from 'react-easy-linkify'; 4 5LinkifyCore.PluginManager.enableHashtag(); 6 7const App: React.FC = () => { 8 return ( 9 <div className="App"> 10 <Linkify> 11 #hello #username1 #123hello 12 </Linkify> 13 </div> 14 ); 15} 16 17export default App;
The ticket only includes numbers, it's away used in issue or work order.
Tips In the Linkifyjs
, the Ticket was started with #
. But when it exists with hashtag
and i18n
, sometimes has been mistakes.
So I fixed it. In this package, the Ticket was starting with &
;
1import React from 'react'; 2import './App.css'; 3import { Linkify, LinkifyCore } from 'react-easy-linkify'; 4 5LinkifyCore.PluginManager.enableTicket(); 6 7const App: React.FC = () => { 8 return ( 9 <div className="App"> 10 <Linkify> 11 #hello #username1 #123hello 12 </Linkify> 13 </div> 14 ); 15} 16 17export default App;
The i18n is only needed for Mention and Hashtag. It's not necessary for i18n. If you don't use Mention or Hashtag, maybe you also don't need i18n.
Firstly, You should find the RegExp of the charset of your language or any you're needed.
Then you can call the method of LinkifyCore.addCharsSupport
to support the language you need.
1LinkifyCore.addCharsSupport(/[\u2E80-\u9FFF]/);
The linkify
's core is an FSM(finite-state machine), It's work through action and state transfer.
In the original package, it only exported the entry point of the state machine.
So, it's so difficult to modify somethings. But now, in this package, I export many important variables from scanner
, and rewrite the plugin module.
You can read the code of this library, I will supplement this part of the document as soon as possible.
TODO
TODO
MIT
PR and issue are welcome.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/11 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
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
89 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