Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@crowdlinker/nestjs-commons

Package Overview
Dependencies
Maintainers
4
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@crowdlinker/nestjs-commons - npm Package Compare versions

Comparing version 0.0.9 to 0.0.10

28

constants/file.d.ts

@@ -0,8 +1,34 @@

export declare const IMAGE_MIME_TYPES: string[];
export declare const PDF_MIME_TYPES: string[];
export declare const CSV_MIME_TYPES: string[];
export declare const CSV_EXTENSION = ".csv";
export declare const PDF_EXTENSION = ".pdf";
export declare const PNG_EXTENSION = ".png";
export declare const JPG_EXTENSION = ".jpg";
export declare const JPEG_EXTENSION = ".jpeg";
export declare const JPG_EXTENSIONS: string[];
export declare const SVG_EXTENSION = ".svg";
export declare const WEBP_EXTENSION = ".webp";
export declare const GIF_EXTENSION = ".gif";
export declare const IMAGE_EXTENSIONS: string[];
export declare const FileErrors: {
INVALID_FORMAT: string;
EMPTY: string;
INVALID_FORMAT_PDF: string;
};
export declare const CsvFileErrors: {
MISSING_REQUIRED_COLUMNS: string;
INVALID_FORMAT_CSV: string;
INVALID_FORMAT: string;
EMPTY: string;
INVALID_FORMAT_PDF: string;
};
export declare const PdfFileErrors: {
INVALID_FORMAT: string;
EMPTY: string;
INVALID_FORMAT_PDF: string;
};
export declare const ImageFileErrors: {
INVALID_FORMAT: string;
EMPTY: string;
INVALID_FORMAT_IMAGE: string;
};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileErrors = exports.CSV_EXTENSION = exports.CSV_MIME_TYPES = void 0;
exports.ImageFileErrors = exports.PdfFileErrors = exports.CsvFileErrors = exports.FileErrors = exports.IMAGE_EXTENSIONS = exports.GIF_EXTENSION = exports.WEBP_EXTENSION = exports.SVG_EXTENSION = exports.JPG_EXTENSIONS = exports.JPEG_EXTENSION = exports.JPG_EXTENSION = exports.PNG_EXTENSION = exports.PDF_EXTENSION = exports.CSV_EXTENSION = exports.CSV_MIME_TYPES = exports.PDF_MIME_TYPES = exports.IMAGE_MIME_TYPES = void 0;
// File Mime Types
exports.IMAGE_MIME_TYPES = [
'image/png',
'image/jpg',
'image/jpeg',
'image/svg+xml',
'image/webp',
'image/gif',
];
exports.PDF_MIME_TYPES = ['application/pdf'];
exports.CSV_MIME_TYPES = ['text/csv', 'application/vnd.ms-excel'];
// File Extensions
exports.CSV_EXTENSION = '.csv';
exports.PDF_EXTENSION = '.pdf';
// Image Extensions
exports.PNG_EXTENSION = '.png';
exports.JPG_EXTENSION = '.jpg';
exports.JPEG_EXTENSION = '.jpeg';
exports.JPG_EXTENSIONS = ['.jpg', '.jpeg', '.jfif', '.pjpeg', '.pjp'];
exports.SVG_EXTENSION = '.svg';
exports.WEBP_EXTENSION = '.webp';
exports.GIF_EXTENSION = '.gif';
exports.IMAGE_EXTENSIONS = [
...exports.JPG_EXTENSIONS,
exports.PNG_EXTENSION,
exports.SVG_EXTENSION,
exports.WEBP_EXTENSION,
exports.GIF_EXTENSION,
];
// File Errros
exports.FileErrors = {
INVALID_FORMAT: 'The file format is invalid!',
EMPTY: 'The uploaded file does not contain any data.',
MISSING_REQUIRED_COLUMNS: 'The uploaded file is missing required column(s).',
INVALID_FORMAT_CSV: `The file format is invalid! Only "${exports.CSV_EXTENSION}" files are allowed!'`,
INVALID_FORMAT_PDF: `The file format is invalid! Only "${exports.PDF_EXTENSION}" files are allowed!'`,
};
exports.CsvFileErrors = Object.assign(Object.assign({}, exports.FileErrors), { MISSING_REQUIRED_COLUMNS: 'The uploaded file is missing required column(s).', INVALID_FORMAT: `The file format is invalid! Only "${exports.CSV_EXTENSION}" files are allowed!'` });
exports.PdfFileErrors = Object.assign(Object.assign({}, exports.FileErrors), { INVALID_FORMAT: `The file format is invalid! Only "${exports.PDF_EXTENSION}" files are allowed!'` });
exports.ImageFileErrors = {
INVALID_FORMAT: 'The image format is invalid!',
EMPTY: 'The image file does not contain any data.',
INVALID_FORMAT_IMAGE: `The file format is invalid! Only images are allowed!'`,
};

