Socket
Socket
Sign inDemoInstall

@b613/utils

Package Overview
Dependencies
182
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0-beta2 to 1.0.0-beta20

lib/clist.d.ts

2

lib/client.d.ts
import { Trace } from './Trace';
import { AxiosInstance, AxiosRequestConfig } from 'axios';
import { IAxiosCacheAdapterOptions } from 'axios-cache-adapter';
import { Color } from './color';

@@ -8,4 +9,5 @@ export type Options = Omit<AxiosRequestConfig, 'baseURL'> & {

cache?: IAxiosCacheAdapterOptions;
color?: Color;
};
export function createClient(baseURL: string, options?: Options): AxiosInstance;

20

lib/client.js

@@ -6,8 +6,12 @@ "use strict";

const axios_1 = tslib_1.__importDefault(require("axios"));
const color_1 = tslib_1.__importDefault(require("./color"));
const axios_cache_adapter_1 = require("axios-cache-adapter");
function createClient(baseURL, _a = {}) {
var { headers = {}, logger, cache } = _a, options = tslib_1.__rest(_a, ["headers", "logger", "cache"]);
const adapter = cache ? (0, axios_cache_adapter_1.setupCache)(cache).adapter : undefined;
const instance = axios_1.default.create(Object.assign(Object.assign({}, options), { baseURL, headers, adapter }));
const axios_cache_adapter_1 = tslib_1.__importDefault(require("axios-cache-adapter"));
const fallbackColor = {
cyan: (str) => `${str}`,
red: (str) => `${str}`,
yellow: (str) => `${str}`,
green: (str) => `${str}`,
};
function createClient(baseURL, { headers = {}, logger, cache, color = fallbackColor, ...options } = {}) {
const adapter = cache ? axios_cache_adapter_1.default.setupCache(cache).adapter : undefined;
const instance = axios_1.default.create({ ...options, baseURL, headers, adapter });
instance.interceptors.response.use((response) => {

@@ -17,7 +21,7 @@ const method = response.request.method || 'GET';

if (response.status >= 400) {
logger === null || logger === void 0 ? void 0 : logger.info(`${prefix} ${color_1.default.red(response.status)}`, 'HTTP');
logger === null || logger === void 0 ? void 0 : logger.info(`${prefix} ${color.red(response.status)}`, 'HTTP');
logger === null || logger === void 0 ? void 0 : logger.error(`Error ${response.status}: ${JSON.stringify(response.data, null, 2)}`);
}
else {
logger === null || logger === void 0 ? void 0 : logger.info(`${prefix} ${color_1.default.green(response.status)}`, 'HTTP');
logger === null || logger === void 0 ? void 0 : logger.info(`${prefix} ${color.green(response.status)}`, 'HTTP');
}

@@ -24,0 +28,0 @@ return response;

@@ -1,2 +0,2 @@

interface Color {
export interface Color {
cyan: (str: string | number) => string;

@@ -3,0 +3,0 @@ red: (str: string | number) => string;

export default {
cyan: (str) => str,
red: (str) => str,
yellow: (str) => str,
green: (str) => str,
cyan: (str) => `${str}`,
red: (str) => `${str}`,
yellow: (str) => `${str}`,
green: (str) => `${str}`,
};
//# sourceMappingURL=color.browser.js.map
{
"name": "color",
"main": "color.node",
"browser": "color.browser"
"name": "color",
"main": "./color.node.js",
"browser": "./color.browser.js"
}

@@ -22,25 +22,20 @@ "use strict";

exports.parseMimeType = parseMimeType;
function parseBase64(filename) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const image = yield promises_1.default.readFile(filename);
return 'data:image/jpeg;base64,' + Buffer.from(image).toString('base64');
});
async function parseBase64(filename) {
const image = await promises_1.default.readFile(filename);
return 'data:image/jpeg;base64,' + Buffer.from(image).toString('base64');
}
exports.parseBase64 = parseBase64;
function pull(_a) {
var { dest = os_1.default.tmpdir(), extractFilename = true } = _a, options = tslib_1.__rest(_a, ["dest", "extractFilename"]);
return image_downloader_1.default.image(Object.assign({ dest, extractFilename }, options));
function pull({ dest = os_1.default.tmpdir(), extractFilename = true, ...options }) {
return image_downloader_1.default.image({ dest, extractFilename, ...options });
}
exports.pull = pull;
function resize(filename, width, height = jimp_1.default.AUTO) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const image = yield jimp_1.default.read(filename);
const newFilename = `${filename}.resized`;
yield image.resize(width, height, jimp_1.default.RESIZE_BEZIER).writeAsync(newFilename);
return {
filename: newFilename,
};
});
async function resize(filename, width, height = jimp_1.default.AUTO) {
const image = await jimp_1.default.read(filename);
const newFilename = `${filename}.resized`;
await image.resize(width, height, jimp_1.default.RESIZE_BEZIER).writeAsync(newFilename);
return {
filename: newFilename,
};
}
exports.resize = resize;
//# sourceMappingURL=image.node.js.map
{
"name": "image",
"main": "image.node",
"browser": "image.browser"
"name": "image",
"main": "./image.node.js",
"browser": "./image.browser.js"
}

@@ -1,2 +0,2 @@

import { Trace } from './Trace';
import { Trace } from './trace';

@@ -3,0 +3,0 @@ export type Options = {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.all = exports.chain = void 0;
const tslib_1 = require("tslib");
/**
* Sequential promise execution
*/
function chain(items, fn) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const results = [];
yield items.reduce((task, item, index) => {
return task
.then(() => fn(item, index))
.then((result) => results.push(result))
.then(() => Promise.resolve());
}, Promise.resolve());
return results;
});
async function chain(items, fn) {
const results = [];
await items.reduce((task, item, index) => {
return task
.then(() => fn(item, index))
.then((result) => results.push(result))
.then(() => Promise.resolve());
}, Promise.resolve());
return results;
}

@@ -24,8 +21,6 @@ exports.chain = chain;

*/
function all(items, fn) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return Promise.all(items.map((item, index) => fn(item, index)));
});
async function all(items, fn) {
return Promise.all(items.map((item, index) => fn(item, index)));
}
exports.all = all;
//# sourceMappingURL=promise.js.map

