├── .github
├── FUNDING.yml
└── workflows
│ └── node.js.yml
├── .gitignore
├── .prettierrc
├── CHANGELOG.md
├── LICENSE
├── README.md
├── index.d.ts
├── index.js
├── package-lock.json
├── package.json
└── test
└── index.js
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: knownasilya
4 |
--------------------------------------------------------------------------------
/.github/workflows/node.js.yml:
--------------------------------------------------------------------------------
1 | # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3 |
4 | name: Node.js CI
5 |
6 | on:
7 | push:
8 | branches: [master]
9 | pull_request:
10 | branches: [master]
11 |
12 | jobs:
13 | build:
14 | runs-on: ubuntu-latest
15 |
16 | strategy:
17 | matrix:
18 | node-version: [12.x, 14.x, 16.x, 18.x, 20.x]
19 | # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
20 |
21 | steps:
22 | - uses: actions/checkout@v3
23 | - name: Use Node.js ${{ matrix.node-version }}
24 | uses: actions/setup-node@v3
25 | with:
26 | node-version: ${{ matrix.node-version }}
27 | cache: 'npm'
28 | - run: npm ci
29 | - run: npm run build --if-present
30 | - run: npm test
31 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | coverage
3 | *.log
4 | *.swp
5 | .DS_Store
6 | .nyc_output
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "singleQuote": true
3 | }
4 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4 |
5 | ## [4.1.0](https://github.com/knownasilya/cli-width/compare/v4.0.0...v4.1.0) (2023-08-05)
6 |
7 |
8 | ### Features
9 |
10 | * ts types and test against node 18 and 20 ([bc2884f](https://github.com/knownasilya/cli-width/commit/bc2884f5346f5465715327970ebca1bfa4bfe807))
11 |
12 | ## [4.0.0](https://github.com/knownasilya/cli-width/compare/v3.0.0...v4.0.0) (2022-03-29)
13 |
14 |
15 | ### ⚠ BREAKING CHANGES
16 |
17 | * drop support for node < 12
18 |
19 | ### Bug Fixes
20 |
21 | * drop support for node < 12 ([50fcd88](https://github.com/knownasilya/cli-width/commit/50fcd8850eb62465b5e1a06df9d5a9a07b6c965c))
22 |
23 | ## [3.0.0](https://github.com/knownasilya/cli-width/compare/v2.2.1...v3.0.0) (2020-04-14)
24 |
25 |
26 | ### ⚠ BREAKING CHANGES
27 |
28 | * Dropped support for node < 10
29 | * Dropped support for IOjs
30 |
31 | ### Bug Fixes
32 |
33 | * drop node < 10 ([e42f6a7](https://github.com/knownasilya/cli-width/commit/e42f6a756ea47f85f736e6de2d7364d4d60a7dfe))
34 |
35 | ### [2.2.1](https://github.com/knownasilya/cli-width/compare/v2.2.0...v2.2.1) (2020-04-14)
36 |
37 |
38 | ### Bug Fixes
39 |
40 | * add more node versions to travis ([f7bc148](https://github.com/knownasilya/cli-width/commit/f7bc14846c2547769681bfc56afed3d0b04aa11e))
41 | * Reduce nesting in index.js and add package-lock.json ([#14](https://github.com/knownasilya/cli-width/issues/14)) ([92d8d6b](https://github.com/knownasilya/cli-width/commit/92d8d6b8e4ce3702b12356c5427723005fccf9b8))
42 | * update deprecated deps and change coverage script ([db06065](https://github.com/knownasilya/cli-width/commit/db0606592f8347eb9f35abdf87c570e1d731463c))
43 |
44 |
45 | # [2.2.0](https://github.com/knownasilya/cli-width/compare/v2.1.1...v2.2.0) (2017-08-22)
46 |
47 |
48 | ### Features
49 |
50 | * return default if env is 0 ([1833baf](https://github.com/knownasilya/cli-width/commit/1833baf)), closes [#9](https://github.com/knownasilya/cli-width/issues/9)
51 |
52 |
53 |
54 |
55 | ## [2.1.1](https://github.com/knownasilya/cli-width/compare/v2.1.0...v2.1.1) (2017-08-22)
56 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2015, Ilya Radchenko
2 |
3 | Permission to use, copy, modify, and/or distribute this software for any
4 | purpose with or without fee is hereby granted, provided that the above
5 | copyright notice and this permission notice appear in all copies.
6 |
7 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # cli-width
2 |
3 | Get stdout window width, with four fallbacks, `tty`, `output.columns`, a custom environment variable and then a default.
4 |
5 | [](http://badge.fury.io/js/cli-width)
6 | [](https://coveralls.io/github/knownasilya/cli-width?branch=master)
7 |
8 | Tested against Node v12 to v20.
9 | Includes TypeScript types.
10 |
11 | ## Usage
12 |
13 | ```
14 | npm install --save cli-width
15 | ```
16 |
17 | ```js
18 | const cliWidth = require('cli-width');
19 |
20 | cliWidth(); // maybe 204 :)
21 | ```
22 |
23 | You can also set the `CLI_WIDTH` environment variable.
24 |
25 | If none of the methods are supported, and the environment variable isn't set,
26 | the default width value is going to be `0`, that can be changed using the configurable `options`.
27 |
28 | ## API
29 |
30 | ### cliWidth([options])
31 |
32 | `cliWidth` can be configured using an `options` parameter, the possible properties are:
33 |
34 | - **defaultWidth**\ Defines a default value to be used if none of the methods are available, defaults to `0`
35 | - **output**\