@@ -70,2 +70,18 @@ /// <reference types="node" />

/**
* Checks if the extension is '.pdf'.
*
* @param {string} fileName
*
* @returns {boolean}
*/
export declare const isPDFExtension: (fileName: string) => boolean;
/**
* Checks if the extension belongs to an image.
*
* @param {string} fileName
*
* @returns {boolean}
*/
export declare const isImageExtension: (fileName: string) => boolean;
/**
* Checks if the 'mime-type' matches an actual csv mime type

@@ -79,2 +95,10 @@ *

/**
* Checks if the 'mime-type' matches an actual image mime type
*
* @param {string} mimeType
*
* @returns {boolean}
*/
export declare const isImageMimeType: (mimeType: string) => boolean;
/**
* Multer filter filter for csv files (used for validating uploaded files).

@@ -89,1 +113,11 @@ *

export declare const multerCsvFileFilter: MulterFileFilter;
/**
* Multer filter filter for image files (used for validating uploaded files).
*
* @param {any} req
* @param {UploadedFile} file
* @param {(error: Error | null, acceptFile: boolean) => void} cb
*
* @returns {void}
*/
export declare const multerImageFileFilter: MulterFileFilter;

@@ -15,8 +15,8 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.multerCsvFileFilter = exports.isCSVMimeType = exports.isCSVExtension = exports.multerFileFilter = exports.multerFileName = exports.deleteFile = exports.createFile = exports.getFile = exports.checkIfFileOrDirectoryExists = void 0;
exports.multerImageFileFilter = exports.multerCsvFileFilter = exports.isImageMimeType = exports.isCSVMimeType = exports.isImageExtension = exports.isPDFExtension = exports.isCSVExtension = exports.multerFileFilter = exports.multerFileName = exports.deleteFile = exports.createFile = exports.getFile = exports.checkIfFileOrDirectoryExists = void 0;
const fs_1 = __importDefault(require("fs"));
const file_1 = require("../constants/file");
const path_1 = require("path");
const util_1 = require("util");
const common_1 = require("@nestjs/common");
const file_1 = require("../constants/file");
/**

@@ -120,2 +120,20 @@ * Check if a file exists at a given path.

/**
* Checks if the extension is '.pdf'.
*
* @param {string} fileName
*
* @returns {boolean}
*/
const isPDFExtension = (fileName) => file_1.PDF_EXTENSION === path_1.extname(fileName);
exports.isPDFExtension = isPDFExtension;
/**
* Checks if the extension belongs to an image.
*
* @param {string} fileName
*
* @returns {boolean}
*/
const isImageExtension = (fileName) => file_1.IMAGE_EXTENSIONS.includes(path_1.extname(fileName));
exports.isImageExtension = isImageExtension;
/**
* Checks if the 'mime-type' matches an actual csv mime type

@@ -130,2 +148,11 @@ *

/**
* Checks if the 'mime-type' matches an actual image mime type
*
* @param {string} mimeType
*
* @returns {boolean}
*/
const isImageMimeType = (mimeType) => file_1.IMAGE_MIME_TYPES.includes(mimeType);
exports.isImageMimeType = isImageMimeType;
/**
* Multer filter filter for csv files (used for validating uploaded files).

@@ -158,5 +185,28 @@ *

cb(null, false);
return cb(new common_1.BadRequestException(file_1.FileErrors.INVALID_FORMAT_CSV), false);
return cb(new common_1.BadRequestException(file_1.CsvFileErrors.INVALID_FORMAT), false);
}
};
exports.multerCsvFileFilter = multerCsvFileFilter;
/**
* Multer filter filter for image files (used for validating uploaded files).
*
* @param {any} req
* @param {UploadedFile} file
* @param {(error: Error | null, acceptFile: boolean) => void} cb
*
* @returns {void}
*/
const multerImageFileFilter = (req, file, cb) => {
const { mimetype, originalname } = file;
if (mimetype && mimetype.length && exports.isImageMimeType(mimetype)) {
cb(null, true);
}
else if (exports.isImageExtension(originalname)) {
cb(null, true);
}
else {
cb(null, false);
return cb(new common_1.BadRequestException(file_1.ImageFileErrors.INVALID_FORMAT), false);
}
};
exports.multerImageFileFilter = multerImageFileFilter;

2

package.json
{
"name": "@crowdlinker/nestjs-commons",
"version": "0.0.9",
"version": "0.0.10",
"description": "Commons for NestJS based projects",

@@ -5,0 +5,0 @@ "author": "Crowdlinker Inc.",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc