Skip to content

Commit

Permalink
Revert "fix stringWidth"
Browse files Browse the repository at this point in the history
This reverts commit 2bafe7c.
  • Loading branch information
shimotmk committed Aug 4, 2022
2 parents f1894ac + 2f7e2cd commit 58c70c5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 99 deletions.
93 changes: 5 additions & 88 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@
"snapshot-diff": "0.8.1",
"source-map-loader": "3.0.0",
"sprintf-js": "1.1.1",
"string-width": "5.1.2",
"style-loader": "3.2.1",
"terser-webpack-plugin": "5.1.4",
"typescript": "4.4.2",
Expand Down
11 changes: 1 addition & 10 deletions packages/components/src/truncate/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* External dependencies
*/
import { isNil } from 'lodash';
// eslint-disable-next-line import/no-extraneous-dependencies
import stringWidth from 'string-width';

export const TRUNCATE_ELLIPSIS = '…';
export const TRUNCATE_TYPE = {
Expand Down Expand Up @@ -34,16 +32,9 @@ export function truncateMiddle( word, headLength, tailLength, ellipsis ) {
return '';
}
const wordLength = word.length;
// Calculate the average character width per character.
const splitWord = word.split( `` );
let total = 0;
for ( let i = 0; i < splitWord.length; i++ ) {
total += stringWidth( splitWord[ i ] );
}
const average = total / splitWord.length;
// Setting default values
// eslint-disable-next-line no-bitwise
const frontLength = ~~headLength / average; // Will cast to integer
const frontLength = ~~headLength; // Will cast to integer
// eslint-disable-next-line no-bitwise
const backLength = ~~tailLength;
/* istanbul ignore next */
Expand Down

0 comments on commit 58c70c5

Please sign in to comment.