Skip to content

Commit

Permalink
Atlas #2 - Adding "truncate" function to /shared/utils/String
Browse files Browse the repository at this point in the history
  • Loading branch information
dleadbetter committed Mar 18, 2024
1 parent cbfd799 commit e173be1
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/shared/src/utils/String.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,20 @@ const toString = (value: any) => {
return value || '';
};

const truncate = (str: string, length: number) => {
if (!str) {
return null;
}

if (!length || length > str.length) {
return str;
}

return str.substring(0, length).trim();
};

export default {
includes,
toString
toString,
truncate
};

0 comments on commit e173be1

Please sign in to comment.