@barusu/tool-sort-imports
sort import/export statement
Last updated 4 hours ago by lemonclown .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @barusu/tool-sort-imports 
SYNC missed versions from official npm registry.

npm version npm download npm license

Usage

  • Install

    yarn add --dev @barusu/tool-sort-imports
    
  • Usage

    npx sort-imports 'src/**/*.ts'
    

Options

Overview

$ sort-imports --help
Usage: sort-imports <cwd> [options]

Options:
  -V, --version                  output the version number
  --log-level <level>            specify logger's level.
  --log-name <name>              specify logger's name.
  --log-flag <option>            specify logger' option. [[no-]<date|colorful|inline>] (default: [])
  --log-output <filepath>        specify logger' output path.
  --log-encoding <encoding>      specify output file encoding.
  -P, --pattern <pattern>        glob pattern of source file (default: [])
  -e, --encoding <encoding>      encoding of source file
  --max-column <maxColumn>       maximum column width
  --indent <indent>              indent of source codes
  --quote <quote>                quotation marker surround the module path
  -h, --help                     display help for command

Details

  • --log-*: see cli-options | @barusu-logger

  • -e, --encoding <encoding>: Specify the encoding of the source files. Default value is utf-8

  • -p, --pattern <pattern>: Specify the glob pattern of source files, see patterns option | globby. Default value is empty array []

  • --max-column <maxColumn>: Specify the maximum column width, if the number of characters in one import/export statement exceeds this limit, line breaks will be performed. Default value is 1000

  • --indent <indent>: Specify indent of source codes. Default value is two spaces .

  • --quote <quote>: Specify the quotation marker surround the module path. Default value is single quotes '

Options in <cwd>/package.json

You can also specify options in the <cwd>/package.json, for example:

{
  "@barusu/tool-sort-imports": {
    "pattern": [
      "src/**/*.{ts,tsx}",
      "test/**/*.{ts,tsx}"
    ],
    "moduleRanks": [
      {
        "regex": "^(react|vue|angular)(?:[\/\\-][\\w\\-.\/]*)?$",
        "rank": 1.1
      },
      {
        "regex": "^mocha|chai(?:[\/][\\w\\-.\/]*)?$",
        "rank": 1.2
      },
      {
        "regex": "^[a-zA-Z\\d][\\w\\-.]*",
        "rank": 1.3
      },
      {
        "regex": "^@[a-zA-Z\\d][\\w\\-.]*\\/[a-zA-Z\\d][\\w\\-.]*",
        "rank": 1.4
      },
      {
        "regex": "^@\\/",
        "rank": 2.1
      },
      {
        "regex": "^(?:\\/|[a-zA-Z]:)",
        "rank": 3.1
      },
      {
        "regex": "^[.]{2}[\\/\\\\][^\\n]*",
        "rank": 3.2
      },
      {
        "regex": "^[.][\\/\\\\][^\\n]*",
        "rank": 3.3
      }
    ],
    "indent": "  ",
    "quote": "'",
    "maxColumn": 100
  }
}
  • moduleRanks specified module rank when sort import/export statements. If a module path matches multiple items, only the first matched item is taken.

Current Tags

  • 0.0.13                                ...           latest (4 hours ago)

9 Versions

  • 0.0.13                                ...           4 hours ago
  • 0.0.12                                ...           a month ago
  • 0.0.11                                ...           a month ago
  • 0.0.10                                ...           a month ago
  • 0.0.9                                ...           2 months ago
  • 0.0.8                                ...           2 months ago
  • 0.0.7                                ...           2 months ago
  • 0.0.6                                ...           2 months ago
  • 0.0.5                                ...           2 months ago
Maintainers (1)
Downloads
Today 0
This Week 7
This Month 7
Last Day 7
Last Week 8
Last Month 53
Dependencies (5)
Dev Dependencies (8)

Copyright 2014 - 2016 © taobao.org |