find-duplicate-strings
Advanced tools
Comparing version 2.1.2 to 2.1.4
@@ -25,9 +25,4 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
yield new scanner_1.Scanner(Object.assign(Object.assign({}, options), { path })).scan(); | ||
} | ||
catch (error) { | ||
throw error; | ||
} | ||
yield new scanner_1.Scanner(Object.assign(Object.assign({}, options), { path })).scan().catch((e) => console.error(e)); | ||
}); | ||
} |
@@ -34,3 +34,3 @@ "use strict"; | ||
this.extensions = extensions; | ||
this.path = (0, path_1.resolve)(process.cwd(), directory); | ||
this.path = (0, path_1.normalize)((0, path_1.resolve)(process.cwd(), directory)); | ||
if (!(0, fs_1.existsSync)(this.path)) { | ||
@@ -46,2 +46,3 @@ throw new Error('Directory does not exist, please pass a valid path.'); | ||
} | ||
// TODO: support reading single file | ||
readdirRecursively(path) { | ||
@@ -54,4 +55,18 @@ return __asyncGenerator(this, arguments, function* readdirRecursively_1() { | ||
} | ||
const fullPath = (0, path_1.resolve)(path, dirent.name); | ||
if (dirent.isDirectory()) { | ||
let fullPath = (0, path_1.join)(path, dirent.name); | ||
let isLink = false; | ||
if (dirent.isSymbolicLink()) { | ||
try { | ||
fullPath = yield __await(fs_1.promises.realpath(fullPath)); | ||
isLink = true; | ||
} | ||
catch (error) { | ||
if (error.message.includes('ENOENT')) { | ||
continue; // ignore broken symlinks | ||
} | ||
throw error; | ||
} | ||
} | ||
const isDir = isLink ? (yield __await(fs_1.promises.lstat(fullPath))).isDirectory() : dirent.isDirectory(); | ||
if (isDir) { | ||
yield __await(yield* __asyncDelegator(__asyncValues(this.readdirRecursively(fullPath)))); | ||
@@ -58,0 +73,0 @@ } |
/// <reference types="node" /> | ||
import type { Interface } from 'readline'; | ||
import { Interface } from 'readline'; | ||
export declare class File { | ||
@@ -8,6 +8,4 @@ private name; | ||
private processLine; | ||
private shouldStoreSingleQuoteString; | ||
private shouldStoreDoubleQuoteString; | ||
private storeMatch; | ||
private readlineInterface; | ||
} |
@@ -7,8 +7,2 @@ "use strict"; | ||
const store_1 = require("./store"); | ||
var Character; | ||
(function (Character) { | ||
Character[Character["SINGLE_QUOTE"] = 39] = "SINGLE_QUOTE"; | ||
Character[Character["DOUBLE_QUOTE"] = 34] = "DOUBLE_QUOTE"; | ||
Character[Character["BACKSLASH"] = 92] = "BACKSLASH"; | ||
})(Character || (Character = {})); | ||
class File { | ||
@@ -24,38 +18,11 @@ constructor(name) { | ||
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 && characterSet.length) { | ||
this.storeMatch(characterSet, this.name); | ||
characterSet = ''; | ||
} | ||
continue; | ||
} | ||
if (this.shouldStoreSingleQuoteString(line, i, doubleQuoteToggle)) { | ||
singleQuoteToggle = !singleQuoteToggle; | ||
if (!singleQuoteToggle && characterSet.length) { | ||
this.storeMatch(characterSet, this.name); | ||
characterSet = ''; | ||
} | ||
continue; | ||
} | ||
if (doubleQuoteToggle || singleQuoteToggle) { | ||
characterSet += line[i]; | ||
continue; | ||
} | ||
const matches = line.match(/(?:("[^"\\]*(?:\\.[^"\\]*)*")|('[^'\\]*(?:\\.[^'\\]*)*'))/g); | ||
if (matches) { | ||
matches | ||
.filter((match) => match && match.length > 2) | ||
.forEach((match) => { | ||
this.storeMatch(match.substring(1, match.length - 1), this.name); | ||
}); | ||
} | ||
} | ||
shouldStoreSingleQuoteString(line, index, toggle) { | ||
return (line.charCodeAt(index) === Character.SINGLE_QUOTE && | ||
line.charCodeAt(index - 1) !== Character.BACKSLASH && | ||
toggle === false); | ||
} | ||
shouldStoreDoubleQuoteString(line, index, toggle) { | ||
return (line.charCodeAt(index) === Character.DOUBLE_QUOTE && | ||
line.charCodeAt(index - 1) !== Character.BACKSLASH && | ||
toggle === false); | ||
} | ||
storeMatch(key, file) { | ||
@@ -62,0 +29,0 @@ const value = store_1.Store.find(key); |
@@ -5,2 +5,4 @@ import { Readable } from 'stream'; | ||
export declare const file3: () => Readable; | ||
export declare const file4: () => Readable; | ||
export declare const emptyStringsFile: () => Readable; | ||
export declare const noStringsFile: () => Readable; | ||
export declare const emptyFile: () => Readable; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.file4 = exports.file3 = exports.file2 = exports.file1 = void 0; | ||
exports.emptyFile = exports.noStringsFile = exports.emptyStringsFile = exports.file3 = exports.file2 = exports.file1 = void 0; | ||
const stream_1 = require("stream"); | ||
@@ -22,12 +22,2 @@ const file1 = () => { | ||
readable.push(` it("", () => {`); | ||
readable.push(` });`); | ||
readable.push(`});`); | ||
readable.push(null); | ||
return readable; | ||
}; | ||
exports.file2 = file2; | ||
const file3 = () => { | ||
const readable = new stream_1.Readable({ encoding: 'utf8' }); | ||
readable.push(`describe('', () => {`); | ||
readable.push(` it("", () => {`); | ||
readable.push(` let foo = "foo";`); | ||
@@ -41,4 +31,4 @@ readable.push(` foo = "foo";`); | ||
}; | ||
exports.file3 = file3; | ||
const file4 = () => { | ||
exports.file2 = file2; | ||
const file3 = () => { | ||
const readable = new stream_1.Readable({ encoding: 'utf8' }); | ||
@@ -57,2 +47,23 @@ readable.push(`const foo = "foo";`); | ||
}; | ||
exports.file4 = file4; | ||
exports.file3 = file3; | ||
const emptyStringsFile = () => { | ||
const readable = new stream_1.Readable({ encoding: 'utf8' }); | ||
readable.push(`console.log('')`); | ||
readable.push(`console.log("")`); | ||
readable.push(null); | ||
return readable; | ||
}; | ||
exports.emptyStringsFile = emptyStringsFile; | ||
const noStringsFile = () => { | ||
const readable = new stream_1.Readable({ encoding: 'utf8' }); | ||
readable.push(`foobar`); | ||
readable.push(null); | ||
return readable; | ||
}; | ||
exports.noStringsFile = noStringsFile; | ||
const emptyFile = () => { | ||
const readable = new stream_1.Readable({ encoding: 'utf8' }); | ||
readable.push(null); | ||
return readable; | ||
}; | ||
exports.emptyFile = emptyFile; |
@@ -1,5 +0,5 @@ | ||
import type { Finding } from './finding'; | ||
import { Finding } from './finding'; | ||
export declare class Output { | ||
private input; | ||
private silent; | ||
private data; | ||
constructor(input: Finding[], silent: boolean); | ||
@@ -6,0 +6,0 @@ output(): Promise<void>; |
@@ -18,4 +18,4 @@ "use strict"; | ||
constructor(input, silent) { | ||
this.input = input; | ||
this.silent = silent; | ||
this.data = input.sort((a, b) => b.count - a.count); | ||
} | ||
@@ -25,6 +25,6 @@ output() { | ||
if (!this.silent) { | ||
this.outputToConsole(this.input); | ||
this.outputToConsole(this.data); | ||
} | ||
const fileName = yield new questions_1.OutputQuestion().getAnswer(); | ||
this.outputToFile(this.input, fileName); | ||
this.outputToFile(this.data, fileName); | ||
}); | ||
@@ -31,0 +31,0 @@ } |
@@ -1,4 +0,4 @@ | ||
import type { Finding } from './finding'; | ||
import { Finding } from './finding'; | ||
declare const findings: Finding[]; | ||
declare const manyFindings: Finding[]; | ||
export { findings, manyFindings }; |
{ | ||
"name": "find-duplicate-strings", | ||
"version": "2.1.2", | ||
"version": "2.1.4", | ||
"description": "Easy to use CLI that finds duplicate strings in a directory and stores them in a external file for easy reference", | ||
@@ -37,3 +37,3 @@ "author": "Erwin Heitzman", | ||
"dependencies": { | ||
"commander": "^8.2.0", | ||
"commander": "^8.3.0", | ||
"inquirer": "^8.2.0" | ||
@@ -45,10 +45,10 @@ }, | ||
"@types/jest": "^27.0.2", | ||
"@types/node": "^16.11.0", | ||
"@typescript-eslint/eslint-plugin": "^5.0.0", | ||
"@typescript-eslint/parser": "^5.0.0", | ||
"eslint": "^8.0.1", | ||
"@types/node": "^16.11.6", | ||
"@typescript-eslint/eslint-plugin": "^5.3.0", | ||
"@typescript-eslint/parser": "^5.3.0", | ||
"eslint": "^8.1.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"husky": "^7.0.2", | ||
"jest": "^27.2.5", | ||
"lint-staged": "^11.2.3", | ||
"husky": "^7.0.4", | ||
"jest": "^27.3.1", | ||
"lint-staged": "^11.2.6", | ||
"prettier": "^2.4.1", | ||
@@ -55,0 +55,0 @@ "ts-jest": "^27.0.7", |
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
42454
837
Updatedcommander@^8.3.0