Skip to content

Commit

Permalink
BREAKING: change default exports to named ones
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed Apr 28, 2023
1 parent 7764eb5 commit 5c0805c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ fusv folder [, folder2...] --ignore "$my-var,$my-second-var" -e scss -e css --ig
## API

```js
import fusv from 'find-unused-sass-variables';
import { findAsync, find } from 'find-unused-sass-variables';

// 'directory' is a folder
const unused = fusv.find('directory');
const unused = find('directory');
// Array of unused variables
console.log(unused.unused);
// Array<{ name: string, line: string, file: string }>
Expand All @@ -48,7 +48,7 @@ console.log(unused.total);
```js
// Ignoring variables
const ignoredVars = ['$my-var', '$my-second-var'];
const unused = fusv.find('directory', { ignore: ignoredVars });
const unused = find('directory', { ignore: ignoredVars });
```

```js
Expand All @@ -59,15 +59,15 @@ const unused = fusv.find('directory', { ignoreFiles });

```js
// Specifying file extensions
const unused = fusv.find('directory', { fileExtensions: ['css','scss']});
const unused = find('directory', { fileExtensions: ['css','scss']});
```

```js
// Asynchronous usage
let unused = await fusv.findAsync('directory');
let unused = await findAsync('directory');

// or like a Promise
unused = fusv.findAsync('directory').then(result => {
unused = findAsync('directory').then(result => {
console.log(unused.unused);
});
```
Expand Down
4 changes: 2 additions & 2 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import process from 'node:process';
import path from 'node:path';
import { program } from 'commander';
import picocolors from 'picocolors';
import fusv from './index.js';
import { findAsync } from './index.js';

const { version } = JSON.parse(await fs.readFile(new URL('package.json', import.meta.url)));

Expand Down Expand Up @@ -43,7 +43,7 @@ async function main() {

const executeForPath = async(arg, options) => {
const dir = path.resolve(arg);
const unusedVars = await fusv.findAsync(dir, options);
const unusedVars = await findAsync(dir, options);
const unusedVarsNumber = unusedVars.unused.length;

console.log(`\nSearching for unused variables in "${picocolors.cyan(dir)}" folder, ${picocolors.cyan(options.fileExtensions.join(', '))} files...`);
Expand Down
13 changes: 6 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const defaultOptions = {
fileExtensions: ['scss']
};

const findUnusedVarsAsync = async(strDir, opts) => {
const findAsync = async(strDir, opts = {}) => {
const options = parseOptions(opts);
const dir = await sanitizeDirAsync(strDir);
// Array of all Sass files
Expand All @@ -29,7 +29,7 @@ const findUnusedVarsAsync = async(strDir, opts) => {
return makeResults(sassFilesString);
};

const findUnusedVarsSync = (strDir, opts) => {
const findSync = (strDir, opts = {}) => {
const options = parseOptions(opts);
const dir = sanitizeDirSync(strDir);
// Array of all Sass files
Expand Down Expand Up @@ -89,7 +89,7 @@ const filterVariables = (sassFilesString, variables) => {
};
};

const parseOptions = opts => {
const parseOptions = (opts = {}) => {
const options = { ...defaultOptions, ...opts };

if (Boolean(options.ignore) && !Array.isArray(options.ignore)) {
Expand Down Expand Up @@ -138,8 +138,7 @@ function checkDir(stat, dir) {
return dir;
}

/* eslint-disable-next-line import/no-anonymous-default-export */
export default {
findAsync: findUnusedVarsAsync,
find: findUnusedVarsSync
export {
findSync as find,
findAsync
};
6 changes: 3 additions & 3 deletions tests/integration.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node

import process from 'node:process';
import fusv from '../index.js';
import { find, findAsync } from '../index.js';

const expectedUnused = [
'$a',
Expand Down Expand Up @@ -31,7 +31,7 @@ const runTests = (type, result) => {
};

try {
const result = fusv.find('./tests/', { ignore, ignoreFiles });
const result = find('./tests/', { ignore, ignoreFiles });
runTests('sync', result);
} catch (error) {
console.error(error);
Expand All @@ -40,7 +40,7 @@ try {

(async() => {
try {
const result = await fusv.findAsync('./tests/', { ignore, ignoreFiles });
const result = await findAsync('./tests/', { ignore, ignoreFiles });
runTests('async', result);
} catch (error) {
console.error(error);
Expand Down
4 changes: 2 additions & 2 deletions tests/options.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node

import process from 'node:process';
import fusv from '../index.js';
import { findAsync } from '../index.js';

const allExpectedUnused = [
'$a',
Expand All @@ -26,7 +26,7 @@ const ignoreFiles = ['**/ignored-file*.scss'];
console.log('Running "Options" tests...');

const runTests = async(description, dir, options, expectedUnused) => {
const result = await fusv.findAsync(dir, options);
const result = await findAsync(dir, options);

try {
console.log(`Running, ${description}...`);
Expand Down

0 comments on commit 5c0805c

Please sign in to comment.