routie dev init since i didn't adhere to any proper guidance up until now
This commit is contained in:
+4
@@ -0,0 +1,4 @@
|
||||
import type { WidthOptions as Options } from 'fast-string-truncated-width';
|
||||
declare const fastStringWidth: (input: string, options?: Options) => number;
|
||||
export default fastStringWidth;
|
||||
export type { Options };
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
/* IMPORT */
|
||||
import fastStringTruncatedWidth from 'fast-string-truncated-width';
|
||||
/* HELPERS */
|
||||
const NO_TRUNCATION = {
|
||||
limit: Infinity,
|
||||
ellipsis: '',
|
||||
ellipsisWidth: 0,
|
||||
};
|
||||
/* MAIN */
|
||||
const fastStringWidth = (input, options = {}) => {
|
||||
return fastStringTruncatedWidth(input, NO_TRUNCATION, options).width;
|
||||
};
|
||||
/* EXPORT */
|
||||
export default fastStringWidth;
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2024-present Fabio Spampinato
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "fast-string-width",
|
||||
"repository": "github:fabiospampinato/fast-string-width",
|
||||
"description": "A fast function for calculating the visual width of a string once printed to the terminal.",
|
||||
"license": "MIT",
|
||||
"version": "1.1.0",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
"exports": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"scripts": {
|
||||
"clean": "tsex clean",
|
||||
"compile": "tsex compile",
|
||||
"compile:watch": "tsex compile --watch",
|
||||
"test": "tsex test",
|
||||
"test:watch": "tsex test --watch",
|
||||
"prepublishOnly": "tsex prepare"
|
||||
},
|
||||
"keywords": [
|
||||
"fast",
|
||||
"string",
|
||||
"width",
|
||||
"cli",
|
||||
"terminal"
|
||||
],
|
||||
"dependencies": {
|
||||
"fast-string-truncated-width": "^1.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"fava": "^0.3.4",
|
||||
"tsex": "^4.0.2",
|
||||
"typescript": "^5.7.3"
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
# Fast String Width
|
||||
|
||||
A fast function for calculating the visual width of a string once printed to the terminal.
|
||||
|
||||
See [`fast-string-truncated-width`](https://github.com/fabiospampinato/fast-string-truncated-width) for a lower-level version of this.
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
npm install fast-string-width
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```ts
|
||||
import fastStringWidth from 'fast-string-width';
|
||||
|
||||
// The width of various classes of characters is configurable
|
||||
|
||||
const options = {
|
||||
ansiWidth: 0,
|
||||
controlWidth: 0,
|
||||
tabWidth: 8,
|
||||
ambiguousWidth: 1,
|
||||
emojiWidth: 2,
|
||||
fullWidthWidth: 2,
|
||||
regularWidth: 1,
|
||||
wideWidth: 2
|
||||
};
|
||||
|
||||
// Calculating the visual width of some strings
|
||||
|
||||
fastStringWidth ( 'hello', options ); // => 5
|
||||
fastStringWidth ( '\x1b[31mhello', options ); // => 5
|
||||
fastStringWidth ( '👨👩👧👦', options ); // => 2
|
||||
fastStringWidth ( 'hello👨👩👧👦', options ); // => 7
|
||||
|
||||
// Calculating the visual width while tweaking the width of emojis
|
||||
|
||||
fastStringWidth ( '👶👶🏽', { ...options, emojiWidth: 1.5 } ); // => 3
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT © Fabio Spampinato
|
||||
Reference in New Issue
Block a user