Socket
Socket
Sign inDemoInstall

@trivago/prettier-plugin-sort-imports

Package Overview
Dependencies
Maintainers
3
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@trivago/prettier-plugin-sort-imports - npm Package Compare versions

Comparing version 0.1.0 to 1.0.0

4

lib/src/utils.js

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc