Skip to content

Commit

Permalink
chore: refactors library into typscript
Browse files Browse the repository at this point in the history
  • Loading branch information
guatedude2 committed Jun 1, 2022
1 parent 9a174c2 commit a9694de
Show file tree
Hide file tree
Showing 22 changed files with 4,052 additions and 799 deletions.
13 changes: 0 additions & 13 deletions .eslintrc

This file was deleted.

75 changes: 75 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: __dirname,
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: ['plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'],
env: {
es6: true,
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
// https://github.com/typescript-eslint/typescript-eslint/blob/v3.2.0/packages/eslint-plugin/docs/rules/explicit-module-boundary-types.md
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/consistent-type-assertions': 'off',
'@typescript-eslint/indent': 'off',
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/member-delimiter-style': [
'off',
'error',
{
multiline: {
delimiter: 'none',
requireLast: true,
},
singleline: {
delimiter: 'semi',
requireLast: false,
},
},
],
'no-param-reassign': 'error',
'@typescript-eslint/member-ordering': 'off',
'@typescript-eslint/no-this-alias': 'error',
'@typescript-eslint/quotes': 'off',
'@typescript-eslint/semi': ['off', null],
'@typescript-eslint/space-within-parens': ['off', 'never'],
'@typescript-eslint/type-annotation-spacing': 'off',
'arrow-parens': ['off', 'as-needed'],
camelcase: ['error', { properties: 'never', ignoreImports: true }],
curly: ['error', 'multi-line'],
'eol-last': 'off',
eqeqeq: ['error', 'smart'],
'id-blacklist': 'error',
'id-match': 'error',
'linebreak-style': 'off',
'new-parens': 'off',
'newline-per-chained-call': 'off',
'no-console': 'off',
'no-duplicate-imports': 'error',
'no-eval': 'error',
'no-extra-semi': 'off',
'no-irregular-whitespace': 'off',
'no-multiple-empty-lines': 'off',
'no-new-wrappers': 'error',
'no-trailing-spaces': 'off',
'no-underscore-dangle': 'error',
'no-var': 'error',
'object-shorthand': 'error',
'one-var': ['error', 'never'],
'prefer-const': 'error',
'prefer-template': 'error',
'quote-props': 'off',
radix: 'error',
'space-before-function-paren': 'off',
'spaced-comment': 'warn',
'arrow-body-style': ['warn', 'as-needed'],
},
};
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
npm-debug.log
lib/
10 changes: 10 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"printWidth": 120,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "all",
"bracketSpacing": true,
"arrowParens": "avoid"
}
3 changes: 0 additions & 3 deletions index.js

This file was deleted.

13 changes: 13 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
moduleFileExtensions: ['js', 'json', 'ts'],
rootDir: '.',
testRegex: '.*\\.spec\\.ts$',
transform: {
'^.+\\.(t|j)s$': 'ts-jest',
},
collectCoverageFrom: ['**/*.(t|j)s'],
coverageDirectory: './coverage',
testEnvironment: 'node',
roots: ['<rootDir>/src/'],
testPathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/apps/legacy/node_modules/'],
};
167 changes: 0 additions & 167 deletions lib/readfiles.js

This file was deleted.

17 changes: 11 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
"name": "node-readfiles",
"version": "0.2.1",
"description": "A lightweight Node.js module to recursively read files in a directory using ES6 Promises",
"main": "index.js",
"main": "lib/readfiles.js",
"scripts": {
"start": "echo 'Not a runnable module' && exit 1",
"test": "mocha",
"test": "jest",
"build": "tsc",
"lint": "eslint lib test",
"preversion": "npm run lint && npm test"
},
Expand All @@ -26,11 +27,15 @@
"url": "git+https://github.com/guatedude2/node-readfiles.git"
},
"devDependencies": {
"chai": "^3.5.0",
"@types/jest": "^27.5.1",
"@typescript-eslint/eslint-plugin": "^5.27.0",
"@typescript-eslint/parser": "^5.27.0",
"eslint": "^6.7.2",
"mocha": "^2.4.5",
"mock-fs": "^3.9.0",
"sinon": "^1.17.4"
"jest": "^28.1.0",
"prettier": "^2.6.2",
"ts-jest": "^28.0.3",
"ts-node": "^10.8.0",
"typescript": "^4.7.2"
},
"dependencies": {
"es6-promise": "^3.2.1"
Expand Down
25 changes: 25 additions & 0 deletions src/build-filter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export const buildFilter = (filtersParam: string | string[]) => {
const filters = filtersParam instanceof Array ? filtersParam.slice() : [filtersParam];
const filterArray = [];

if (filters.length === 0) return null;

while (filters.length > 0) {
const filter = filters.shift();
filterArray.push(
'\\/?' +
filter
.replace(/\./g, '\\.')
.replace(/(\*?)(\*)(?!\*)/g, function (match, prefix) {
if (prefix == '*') {
return match;
}
return '[^\\/]*';
})
.replace(/\?/g, '[^\\/]?')
.replace(/\*\*/g, '.*')
.replace(/([\-\+\|])/g, '\\$1'),
);
}
return new RegExp('^' + filterArray.join('|') + '$', 'i');
};
21 changes: 21 additions & 0 deletions src/build-filters.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { buildFilter } from './build-filter';

describe('buildFilter', () => {
it('creates a filter RegExp given a wildcard filter string', () => {
const result = buildFilter('*');

expect(result).toEqual(/^\/?[^\/]*$/i);
});

it('creates a filter RegExp given a wildcard filter string', () => {
const result = buildFilter('**');

expect(result).toEqual(/^\/?.*$/i);
});

it('creates a filter RegExp given an array of filters', () => {
const result = buildFilter(['**/*123*', '**/abc.*']);

expect(result).toEqual(/^\/?.*\/[^\/]*123[^\/]*|\/?.*\/abc\.[^\/]*$/i);
});
});
5 changes: 5 additions & 0 deletions src/consts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum FilenameFormat {
RELATIVE = 0,
FULL_PATH,
FILENAME,
}
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './consts';
export * from './readfiles';
export { readfiles as default } from './readfiles';
Loading

0 comments on commit a9694de

Please sign in to comment.