@@ -5,3 +5,3 @@ "use strict";

exports.generateEmptyValue = void 0;
const object_1 = require("./object");
const object_js_1 = require("./object.js");
const Filters = {

@@ -26,3 +26,3 @@ object: (item) => typeof item === 'object' && item !== null,

.filter(Filters.object)
.reduce((data, item) => (0, object_1.merge)(data, item), {});
.reduce((data, item) => (0, object_js_1.merge)(data, item), {});
}

@@ -44,3 +44,3 @@ return dataItems[0];

const propSchema = schema.properties[prop];
if ((0, object_1.isObject)(propSchema) && (((_a = schema.required) === null || _a === void 0 ? void 0 : _a.includes(prop)) || 'default' in propSchema || 'const' in propSchema)) {
if ((0, object_js_1.isObject)(propSchema) && (((_a = schema.required) === null || _a === void 0 ? void 0 : _a.includes(prop)) || 'default' in propSchema || 'const' in propSchema)) {
object[prop] = generateEmptyValue(propSchema, useDefault);

@@ -47,0 +47,0 @@ }

@@ -0,3 +1,9 @@

export type ParseCaseOptions = {
escapedChars?: string[];
separator: string;
};
export function trimlines(str: string, separator?: string): string;
export function toKebabCase(str: string): string;
export function unCamelCase(str: string, separator?: string): string;
export function parseCase(str: string, options: ParseCaseOptions): string;
export function toKebabCase(str: string, escapedChars?: string[]): string;
export function unCamelCase(str: string, escapedChars?: string[]): string;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.unCamelCase = exports.toKebabCase = exports.trimlines = void 0;
exports.unCamelCase = exports.toKebabCase = exports.parseCase = exports.trimlines = void 0;
const RE_TRIMLINES = /(.+)(\n|\r\n)?/g;

@@ -13,2 +13,3 @@ const CHAR_CODE_0 = '0'.charCodeAt(0);

const CHAR_CODE_Z = 'Z'.charCodeAt(0);
const KEBAB_SEPARATOR = '-';
function trimlines(str, separator = '') {

@@ -28,45 +29,51 @@ let index = 0;

exports.trimlines = trimlines;
function toKebabCase(str) {
const tokens = [];
function isLowerCode(code) {
// eslint-disable-next-line camelcase
return code >= CHAR_CODE_a && code <= CHAR_CODE_z;
}
function isNumberCode(code) {
// eslint-disable-next-line camelcase
return code >= CHAR_CODE_0 && code <= CHAR_CODE_9;
}
// eslint-disable-next-line radar/cognitive-complexity
function parseCase(str, { escapedChars = [], separator }) {
let output = '';
for (let index = 0; index < str.length; index++) {
const char = str.charAt(index);
const code = str.charCodeAt(index);
if (code >= CHAR_CODE_A && code <= CHAR_CODE_Z) {
if (index && tokens[index - 1] !== '-') {
tokens.push('-');
}
tokens.push(String.fromCharCode(code + 32));
// eslint-disable-next-line camelcase
if (escapedChars.includes(char)) {
output += char;
}
else if ((code >= CHAR_CODE_a && code <= CHAR_CODE_z) || (code >= CHAR_CODE_0 && code <= CHAR_CODE_9)) {
tokens.push(char);
}
else {
tokens.push('-');
const code = str.charCodeAt(index);
if (code >= CHAR_CODE_A && code <= CHAR_CODE_Z) {
if (index) {
const previousToken = output.at(-1);
if (previousToken !== separator && !escapedChars.includes(previousToken)) {
const previousCode = str.charCodeAt(index - 1);
if (isLowerCode(previousCode) || isNumberCode(previousCode)) {
output += separator;
}
}
}
output += String.fromCharCode(code + 32);
}
else if (isLowerCode(code) || isNumberCode(code)) {
output += char;
}
else {
output += separator;
}
}
}
return tokens.join('');
return output;
}
exports.parseCase = parseCase;
function toKebabCase(str, escapedChars = []) {
return parseCase(str, { escapedChars, separator: '-' });
}
exports.toKebabCase = toKebabCase;
function unCamelCase(str, separator = ' ') {
const tokens = [];
for (let index = 0; index < str.length; index++) {
const code = str.charCodeAt(index);
// eslint-disable-next-line camelcase
if ((code >= CHAR_CODE_a && code <= CHAR_CODE_z) || (code >= CHAR_CODE_0 && code <= CHAR_CODE_9)) {
tokens.push(str.charAt(index));
}
else if (code >= CHAR_CODE_A && code <= CHAR_CODE_Z) {
if (index && tokens[index - 1] !== separator) {
tokens.push(separator);
}
tokens.push(String.fromCharCode(code + 32));
}
else if (index) {
tokens.push(separator);
}
}
return tokens.join('');
function unCamelCase(str, escapedChars = []) {
return parseCase(str, { escapedChars, separator: ' ' });
}
exports.unCamelCase = unCamelCase;
//# sourceMappingURL=string.js.map
{
"name": "@b613/utils",
"version": "1.0.0-beta2",
"version": "1.0.0-beta20",
"description": "Set of utility methods for common operations",
"license": "MIT",
"type": "commonjs",
"scripts": {
"lint": "eslint .",
"test": "jest --detectOpenHandles --coverage",
"watch": "jest --detectOpenHandles --no-coverage --watchAll",
"build": "rm -rf lib* && tsc && tsc -p tsconfig.browser.json && cp src/*.d.ts lib/ && mkdir -p libtmp && cp --parents src/*/package.json libtmp/ && cp -r libtmp/src/* lib/"
"test": "NODE_OPTIONS=--experimental-vm-modules node_modules/.bin/jest --coverage",
"watch": "NODE_OPTIONS=--experimental-vm-modules node_modules/.bin/jest --no-coverage --watchAll",
"build": "tsc && tsc -p tsconfig.browser.json && cp src/*.d.ts lib/"
},

@@ -34,3 +35,2 @@ "repository": {

"author": "Sébastien Demanou",
"types": "typings.d.ts",
"dependencies": {

@@ -42,5 +42,5 @@ "axios": "0.27.2",

"express": "^4.18.1",
"image-downloader": "^4.2.0",
"jimp": "^0.16.1",
"morgan": "^1.10.0",
"image-downloader": "^4.2.0",
"tslib": "^2.4.0"

@@ -51,5 +51,5 @@ },

"@types/express": "^4.17.13",
"@types/jest": "^27.4.0",
"@types/jest": "^28.1.2",
"@types/morgan": "^1.9.3",
"@types/node": "^17.0.30",
"@types/node": "^18.0.0",
"@typescript-eslint/eslint-plugin": "^5.21.0",

@@ -62,7 +62,10 @@ "@typescript-eslint/parser": "^5.21.0",

"eslint-plugin-radar": "^0.2.1",
"jest": "^27.5.1",
"jest": "^28.1.1",
"nock": "^13.2.4",
"ts-jest": "^27.1.3",
"ts-jest": "^28.0.5",
"typescript": "^4.6.4"
},
"engines": {
"node": ">=16.6"
}
}

@@ -6,2 +6,3 @@ # Common Utils

[![Test coverage](https://gitlab.com/demsking/xutils/badges/main/coverage.svg)](https://gitlab.com/demsking/xutils/pipelines)
[![Buy me a beer](https://img.shields.io/badge/Buy%20me-a%20beer-1f425f.svg)](https://www.buymeacoffee.com/demsking)

@@ -19,20 +20,20 @@ This package provides utility methods for common operations which cover a wide

| Module | Documentation |
| ------------------------------- | ----------------------------------------------------------------------------------------- |
| `@b613/utils/lib/array` | [array.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/array.d.ts) |
| `@b613/utils/lib/CircularList` | [CircularList.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/CircularList.d.ts) |
| `@b613/utils/lib/client` | [client.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/client.d.ts) |
| `@b613/utils/lib/color` | [color.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/color.d.ts) |
| `@b613/utils/lib/http` | [http.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/http.d.ts) |
| `@b613/utils/lib/image` | [image.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/image.d.ts) |
| `@b613/utils/lib/number` | [number.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/number.d.ts) |
| `@b613/utils/lib/object` | [object.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/object.d.ts) |
| `@b613/utils/lib/ping` | [ping.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/ping.d.ts) |
| `@b613/utils/lib/promise` | [promise.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/promise.d.ts) |
| `@b613/utils/lib/qs` | [qs.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/qs.d.ts) |
| `@b613/utils/lib/regex` | [regex.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/regex.d.ts) |
| `@b613/utils/lib/schema` | [schema.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/schema.d.ts) |
| `@b613/utils/lib/Server` | [Server.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/Server.d.ts) |
| `@b613/utils/lib/string` | [string.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/string.d.ts) |
| `@b613/utils/lib/Trace` | [Trace.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/Trace.d.ts) |
| Module | Documentation |
| ------------------------- | ----------------------------------------------------------------------------------------- |
| `@b613/utils/lib/array` | [array.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/array.d.ts) |
| `@b613/utils/lib/clist` | [CircularList.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/CircularList.d.ts) |
| `@b613/utils/lib/client` | [client.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/client.d.ts) |
| `@b613/utils/lib/color` | [color.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/color.d.ts) |
| `@b613/utils/lib/http` | [color.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/http.d.ts) |
| `@b613/utils/lib/image` | [image.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/image.d.ts) |
| `@b613/utils/lib/number` | [number.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/number.d.ts) |
| `@b613/utils/lib/object` | [object.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/object.d.ts) |
| `@b613/utils/lib/ping` | [ping.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/ping.d.ts) |
| `@b613/utils/lib/promise` | [promise.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/promise.d.ts) |
| `@b613/utils/lib/qs` | [qs.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/qs.d.ts) |
| `@b613/utils/lib/regex` | [regex.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/regex.d.ts) |
| `@b613/utils/lib/schema` | [schema.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/schema.d.ts) |
| `@b613/utils/lib/server` | [Server.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/server.d.ts) |
| `@b613/utils/lib/string` | [string.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/string.d.ts) |
| `@b613/utils/lib/trace` | [trace.d.ts](https://gitlab.com/demsking/xutils/-/blob/main/src/trace.d.ts) |

@@ -39,0 +40,0 @@ ## Development Setup

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc