find-duplicate-strings
Advanced tools
Comparing version 2.0.4 to 2.1.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ThresholdQuestion = exports.ConfirmScannedDirQuestion = exports.ConfirmDirectoryQuestion = exports.OutputQuestion = exports.ExtensionsQuestion = exports.ExclusionsQuestion = exports.DirectoryQuestion = void 0; | ||
var directory_1 = require("./directory"); | ||
@@ -4,0 +5,0 @@ Object.defineProperty(exports, "DirectoryQuestion", { enumerable: true, get: function () { return directory_1.DirectoryQuestion; } }); |
@@ -6,4 +6,4 @@ export declare class Directory { | ||
constructor(directory: string, exclusions: string[], extensions: string[]); | ||
getFiles(): string[]; | ||
getFiles(): AsyncGenerator<string, void, unknown>; | ||
private readdirRecursively; | ||
} |
"use strict"; | ||
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); } | ||
var __asyncValues = (this && this.__asyncValues) || function (o) { | ||
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); | ||
var m = o[Symbol.asyncIterator], i; | ||
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i); | ||
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } | ||
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } | ||
}; | ||
var __asyncDelegator = (this && this.__asyncDelegator) || function (o) { | ||
var i, p; | ||
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i; | ||
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; } | ||
}; | ||
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) { | ||
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); | ||
var g = generator.apply(thisArg, _arguments || []), i, q = []; | ||
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; | ||
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } | ||
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } | ||
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } | ||
function fulfill(value) { resume("next", value); } | ||
function reject(value) { resume("throw", value); } | ||
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -10,20 +34,2 @@ exports.Directory = void 0; | ||
this.extensions = extensions; | ||
this.readdirRecursively = (path) => { | ||
const files = []; | ||
fs_1.readdirSync(path).forEach((file) => { | ||
if (this.exclusions.includes(file)) { | ||
return; | ||
} | ||
const fullPath = path_1.resolve(path, file); | ||
if (fs_1.statSync(fullPath).isDirectory()) { | ||
files.push(...this.readdirRecursively(fullPath)); | ||
return; | ||
} | ||
const extension = path_1.extname(fullPath).substr(1); | ||
if (!this.extensions.length || this.extensions.includes(extension)) { | ||
files.push(fullPath); | ||
} | ||
}); | ||
return files; | ||
}; | ||
this.path = path_1.resolve(process.cwd(), directory); | ||
@@ -40,3 +46,23 @@ if (!fs_1.existsSync(this.path)) { | ||
} | ||
readdirRecursively(path) { | ||
return __asyncGenerator(this, arguments, function* readdirRecursively_1() { | ||
const dirents = yield __await(fs_1.promises.readdir(path, { withFileTypes: true })); | ||
for (const dirent of dirents) { | ||
if (this.exclusions.includes(dirent.name)) { | ||
continue; | ||
} | ||
const fullPath = path_1.resolve(path, dirent.name); | ||
if (dirent.isDirectory()) { | ||
yield __await(yield* __asyncDelegator(__asyncValues(this.readdirRecursively(fullPath)))); | ||
} | ||
else { | ||
const extension = path_1.extname(dirent.name).substr(1); | ||
if (!this.extensions.length || this.extensions.includes(extension)) { | ||
yield yield __await(fullPath); | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
exports.Directory = Directory; |
@@ -1,13 +0,12 @@ | ||
import { Store } from './store'; | ||
import { Finding } from './ifinding'; | ||
/// <reference types="node" /> | ||
import { Interface } from 'readline'; | ||
export declare class File { | ||
private store; | ||
private name; | ||
private readonly file; | ||
constructor(store: Store<Finding>, name: string); | ||
getStrings(): void; | ||
constructor(name: string); | ||
processContent(): Interface; | ||
private processLine; | ||
private shouldStoreSingleQuoteString; | ||
private shouldStoreDoubleQuoteString; | ||
private storeMatch; | ||
private getLines; | ||
private readlineInterface; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.File = void 0; | ||
const readline_1 = require("readline"); | ||
const fs_1 = require("fs"); | ||
const store_1 = require("./store"); | ||
var Character; | ||
@@ -12,35 +14,36 @@ (function (Character) { | ||
class File { | ||
constructor(store, name) { | ||
this.store = store; | ||
constructor(name) { | ||
this.name = name; | ||
this.file = fs_1.readFileSync(name, 'utf8'); | ||
} | ||
getStrings() { | ||
this.getLines().forEach((line) => { | ||
let singleQuoteToggle = false; | ||
let doubleQuoteToggle = false; | ||
let characterSet = ''; | ||
for (let i = 0; i < line.length; i++) { | ||
if (this.shouldStoreDoubleQuoteString(line, i, singleQuoteToggle)) { | ||
doubleQuoteToggle = !doubleQuoteToggle; | ||
if (doubleQuoteToggle === false && characterSet.length) { | ||
this.storeMatch(characterSet, this.name); | ||
characterSet = ''; | ||
} | ||
continue; | ||
processContent() { | ||
const rl = this.readlineInterface(); | ||
rl.on('line', (line) => this.processLine(line)); | ||
return rl; | ||
} | ||
processLine(line) { | ||
let singleQuoteToggle = false; | ||
let doubleQuoteToggle = false; | ||
let characterSet = ''; | ||
for (let i = 0; i < line.length; i++) { | ||
if (this.shouldStoreDoubleQuoteString(line, i, singleQuoteToggle)) { | ||
doubleQuoteToggle = !doubleQuoteToggle; | ||
if (doubleQuoteToggle === false && characterSet.length) { | ||
this.storeMatch(characterSet, this.name); | ||
characterSet = ''; | ||
} | ||
if (this.shouldStoreSingleQuoteString(line, i, doubleQuoteToggle)) { | ||
singleQuoteToggle = !singleQuoteToggle; | ||
if (singleQuoteToggle === false && characterSet.length) { | ||
this.storeMatch(characterSet, this.name); | ||
characterSet = ''; | ||
} | ||
continue; | ||
continue; | ||
} | ||
if (this.shouldStoreSingleQuoteString(line, i, doubleQuoteToggle)) { | ||
singleQuoteToggle = !singleQuoteToggle; | ||
if (singleQuoteToggle === false && characterSet.length) { | ||
this.storeMatch(characterSet, this.name); | ||
characterSet = ''; | ||
} | ||
if (doubleQuoteToggle === true || singleQuoteToggle === true) { | ||
characterSet += line[i]; | ||
continue; | ||
} | ||
continue; | ||
} | ||
}); | ||
if (doubleQuoteToggle === true || singleQuoteToggle === true) { | ||
characterSet += line[i]; | ||
continue; | ||
} | ||
} | ||
} | ||
@@ -58,5 +61,5 @@ shouldStoreSingleQuoteString(line, index, toggle) { | ||
storeMatch(key, file) { | ||
const value = this.store.find(key); | ||
const value = store_1.Store.find(key); | ||
if (!value) { | ||
this.store.add(key, { key, count: 1, files: [file] }); | ||
store_1.Store.add(key, { key, count: 1, files: [file] }); | ||
return; | ||
@@ -68,8 +71,11 @@ } | ||
value.count++; | ||
this.store.update(key, { key, count: value.count, files: value.files }); | ||
store_1.Store.update(key, { key, count: value.count, files: value.files }); | ||
} | ||
getLines() { | ||
return this.file.split('\n'); | ||
readlineInterface() { | ||
return readline_1.createInterface({ | ||
input: fs_1.createReadStream(this.name, { encoding: 'utf8' }), | ||
terminal: false, | ||
}); | ||
} | ||
} | ||
exports.File = File; |
@@ -1,2 +0,2 @@ | ||
import { Finding } from './ifinding'; | ||
import type { Finding } from './finding'; | ||
export declare class Output { | ||
@@ -3,0 +3,0 @@ private input; |
@@ -11,2 +11,9 @@ "use strict"; | ||
}; | ||
var __asyncValues = (this && this.__asyncValues) || function (o) { | ||
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); | ||
var m = o[Symbol.asyncIterator], i; | ||
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i); | ||
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } | ||
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -24,3 +31,3 @@ exports.Scanner = void 0; | ||
this.scannedDirs = []; | ||
this.store = new store_1.Store(); | ||
this.store = store_1.Store; | ||
if (options.exclusions) { | ||
@@ -58,3 +65,3 @@ this.exclusions = exclusions_1.Exclusions.process(options.exclusions); | ||
if (shouldScan) { | ||
this.scanDir(path); | ||
yield this.scanDir(path); | ||
this.scannedDirs.push(path); | ||
@@ -66,3 +73,3 @@ } | ||
} | ||
const duplicates = this.getDuplicates(this.store); | ||
const duplicates = this.getDuplicates(); | ||
if (!duplicates.length) { | ||
@@ -76,12 +83,25 @@ console.log('No duplicates where found.'); | ||
scanDir(dirName) { | ||
const directory = new directory_1.Directory(dirName, this.exclusions, this.extensions); | ||
const files = directory.getFiles(); | ||
for (const file of files) { | ||
new file_1.File(this.store, file).getStrings(); | ||
} | ||
var e_1, _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const directory = new directory_1.Directory(dirName, this.exclusions, this.extensions); | ||
const files = directory.getFiles(); | ||
try { | ||
for (var files_1 = __asyncValues(files), files_1_1; files_1_1 = yield files_1.next(), !files_1_1.done;) { | ||
const file = files_1_1.value; | ||
new file_1.File(file).processContent(); | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (files_1_1 && !files_1_1.done && (_a = files_1.return)) yield _a.call(files_1); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
}); | ||
} | ||
getDuplicates(store) { | ||
return store.getAll().filter((value) => value.count > this.threshold); | ||
getDuplicates() { | ||
return store_1.Store.getAll().filter((value) => value.count > this.threshold); | ||
} | ||
} | ||
exports.Scanner = Scanner; |
@@ -1,8 +0,7 @@ | ||
export declare class Store<T> { | ||
private readonly store; | ||
add(key: string, value: T): void; | ||
update(key: string, value: T): void; | ||
find(key: string): T | null; | ||
getAll(): T[]; | ||
clear(): void; | ||
export declare class Store { | ||
private static store; | ||
static add(key: string, value: unknown): void; | ||
static update(key: string, value: unknown): void; | ||
static find(key: string): unknown | null; | ||
static getAll(): unknown[]; | ||
} |
@@ -5,6 +5,3 @@ "use strict"; | ||
class Store { | ||
constructor() { | ||
this.store = new Map(); | ||
} | ||
add(key, value) { | ||
static add(key, value) { | ||
if (this.store.has(key)) { | ||
@@ -15,3 +12,3 @@ throw new Error(`Key ${key} already exists`); | ||
} | ||
update(key, value) { | ||
static update(key, value) { | ||
if (!this.store.has(key)) { | ||
@@ -22,12 +19,10 @@ throw new Error(`Key ${key} does not exist`); | ||
} | ||
find(key) { | ||
static find(key) { | ||
return this.store.get(key) || null; | ||
} | ||
getAll() { | ||
static getAll() { | ||
return Array.from(this.store.values()); | ||
} | ||
clear() { | ||
this.store.clear(); | ||
} | ||
} | ||
exports.Store = Store; | ||
Store.store = new Map(); |
{ | ||
"name": "find-duplicate-strings", | ||
"version": "2.0.4", | ||
"version": "2.1.0", | ||
"description": "Easy to use CLI that finds duplicate strings in a directory and stores them in a external file for easy reference", | ||
@@ -37,20 +37,20 @@ "author": "Erwin Heitzman", | ||
"dependencies": { | ||
"commander": "^6.0.0", | ||
"commander": "^6.2.0", | ||
"inquirer": "^7.3.3" | ||
}, | ||
"devDependencies": { | ||
"@types/inquirer": "^7.3.0", | ||
"@types/jest": "^26.0.9", | ||
"@types/node": "^14.0.27", | ||
"@typescript-eslint/eslint-plugin": "^3.9.0", | ||
"@typescript-eslint/parser": "^3.9.0", | ||
"eslint": "^7.6.0", | ||
"eslint-config-prettier": "^6.11.0", | ||
"@types/inquirer": "^7.3.1", | ||
"@types/jest": "^26.0.15", | ||
"@types/node": "^14.14.9", | ||
"@typescript-eslint/eslint-plugin": "^4.8.2", | ||
"@typescript-eslint/parser": "^4.8.2", | ||
"eslint": "^7.14.0", | ||
"eslint-config-prettier": "^6.15.0", | ||
"eslint-plugin-prettier": "^3.1.4", | ||
"husky": "^4.2.5", | ||
"jest": "^26.3.0", | ||
"lint-staged": "^10.2.11", | ||
"prettier": "^2.0.5", | ||
"ts-jest": "^26.2.0", | ||
"typescript": "^3.9.7" | ||
"husky": "^4.3.0", | ||
"jest": "^26.6.3", | ||
"lint-staged": "^10.5.1", | ||
"prettier": "^2.2.0", | ||
"ts-jest": "^26.4.4", | ||
"typescript": "^4.1.2" | ||
}, | ||
@@ -57,0 +57,0 @@ "husky": { |
@@ -1,3 +0,3 @@ | ||
[![Build Status](https://travis-ci.org/erwinheitzman/find-duplicate-strings.svg?branch=master)](https://travis-ci.org/erwinheitzman/find-duplicate-strings) | ||
[![codecov](https://codecov.io/gh/erwinheitzman/find-duplicate-strings/branch/master/graph/badge.svg)](https://codecov.io/gh/erwinheitzman/find-duplicate-strings) | ||
![ci](https://github.com/erwinheitzman/find-duplicate-strings/workflows/ci/badge.svg) | ||
![codecov](https://codecov.io/gh/erwinheitzman/find-duplicate-strings/branch/master/graph/badge.svg) | ||
@@ -4,0 +4,0 @@ # find-duplicate-strings |
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
41411
44
809
Updatedcommander@^6.2.0