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

@squared-functions/module

Package Overview
Dependencies
Maintainers
1
Versions
355
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@squared-functions/module - npm Package Compare versions

Comparing version 0.14.4 to 1.0.0

72

index.js

@@ -1,5 +0,6 @@

/* @squared-functions/module 0.14.4
/* @squared-functions/module 1.0.0
https://github.com/anpham6/squared-functions */
"use strict";
/* eslint no-console: "off" */
Object.defineProperty(exports, "__esModule", { value: true });

@@ -25,2 +26,3 @@ exports.LOG_TYPE = void 0;

const SETTINGS = {};
const HEX_STRING = '0123456789abcdef';
function allSettled(values) {

@@ -37,2 +39,3 @@ return Promise.all(values.map((promise) => promise.then(value => ({ status: 'fulfilled', value })).catch(reason => ({ status: 'rejected', reason }))));

}
const useColor = (options) => !(options && options.useColor === false || SETTINGS.color === false);
class Module {

@@ -47,4 +50,23 @@ constructor() {

}
static isString(value) {
return typeof value === 'string' && value.length > 0;
}
static generateUUID(format = '8-4-4-4-12') {
const match = format.match(/(\d+|[^\d]+)/g);
if (match) {
return match.reduce((a, b) => {
const length = +b;
if (!isNaN(length)) {
for (let i = 0; i < length; ++i) {
a += HEX_STRING[Math.floor(Math.random() * 16)];
}
return a;
}
return a + b;
}, '');
}
return uuid.v4();
}
static escapePattern(value) {
return typeof value === 'string' ? value.replace(/[-|\\{}()[\]^$+*?.]/g, capture => capture === '-' ? '\\x2d' : '\\' + capture) : '';
return this.isString(value) ? value.replace(/[-|\\{}()[\]^$+*?.]/g, capture => capture === '-' ? '\\x2d' : '\\' + capture) : '';
}

@@ -96,3 +118,3 @@ static formatMessage(type, title, value, message, options = {}) {

}
options.hintColor || (options.hintColor = 'magenta');
options.hintColor || (options.hintColor = 'yellow');
break;

@@ -105,7 +127,7 @@ default:

}
const useColor = !(options.useColor === false || SETTINGS.color === false);
const coloring = useColor(options);
if (Array.isArray(value)) {
const hint = value[1];
let length = 0;
if (typeof hint === 'string' && (length = hint.length)) {
let length;
if (this.isString(hint) && (length = hint.length)) {
const getHint = () => length > 32 ? hint.substring(0, 29) + '...' : hint;

@@ -125,3 +147,3 @@ const formatHint = (content) => {

let padding = ' '.repeat(32 - length);
if (useColor) {
if (coloring) {
padding = chalk.blackBright(padding);

@@ -131,3 +153,3 @@ }

}
value += useColor ? chalk.blackBright('[') + formatHint(getHint()) + chalk.blackBright(']') : `[${getHint()}]`;
value += coloring ? chalk.blackBright('[') + formatHint(getHint()) + chalk.blackBright(']') : `[${getHint()}]`;
}

@@ -141,3 +163,10 @@ else {

}
if (useColor) {
title = title.toUpperCase();
if (title.length < 7) {
title = (title + ' ').padStart(7);
}
if (message instanceof Error) {
message = message.message;
}
if (coloring) {
const { titleColor = 'green', titleBgColor = 'bgBlack', valueColor, valueBgColor, messageColor, messageBgColor } = options;

@@ -159,6 +188,6 @@ if (valueColor) {

}
console.log(chalk[titleBgColor].bold[titleColor](title.toUpperCase().padEnd(7)) + chalk.blackBright(':') + ' ' + value + (message || '')); // eslint-disable-line no-console
console.log(chalk[titleBgColor].bold[titleColor](title) + chalk.blackBright(':') + ' ' + value + (message || ''));
}
else {
console.log(title.toUpperCase().padEnd(7) + ':' + ' ' + value + (message && ` (${message})` || '')); // eslint-disable-line no-console
console.log(title + ': ' + value + (message ? ` (${message})` : ''));
}

@@ -204,3 +233,3 @@ }

static toPosix(value, filename) {
return value ? value.replace(/\\+/g, '/').replace(/\/+$/, '') + (filename ? '/' + filename : '') : '';
return this.isString(value) ? value.replace(/(?:^\\|\\+)/g, '/').replace(/\/+$/, '') + (filename ? '/' + filename : '') : '';
}

@@ -228,3 +257,3 @@ static renameExt(value, ext) {

}
static isDirectoryUNC(value) {
static isPathUNC(value) {
return /^(?:\\\\|\/\/)([\w.-]+)[\\/]([\w-]+\$|[\w-]+\$[\\/].+|[\w-]+[\\/].*)$/.test(value);

@@ -262,3 +291,3 @@ }

--pathname.length;
value = value.replace(/\\/g, '/');
value = this.toPosix(value);
if (value[0] === '/') {

@@ -292,3 +321,3 @@ return origin + value;

static joinPath(...values) {
values = values.filter(value => value && value.trim().replace(/\\/g, '/'));
values = values.filter(value => this.toPosix(value));
let result = '';

@@ -357,7 +386,16 @@ for (let i = 0; i < values.length; ++i) {

}
writeTimeProcess(title, value, time, options) {
time = Date.now() - time;
const progress = '>'.repeat(Math.ceil(time / 250));
Module.formatMessage(LOG_TYPE.TIME_ELAPSED, title, [value, time / 1000 + 's'], useColor(options) ? chalk.bgCyan(progress) : progress, options);
}
writeTimeElapsed(title, value, time, options) {
Module.formatMessage(LOG_TYPE.TIME_ELAPSED, title, ['Completed', (Date.now() - time) / 1000 + 's'], value, options);
Module.formatMessage(LOG_TYPE.TIME_ELAPSED, title, ['Complete', (Date.now() - time) / 1000 + 's'], value, options);
}
formatFail(type, title, value, message, options) {
Module.formatMessage(type, title, value, message, applyFailStyle(options));
const padding = 7 - title.length;
if (padding > 1) {
title = title.padStart(title.length + Math.floor(padding / 2));
}
Module.formatMessage(type, title.padEnd(7), value, message, applyFailStyle(options));
if (message) {

@@ -364,0 +402,0 @@ this.errors.push(message instanceof Error ? message.message : message.toString());

{
"name": "@squared-functions/module",
"version": "0.14.4",
"version": "1.0.0",
"description": "Module extension class for squared-functions",

@@ -18,3 +18,3 @@ "main": "index.js",

"dependencies": {
"@squared-functions/types": "^0.14.4",
"@squared-functions/types": "^1.0.0",
"uuid": "^8.3.2",

@@ -21,0 +21,0 @@ "chalk": "^4.1.1"

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