@trivago/prettier-plugin-sort-imports
Advanced tools
Comparing version 0.1.0 to 1.0.0
@@ -11,7 +11,7 @@ "use strict"; | ||
var isSimilarTextExistInArray = function (arr, text) { | ||
return arr.some(function (element) { return text.startsWith(element); }); | ||
return arr.some(function (element) { return text.match(new RegExp(element)) !== null; }); | ||
}; | ||
exports.getSortedNodesByImportOrder = function (nodes, order) { | ||
return order.reduce(function (res, val) { | ||
var x = nodes.filter(function (node) { return node.source.value.startsWith(val); }); | ||
var x = nodes.filter(function (node) { return node.source.value.match(new RegExp(val)) !== null; }); | ||
x.sort(function (a, b) { return javascript_natural_sort_1.default(a.source.value, b.source.value); }); | ||
@@ -18,0 +18,0 @@ return res.concat(x); |
{ | ||
"name": "@trivago/prettier-plugin-sort-imports", | ||
"version": "0.1.0", | ||
"description": "A prettier plugins to sort imports in provided order", | ||
"version": "1.0.0", | ||
"description": "A prettier plugins to sort imports in provided RegEx order", | ||
"main": "lib/src/index.js", | ||
@@ -6,0 +6,0 @@ "scripts": { |
# Prettier plugin sort imports | ||
A prettier plugin to sort import declarations by provided order. | ||
A prettier plugin to sort import declarations by provided RegEx order. | ||
@@ -10,3 +10,3 @@ #### Install | ||
```shell script | ||
npm install --dev @trivago/prettier-plugin-sort-imports | ||
npm install --save-dev @trivago/prettier-plugin-sort-imports | ||
``` | ||
@@ -32,6 +32,14 @@ | ||
"semi": true, | ||
"importOrder": ["@core","@server", "@ui", ".", "../"] | ||
"importOrder": ["^@core/(.*)$", "^@server/(.*)", "^@ui/(.*)$", "^[./]"], | ||
} | ||
``` | ||
#### API | ||
**importOrder**: A collection of regular expressions in string format. The plugin | ||
uses [`new RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) | ||
to evaluate RegEx. E.g. `node.source.value.match(new RegExp(val))` Here, `val` | ||
is the string provide in import order. | ||
#### How does import sort work ? | ||
@@ -50,5 +58,5 @@ | ||
##### Q. Should I add the full name of imports in the `importOrder` list ? | ||
You can define the starting part of the import in the `importOrder`. For | ||
example if you want to short the following imports: | ||
##### Q. Hoe can I add the RegEx imports in the `importOrder` list ? | ||
You can define the RegEx in the `importOrder`. For | ||
example if you want to sort the following imports: | ||
```ecmascript 6 | ||
@@ -63,4 +71,4 @@ import React from 'react'; | ||
``` | ||
then the `importOrder` would be `['@ui','@server', '.']`. Now, the final output | ||
would be as follows: | ||
then the `importOrder` would be `["^@ui/(.*)$","^@server/(.*)", '^[./]']`. | ||
Now, the final output would be as follows: | ||
@@ -67,0 +75,0 @@ ```ecmascript 6 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
20016
1
97