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

concolor

Package Overview
Dependencies
Maintainers
4
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

concolor - npm Package Compare versions

Comparing version 0.1.8 to 0.1.9

97

concolor.js
'use strict';
const colors = [
const COLORS = [
/* 1 */ 'black',

@@ -14,3 +14,3 @@ /* 2 */ 'red',

const ansi = [
const ANSI = [
/* 1 */ 'b', // bold (increased intensity)

@@ -29,21 +29,19 @@ /* 2 */ 'f', // faint (decreased intensity)

const stylize = (
// Create escape sequence from concolor style definition
styles, // String, comma separated styles
val // String, value to stylize
) => {
let style, color, index;
// Create escape sequence from concolor style definition
// styles:string - comma separated styles
// val:string - value to stylize
const stylize = (styles, val) => {
styles = styles.split(',');
for (style of styles) {
for (const style of styles) {
if (style.length === 1) {
const code = ansi.indexOf(style) + 1;
const code = ANSI.indexOf(style) + 1;
val = esc(code + 'm' + val);
} else {
color = style.split('/');
index = colors.indexOf(color[0]);
const color = style.split('/');
const index = COLORS.indexOf(color[0]);
if (index > -1) {
val = esc('3' + index + 'm' + val);
}
if (colors.length > 1) {
index = colors.indexOf(color[1]);
if (COLORS.length > 1) {
const index = COLORS.indexOf(color[1]);
if (index > -1) {

@@ -58,10 +56,8 @@ val = esc('4' + index + 'm' + val);

const tag = (
// Create tag function
styles // String, wrap tag into styles
) => (
strings, // Array of String or String
...values // Array of String
) => {
if (typeof(strings) === 'string') {
// Create tag function
// styles:string - wrap tag into styles
// strings:array - array of string or string
// values:array - array of string
const tag = styles => (strings, ...values) => {
if (typeof strings === 'string') {
return stylize(styles, strings);

@@ -71,6 +67,5 @@ }

const result = [strings[0]];
let val, str;
let i = 1;
for (val of values) {
str = strings[i++];
for (const val of values) {
const str = strings[i++];
result.push(val, str);

@@ -81,17 +76,15 @@ }

const theme = (
// Create theme tag
tags // String, theme tags
) => {
const styles = (
strings, // Array of String or String
...values // Array of String
) => {
// Create theme tag
// tags:string - theme tags
const theme = tags => {
const styles = (strings, ...values) => {
const result = [strings[0]];
let val, str, name;
let i = 1;
for (val of values) {
str = strings[i++];
for (name in val) {
result.push(styles[name](val[name]));
for (const val of values) {
const str = strings[i++];
for (const name in val) {
const style = styles[name];
const value = val[name];
const res = style(value);
result.push(res);
}

@@ -103,4 +96,3 @@ result.push(str);

let name;
for (name in tags) {
for (const name in tags) {
styles[name] = tag(tags[name]);

@@ -111,7 +103,7 @@ }

const concolor = (
strings, // Array of String or String
...values // Array of String
) => {
if (typeof(strings) === 'string') {
// Concolor main function
// strings:array - array of string or string
// values:array - array of string
const concolor = (strings, ...values) => {
if (typeof strings === 'string') {
return tag(strings);

@@ -125,12 +117,11 @@ }

const result = [strings[0]];
let val, str, pos, styles;
let i = 1;
for (val of values) {
str = strings[i++];
for (const val of values) {
const str = strings[i++];
if (str.startsWith('(')) {
pos = str.indexOf(')');
styles = str.substring(1, pos);
val = stylize(styles, val);
str = str.substring(pos + 1);
result.push(val, str);
const pos = str.indexOf(')');
const styles = str.substring(1, pos);
const value = stylize(styles, val);
const rest = str.substring(pos + 1);
result.push(value, rest);
}

@@ -137,0 +128,0 @@ }

{
"name": "concolor",
"version": "0.1.8",
"version": "0.1.9",
"author": "Vladyslav Dukhin <vladyslav.dukhin@gmail.com>",

@@ -5,0 +5,0 @@ "description": "Console colors for strings templates in node.js",

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