Package Exports
- @ricardojrmcom/use-string-truncate
- @ricardojrmcom/use-string-truncate/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@ricardojrmcom/use-string-truncate) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
🌘 @ricardojrmcom/use-string-truncate
Truncate strings with React
Install
npm install @ricardojrmcom/use-string-truncate
yarn add @ricardojrmcom/use-string-truncateUsage
import { useStringTruncate } from '@ricardojrmcom/use-string-truncate';
/**
* Truncates string to fit within given length with appended ellipsis. Option to keep last word.
*/
export const TruncateString = ({
str,
length,
keepLastWord,
}: TruncateStringProps) => (
<span>
{useStringTruncate(str, length, keepLastWord)}
</span>
);
<TruncateString str="Lorem ipsum dolor sit amet" length={20} />
-> <span>Lorem ipsum dolor...</span>
<TruncateString str="Lorem ipsum dolor sit amet" length={20} keepLastWord />
-> <span>Lorem ipsum ... amet</span>
/**
* Exported TruncateString props
*/
export interface TruncateStringProps {
/**
* String to transform
*/
str: string;
/**
* Total length of the result
*/
length: number;
/**
* Option to keep last word in
*/
keepLastWord?: boolean;
}License
MIT © Ricardo <l1b3r_-> Mota (@ricardojrmcom)
Bootstrapped with 🟣@ricardojrmcom/supernova