Skip to content

Commit

Permalink
chore: Fixed "no-var" lint
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Dec 1, 2020
1 parent bf2d609 commit a9623cd
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 54 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ module.exports = {
'no-empty': ['error', { allowEmptyCatch: true }],
'no-useless-catch': 'off',
'no-useless-escape': 'off',
'no-var': 'off',
'prefer-const': 'off',
},
overrides: [
Expand Down
24 changes: 12 additions & 12 deletions src/api/helpers/decrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ export const magix = (
mediaType: any,
expectedSize?: number
) => {
var encodedHex = fileData.toString('hex');
var encodedBytes = hexToBytes(encodedHex);
var mediaKeyBytes: any = base64ToBytes(mediaKeyBase64);
const encodedHex = fileData.toString('hex');
const encodedBytes = hexToBytes(encodedHex);
const mediaKeyBytes: any = base64ToBytes(mediaKeyBase64);
const info = `WhatsApp ${mediaTypes[mediaType.toUpperCase()]} Keys`;
const hash: string = 'sha256';
const salt: any = new Uint8Array(32);
Expand All @@ -105,10 +105,10 @@ export const magix = (
info,
hash,
});
var iv = mediaKeyExpanded.slice(0, 16);
var cipherKey = mediaKeyExpanded.slice(16, 48);
var decipher = crypto.createDecipheriv('aes-256-cbc', cipherKey, iv);
var decoded: Buffer = decipher.update(encodedBytes);
const iv = mediaKeyExpanded.slice(0, 16);
const cipherKey = mediaKeyExpanded.slice(16, 48);
const decipher = crypto.createDecipheriv('aes-256-cbc', cipherKey, iv);
const decoded: Buffer = decipher.update(encodedBytes);
const mediaDataBuffer = expectedSize
? fixPadding(decoded, expectedSize)
: decoded;
Expand All @@ -132,17 +132,17 @@ const fixPadding = (data: Buffer, expectedSize: number) => {
};

const hexToBytes = (hexStr: any) => {
var intArray = [];
for (var i = 0; i < hexStr.length; i += 2) {
const intArray = [];
for (let i = 0; i < hexStr.length; i += 2) {
intArray.push(parseInt(hexStr.substr(i, 2), 16));
}
return new Uint8Array(intArray);
};

const base64ToBytes = (base64Str: any) => {
var binaryStr = atob(base64Str);
var byteArray = new Uint8Array(binaryStr.length);
for (var i = 0; i < binaryStr.length; i++) {
const binaryStr = atob(base64Str);
const byteArray = new Uint8Array(binaryStr.length);
for (let i = 0; i < binaryStr.length; i++) {
byteArray[i] = binaryStr.charCodeAt(i);
}
return byteArray;
Expand Down
2 changes: 1 addition & 1 deletion src/api/helpers/delete-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function deleteFiles(
spinnies: Spinnies
) {
spinnies.add(`removeFile`, { text: '....' });
var pathTokens: string = path.join(
const pathTokens: string = path.join(
path.resolve(
process.cwd() + mergedOptions.mkdirFolderToken,
mergedOptions.folderNameToken
Expand Down
2 changes: 1 addition & 1 deletion src/api/helpers/file-to-base64.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNMMNMNMMMNMMNNMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNNNNMMNNNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
*/
var mimeTypes = require('mime-types');
const mimeTypes = require('mime-types');
import * as fs from 'fs';

/**
Expand Down
4 changes: 2 additions & 2 deletions src/api/helpers/scrape-deletetoken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ declare global {
}
}
export async function scrapeDeleteToken(page: Page): Promise<boolean> {
var result = await page.evaluate(() => {
var scrape = window.pathSession;
const result = await page.evaluate(() => {
const scrape = window.pathSession;
if (scrape === true) {
return true;
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/api/helpers/scrape-desconnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ declare global {
}
}
export async function scrapeDesconnected(page: Page): Promise<boolean> {
var result = await page.evaluate(() => {
var scrape = window.Store.State.default.on('change:state');
const result = await page.evaluate(() => {
const scrape = window.Store.State.default.on('change:state');
if (
scrape.__x_stream === 'DISCONNECTED' &&
scrape.__x_state === 'CONNECTED'
Expand Down
8 changes: 4 additions & 4 deletions src/api/helpers/scrape-login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
*/
import { Page } from 'puppeteer';
export async function scrapeLogin(page: Page): Promise<boolean> {
var result = await page.evaluate(() => {
let count = document.querySelector('._9a59P');
var data: boolean;
const result = await page.evaluate(() => {
const count = document.querySelector('._9a59P');
let data: boolean;
data = false;
if (count != null) {
var text = count.textContent,
const text = count.textContent,
timeNumber = text.match('Invalid');
if (timeNumber) {
data = true;
Expand Down
2 changes: 1 addition & 1 deletion src/api/helpers/select-sticker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ interface CreateSize {
height?: number;
}
export async function resizeImg(buff: Buffer, size: CreateSize) {
var _ins = await sharp(buff, { failOnError: false })
const _ins = await sharp(buff, { failOnError: false })
.resize({ width: size.width, height: size.height })
.toBuffer(),
_w = sharp(_ins, { failOnError: false }).jpeg(),
Expand Down
2 changes: 1 addition & 1 deletion src/api/layers/controls.layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class ControlsLayer extends UILayer {
*/
public async pinChat(chatId: string, option: boolean, nonExistent?: boolean) {
return new Promise(async (resolve, reject) => {
var result = await this.page.evaluate(
const result = await this.page.evaluate(
({ chatId, option, nonExistent }) => {
return WAPI.pinChat(chatId, option, nonExistent);
},
Expand Down
2 changes: 1 addition & 1 deletion src/api/layers/listener.layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class ListenerLayer extends ProfileLayer {
];

for (const func of functions) {
var has = await this.page
const has = await this.page
.evaluate((func) => typeof window[func] === 'function', func)
.catch(() => false);

Expand Down
6 changes: 3 additions & 3 deletions src/api/layers/profile.layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class ProfileLayer extends HostLayer {
*/
public sendMute(id: string, time: number, type: string): Promise<object> {
return new Promise(async (resolve, reject) => {
var result = await this.page.evaluate(
const result = await this.page.evaluate(
(id, time, type) => WAPI.sendMute(id, time, type),
id,
time,
Expand Down Expand Up @@ -133,9 +133,9 @@ export class ProfileLayer extends HostLayer {
const mimeInfo = base64MimeType(b64);

if (!mimeInfo || mimeInfo.includes('image')) {
var _webb64_96 = await resizeImg(buff, { width: 96, height: 96 }),
let _webb64_96 = await resizeImg(buff, { width: 96, height: 96 }),
_webb64_640 = await resizeImg(buff, { width: 640, height: 640 });
var obj = { a: _webb64_640, b: _webb64_96 };
let obj = { a: _webb64_640, b: _webb64_96 };

return await this.page.evaluate(({ obj }) => WAPI.setProfilePic(obj), {
obj,
Expand Down
38 changes: 19 additions & 19 deletions src/api/layers/sender.layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class SenderLayer extends ListenerLayer {
title: string
): Promise<SendLinkResult> {
return new Promise(async (resolve, reject) => {
var result = await this.page.evaluate(
const result = await this.page.evaluate(
({ chatId, url, title }) => {
return WAPI.sendLinkPreview(chatId, url, title);
},
Expand All @@ -110,13 +110,13 @@ export class SenderLayer extends ListenerLayer {
*/
public async sendText(to: string, content: string): Promise<Message> {
return new Promise(async (resolve, reject) => {
var messageId: string = await this.page.evaluate(
const messageId: string = await this.page.evaluate(
({ to, content }) => {
return WAPI.sendMessage(to, content);
},
{ to, content }
);
var result = (await this.page.evaluate(
const result = (await this.page.evaluate(
(messageId: any) => WAPI.getMessageById(messageId),
messageId
)) as Message;
Expand All @@ -135,13 +135,13 @@ export class SenderLayer extends ListenerLayer {
): Promise<Message> {
return new Promise(async (resolve, reject) => {
try {
var messageId = await this.page.evaluate(
const messageId = await this.page.evaluate(
({ chat, content, options }) => {
return WAPI.sendMessageOptions(chat, content, options);
},
{ chat, content, options }
);
var result = (await this.page.evaluate(
const result = (await this.page.evaluate(
(messageId: any) => WAPI.getMessageById(messageId),
messageId
)) as Message;
Expand Down Expand Up @@ -179,7 +179,7 @@ export class SenderLayer extends ListenerLayer {
}

if (!base64) {
var obj = {
const obj = {
erro: true,
to: to,
text: 'No such file or directory, open "' + filePath + '"',
Expand Down Expand Up @@ -214,7 +214,7 @@ export class SenderLayer extends ListenerLayer {
let mimeType = base64MimeType(base64);

if (!mimeType) {
var obj = {
const obj = {
erro: true,
to: to,
text: 'Invalid base64!',
Expand All @@ -223,7 +223,7 @@ export class SenderLayer extends ListenerLayer {
}

if (!mimeType.includes('image')) {
var obj = {
const obj = {
erro: true,
to: to,
text: 'Not an image, allowed formats png, jpeg and webp',
Expand All @@ -233,7 +233,7 @@ export class SenderLayer extends ListenerLayer {

filename = filenameFromMimeType(filename, mimeType);

var result = await this.page.evaluate(
const result = await this.page.evaluate(
({ to, base64, filename, caption }) => {
return WAPI.sendImage(base64, to, filename, caption);
},
Expand Down Expand Up @@ -288,13 +288,13 @@ export class SenderLayer extends ListenerLayer {
quotedMsg: string
): Promise<Message> {
return new Promise(async (resolve, reject) => {
var messageId: string = await this.page.evaluate(
const messageId: string = await this.page.evaluate(
({ to, content, quotedMsg }) => {
return WAPI.reply(to, content, quotedMsg);
},
{ to, content, quotedMsg }
);
var result = (await this.page.evaluate(
const result = (await this.page.evaluate(
(messageId: any) => WAPI.getMessageById(messageId),
messageId
)) as Message;
Expand Down Expand Up @@ -346,7 +346,7 @@ export class SenderLayer extends ListenerLayer {
let mimeType = base64MimeType(base64);

if (!mimeType) {
var obj = {
const obj = {
erro: true,
to: to,
text: 'Invalid base64!',
Expand All @@ -356,8 +356,8 @@ export class SenderLayer extends ListenerLayer {

filename = filenameFromMimeType(filename, mimeType);

var type = 'FileFromBase64';
var result = await this.page.evaluate(
const type = 'FileFromBase64';
const result = await this.page.evaluate(
({ to, base64, filename, caption, type }) => {
return WAPI.sendFile(base64, to, filename, caption, type);
},
Expand Down Expand Up @@ -462,7 +462,7 @@ export class SenderLayer extends ListenerLayer {
name?: string
) {
return new Promise(async (resolve, reject) => {
var result = await this.page.evaluate(
const result = await this.page.evaluate(
({ to, contactsId, name }) => {
return WAPI.sendContactVcard(to, contactsId, name);
},
Expand All @@ -483,7 +483,7 @@ export class SenderLayer extends ListenerLayer {
*/
public async sendContactVcardList(to: string, contacts: string[]) {
return new Promise(async (resolve, reject) => {
var result = await this.page.evaluate(
const result = await this.page.evaluate(
({ to, contacts }) => {
return WAPI.sendContactVcardList(to, contacts);
},
Expand Down Expand Up @@ -541,7 +541,7 @@ export class SenderLayer extends ListenerLayer {
let _met = obj['metadata'];

return new Promise(async (resolve, reject) => {
var result = await this.page.evaluate(
const result = await this.page.evaluate(
({ _webb64, to, _met }) => {
return WAPI.sendImageAsSticker(_webb64, to, _met, 'StickerGif');
},
Expand Down Expand Up @@ -593,7 +593,7 @@ export class SenderLayer extends ListenerLayer {
let _webb64 = obj['webpBase64'];
let _met = obj['metadata'];
return new Promise(async (resolve, reject) => {
var result = await this.page.evaluate(
const result = await this.page.evaluate(
({ _webb64, to, _met }) => {
return WAPI.sendImageAsSticker(_webb64, to, _met, 'Sticker');
},
Expand Down Expand Up @@ -628,7 +628,7 @@ export class SenderLayer extends ListenerLayer {
title: string
) {
return new Promise(async (resolve, reject) => {
var result = await this.page.evaluate(
const result = await this.page.evaluate(
({ to, latitude, longitude, title }) => {
return WAPI.sendLocation(to, latitude, longitude, title);
},
Expand Down
8 changes: 3 additions & 5 deletions src/controllers/initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ export async function create(
options?: CreateConfig,
browserSessionToken?: object
): Promise<Whatsapp> {
var browserToken: any,
Session: string,
Session = session;
let browserToken: any;

const spinnies = getSpinnies({
disableSpins: options ? options.disableSpins : false,
Expand All @@ -107,7 +105,7 @@ export async function create(
text: 'Initializing browser...',
});

const browser = await initBrowser(Session, mergedOptions);
const browser = await initBrowser(session, mergedOptions);

if (browser === 'connect') {
spinnies.fail(`browser-${session}`, {
Expand Down Expand Up @@ -167,7 +165,7 @@ export async function create(
}

const waPage = await initWhatsapp(
Session,
session,
mergedOptions,
browser,
browserToken
Expand Down
2 changes: 1 addition & 1 deletion src/types/WAPI.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,5 +203,5 @@ declare global {
interface Window {
WAPI: WAPI;
}
var WAPI: WAPI;
const WAPI: WAPI;
}

0 comments on commit a9623cd

Please sign in to comment.