🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

message-tag

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

message-tag - npm Package Compare versions

Comparing version
0.8.1
to
0.9.0
+129
dist/node-cjs/message.cjs
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.raw = exports.msgTag = exports.default = exports.custom = void 0;
var _dateformat = _interopRequireDefault(require("dateformat"));
var _prettyFormat = require("pretty-format");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// Generic builder for template literal tags
const createTag = encode => function (stringParts) {
for (var _len = arguments.length, substitutions = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
substitutions[_key - 1] = arguments[_key];
}
return substitutions.reduce((prev, cur, i) => prev + encode(cur) + stringParts[i + 1], stringParts[0]);
};
// Version of `obj.hasOwnProperty()` that works regardless of prototype
const hasOwnProperty = (obj, propName) => Object.prototype.hasOwnProperty.call(obj, propName);
const customKey = Symbol('msg.custom');
const quote = value => `\`${value}\``;
const formatObject = (obj, options) => {
return (0, _prettyFormat.format)(obj, options).replace(/^Object /, ''); // Remove 'Object' tag
};
const format = function (value) {
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (typeof value === 'object' && value && customKey in value) {
if (value.type === 'raw') {
return value.value;
}
if (typeof value.options === 'object' && value.options) {
options = value.options;
value = value.value;
}
}
if (value === undefined) {
return quote('undefined');
} else if (value === null) {
return quote('null');
} else if (typeof value === 'boolean') {
return quote(String(value));
} else if (typeof value === 'symbol') {
return quote(value.toString()); // `Symbol(<symbol-name>)`
} else if (typeof value === 'string') {
return JSON.stringify(value); // Don't quote, just encode as a string literal
} else if (typeof value === 'number') {
if (isNaN(value)) {
return 'NaN';
} else if (value === +Infinity) {
return '+Infinity';
} else if (value === -Infinity) {
return '-Infinity';
}
return String(value);
} else if (Array.isArray(value)) {
// Currently just JSON encodes the entire array. We may want to format this a bit nicer.
return quote(JSON.stringify(value));
} else if (typeof value === 'function') {
return quote(value.toString());
} else if (value instanceof Date) {
if (Number.isNaN(value.valueOf())) {
return '[invalid Date]';
} else {
// Note: `dateFormat` throws a TypeError if the given Date is invalid (i.e. value is NaN)
return (0, _dateformat.default)(value, options.dateFormat || 'isoUtcDateTime');
}
} else if (value instanceof RegExp) {
return quote(value.toString());
} else if (value instanceof Error) {
// For error messages, print the message raw. We expect the message to be already formatted
// for display, so encoding it would mess up the formatting.
return `[${value.constructor.name}] ${value.message}`;
} else if (typeof value === 'object') {
const proto = Object.getPrototypeOf(value);
if (proto === null || proto === Object.prototype) {
// Currently just JSON encodes the entire object. We may want to format this a bit nicer.
return quote(formatObject(value, options.format));
}
if (hasOwnProperty(proto, 'constructor') && typeof proto.constructor === 'function') {
const constructor = proto.constructor;
const tag = constructor.name || 'Unknown';
let stringRep;
if ('toJSON' in value) {
// Note: `toJSON` is not included in `Object.prototype`, so will only be present in types
// that explicitly implement JSON encoding.
stringRep = quote(formatObject(value, options.format));
} else if ('toString' in value && value.toString !== Object.prototype.toString) {
// Note: `toString` is included in `Object.prototype`. However, the default implementation is
// generally not very helpful (e.g. `[Object object]`). So we explicitly ignore it.
stringRep = JSON.stringify(value.toString()); // Encode as string literal
} else {
// Fallback: take all enumerable properties and format as object
stringRep = quote(formatObject({
...value
}, options.format));
}
return `[${tag}] ${stringRep}`;
}
}
// Fallback
return JSON.stringify(value);
};
const msgTag = options => createTag(value => format(value, options));
exports.msgTag = msgTag;
const msg = msgTag({
format: {
maxDepth: 4,
min: true
},
dateFormat: 'isoUtcDateTime'
});
const raw = msg.raw = value => ({
[customKey]: true,
type: 'raw',
value
});
exports.raw = raw;
const custom = msg.custom = (options, value) => ({
[customKey]: true,
options,
value
});
exports.custom = custom;
var _default = msg;
exports.default = _default;
//# sourceMappingURL=message.cjs.map
{"version":3,"file":"message.cjs","names":["_dateformat","_interopRequireDefault","require","_prettyFormat","obj","__esModule","default","createTag","encode","stringParts","_len","arguments","length","substitutions","Array","_key","reduce","prev","cur","i","hasOwnProperty","propName","Object","prototype","call","customKey","Symbol","quote","value","formatObject","options","prettyFormat","replace","format","undefined","type","String","toString","JSON","stringify","isNaN","Infinity","isArray","Date","Number","valueOf","dateFormat","RegExp","Error","constructor","name","message","proto","getPrototypeOf","tag","stringRep","msgTag","exports","msg","maxDepth","min","raw","custom","_default"],"sources":["../../src/message.js"],"sourcesContent":["\nimport dateFormat from 'dateformat';\nimport { format as prettyFormat } from 'pretty-format';\n\n\n// Generic builder for template literal tags\nconst createTag = encode => (stringParts, ...substitutions) =>\n substitutions.reduce(\n (prev, cur, i) => prev + encode(cur) + stringParts[i + 1],\n stringParts[0]\n );\n\n// Version of `obj.hasOwnProperty()` that works regardless of prototype\nconst hasOwnProperty = (obj, propName) => Object.prototype.hasOwnProperty.call(obj, propName);\n\n\nconst customKey = Symbol('msg.custom');\n\nconst quote = value => `\\`${value}\\``;\n\nconst formatObject = (obj, options) => {\n return prettyFormat(obj, options)\n .replace(/^Object /, ''); // Remove 'Object' tag\n};\n\nconst format = (value, options = {}) => {\n if (typeof value === 'object' && value && customKey in value) {\n if (value.type === 'raw') {\n return value.value;\n }\n \n if (typeof value.options === 'object' && value.options) {\n options = value.options;\n value = value.value;\n }\n }\n \n if (value === undefined) {\n return quote('undefined');\n } else if (value === null) {\n return quote('null');\n } else if (typeof value === 'boolean') {\n return quote(String(value));\n } else if (typeof value === 'symbol') {\n return quote(value.toString()); // `Symbol(<symbol-name>)`\n } else if (typeof value === 'string') {\n return JSON.stringify(value); // Don't quote, just encode as a string literal\n } else if (typeof value === 'number') {\n if (isNaN(value)) {\n return 'NaN';\n } else if (value === +Infinity) {\n return '+Infinity';\n } else if (value === -Infinity) {\n return '-Infinity';\n }\n \n return String(value);\n } else if (Array.isArray(value)) {\n // Currently just JSON encodes the entire array. We may want to format this a bit nicer.\n return quote(JSON.stringify(value));\n } else if (typeof value === 'function') {\n return quote(value.toString());\n } else if (value instanceof Date) {\n if (Number.isNaN(value.valueOf())) {\n return '[invalid Date]';\n } else {\n // Note: `dateFormat` throws a TypeError if the given Date is invalid (i.e. value is NaN)\n return dateFormat(value, options.dateFormat || 'isoUtcDateTime');\n }\n } else if (value instanceof RegExp) {\n return quote(value.toString());\n } else if (value instanceof Error) {\n // For error messages, print the message raw. We expect the message to be already formatted\n // for display, so encoding it would mess up the formatting.\n return `[${value.constructor.name}] ${value.message}`;\n } else if (typeof value === 'object') {\n const proto = Object.getPrototypeOf(value);\n if (proto === null || proto === Object.prototype) {\n // Currently just JSON encodes the entire object. We may want to format this a bit nicer.\n return quote(formatObject(value, options.format));\n }\n \n if (hasOwnProperty(proto, 'constructor') && typeof proto.constructor === 'function') {\n const constructor = proto.constructor;\n \n const tag = constructor.name || 'Unknown';\n \n let stringRep;\n if ('toJSON' in value) {\n // Note: `toJSON` is not included in `Object.prototype`, so will only be present in types\n // that explicitly implement JSON encoding.\n stringRep = quote(formatObject(value, options.format));\n } else if ('toString' in value && value.toString !== Object.prototype.toString) {\n // Note: `toString` is included in `Object.prototype`. However, the default implementation is\n // generally not very helpful (e.g. `[Object object]`). So we explicitly ignore it.\n \n stringRep = JSON.stringify(value.toString()); // Encode as string literal\n } else {\n // Fallback: take all enumerable properties and format as object\n stringRep = quote(formatObject({ ...value }, options.format));\n }\n \n return `[${tag}] ${stringRep}`;\n }\n }\n \n // Fallback\n return JSON.stringify(value);\n};\n\nexport const msgTag = options => createTag(value => format(value, options));\n\nconst msg = msgTag({\n format: {\n maxDepth: 4,\n min: true,\n },\n dateFormat: 'isoUtcDateTime',\n});\n\nexport const raw = msg.raw = value => ({ [customKey]: true, type: 'raw', value });\n\nexport const custom = msg.custom = (options, value) => ({ [customKey]: true, options, value });\n\nexport default msg;\n"],"mappings":";;;;;;AACA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AAAuD,SAAAD,u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AAA,CAAAK,MAAA,GAAAA,MAAA;AAAA,IAAAC,QAAA,GAEhFL,GAAG;AAAAD,OAAA,CAAAnD,OAAA,GAAAyD,QAAA"}
import dateFormat from 'dateformat';
import { format as prettyFormat } from 'pretty-format';
// Generic builder for template literal tags
const createTag = encode => function (stringParts) {
for (var _len = arguments.length, substitutions = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
substitutions[_key - 1] = arguments[_key];
}
return substitutions.reduce((prev, cur, i) => prev + encode(cur) + stringParts[i + 1], stringParts[0]);
};
// Version of `obj.hasOwnProperty()` that works regardless of prototype
const hasOwnProperty = (obj, propName) => Object.prototype.hasOwnProperty.call(obj, propName);
const customKey = Symbol('msg.custom');
const quote = value => `\`${value}\``;
const formatObject = (obj, options) => {
return prettyFormat(obj, options).replace(/^Object /, ''); // Remove 'Object' tag
};
const format = function (value) {
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (typeof value === 'object' && value && customKey in value) {
if (value.type === 'raw') {
return value.value;
}
if (typeof value.options === 'object' && value.options) {
options = value.options;
value = value.value;
}
}
if (value === undefined) {
return quote('undefined');
} else if (value === null) {
return quote('null');
} else if (typeof value === 'boolean') {
return quote(String(value));
} else if (typeof value === 'symbol') {
return quote(value.toString()); // `Symbol(<symbol-name>)`
} else if (typeof value === 'string') {
return JSON.stringify(value); // Don't quote, just encode as a string literal
} else if (typeof value === 'number') {
if (isNaN(value)) {
return 'NaN';
} else if (value === +Infinity) {
return '+Infinity';
} else if (value === -Infinity) {
return '-Infinity';
}
return String(value);
} else if (Array.isArray(value)) {
// Currently just JSON encodes the entire array. We may want to format this a bit nicer.
return quote(JSON.stringify(value));
} else if (typeof value === 'function') {
return quote(value.toString());
} else if (value instanceof Date) {
if (Number.isNaN(value.valueOf())) {
return '[invalid Date]';
} else {
// Note: `dateFormat` throws a TypeError if the given Date is invalid (i.e. value is NaN)
return dateFormat(value, options.dateFormat || 'isoUtcDateTime');
}
} else if (value instanceof RegExp) {
return quote(value.toString());
} else if (value instanceof Error) {
// For error messages, print the message raw. We expect the message to be already formatted
// for display, so encoding it would mess up the formatting.
return `[${value.constructor.name}] ${value.message}`;
} else if (typeof value === 'object') {
const proto = Object.getPrototypeOf(value);
if (proto === null || proto === Object.prototype) {
// Currently just JSON encodes the entire object. We may want to format this a bit nicer.
return quote(formatObject(value, options.format));
}
if (hasOwnProperty(proto, 'constructor') && typeof proto.constructor === 'function') {
const constructor = proto.constructor;
const tag = constructor.name || 'Unknown';
let stringRep;
if ('toJSON' in value) {
// Note: `toJSON` is not included in `Object.prototype`, so will only be present in types
// that explicitly implement JSON encoding.
stringRep = quote(formatObject(value, options.format));
} else if ('toString' in value && value.toString !== Object.prototype.toString) {
// Note: `toString` is included in `Object.prototype`. However, the default implementation is
// generally not very helpful (e.g. `[Object object]`). So we explicitly ignore it.
stringRep = JSON.stringify(value.toString()); // Encode as string literal
} else {
// Fallback: take all enumerable properties and format as object
stringRep = quote(formatObject({
...value
}, options.format));
}
return `[${tag}] ${stringRep}`;
}
}
// Fallback
return JSON.stringify(value);
};
export const msgTag = options => createTag(value => format(value, options));
const msg = msgTag({
format: {
maxDepth: 4,
min: true
},
dateFormat: 'isoUtcDateTime'
});
export const raw = msg.raw = value => ({
[customKey]: true,
type: 'raw',
value
});
export const custom = msg.custom = (options, value) => ({
[customKey]: true,
options,
value
});
export default msg;
//# sourceMappingURL=message.mjs.map
{"version":3,"file":"message.mjs","names":["dateFormat","format","prettyFormat","createTag","encode","stringParts","_len","arguments","length","substitutions","Array","_key","reduce","prev","cur","i","hasOwnProperty","obj","propName","Object","prototype","call","customKey","Symbol","quote","value","formatObject","options","replace","undefined","type","String","toString","JSON","stringify","isNaN","Infinity","isArray","Date","Number","valueOf","RegExp","Error","constructor","name","message","proto","getPrototypeOf","tag","stringRep","msgTag","msg","maxDepth","min","raw","custom"],"sources":["../../src/message.js"],"sourcesContent":["\nimport dateFormat from 'dateformat';\nimport { format as prettyFormat } from 'pretty-format';\n\n\n// Generic builder for template literal tags\nconst createTag = encode => (stringParts, ...substitutions) =>\n substitutions.reduce(\n (prev, cur, i) => prev + encode(cur) + stringParts[i + 1],\n stringParts[0]\n );\n\n// Version of `obj.hasOwnProperty()` that works regardless of prototype\nconst hasOwnProperty = (obj, propName) => Object.prototype.hasOwnProperty.call(obj, propName);\n\n\nconst customKey = Symbol('msg.custom');\n\nconst quote = value => `\\`${value}\\``;\n\nconst formatObject = (obj, options) => {\n return prettyFormat(obj, options)\n .replace(/^Object /, ''); // Remove 'Object' tag\n};\n\nconst format = (value, options = {}) => {\n if (typeof value === 'object' && value && customKey in value) {\n if (value.type === 'raw') {\n return value.value;\n }\n \n if (typeof value.options === 'object' && value.options) {\n options = value.options;\n value = value.value;\n }\n }\n \n if (value === undefined) {\n return quote('undefined');\n } else if (value === null) {\n return quote('null');\n } else if (typeof value === 'boolean') {\n return quote(String(value));\n } else if (typeof value === 'symbol') {\n return quote(value.toString()); // `Symbol(<symbol-name>)`\n } else if (typeof value === 'string') {\n return JSON.stringify(value); // Don't quote, just encode as a string literal\n } else if (typeof value === 'number') {\n if (isNaN(value)) {\n return 'NaN';\n } else if (value === +Infinity) {\n return '+Infinity';\n } else if (value === -Infinity) {\n return '-Infinity';\n }\n \n return String(value);\n } else if (Array.isArray(value)) {\n // Currently just JSON encodes the entire array. We may want to format this a bit nicer.\n return quote(JSON.stringify(value));\n } else if (typeof value === 'function') {\n return quote(value.toString());\n } else if (value instanceof Date) {\n if (Number.isNaN(value.valueOf())) {\n return '[invalid Date]';\n } else {\n // Note: `dateFormat` throws a TypeError if the given Date is invalid (i.e. value is NaN)\n return dateFormat(value, options.dateFormat || 'isoUtcDateTime');\n }\n } else if (value instanceof RegExp) {\n return quote(value.toString());\n } else if (value instanceof Error) {\n // For error messages, print the message raw. We expect the message to be already formatted\n // for display, so encoding it would mess up the formatting.\n return `[${value.constructor.name}] ${value.message}`;\n } else if (typeof value === 'object') {\n const proto = Object.getPrototypeOf(value);\n if (proto === null || proto === Object.prototype) {\n // Currently just JSON encodes the entire object. We may want to format this a bit nicer.\n return quote(formatObject(value, options.format));\n }\n \n if (hasOwnProperty(proto, 'constructor') && typeof proto.constructor === 'function') {\n const constructor = proto.constructor;\n \n const tag = constructor.name || 'Unknown';\n \n let stringRep;\n if ('toJSON' in value) {\n // Note: `toJSON` is not included in `Object.prototype`, so will only be present in types\n // that explicitly implement JSON encoding.\n stringRep = quote(formatObject(value, options.format));\n } else if ('toString' in value && value.toString !== Object.prototype.toString) {\n // Note: `toString` is included in `Object.prototype`. However, the default implementation is\n // generally not very helpful (e.g. `[Object object]`). So we explicitly ignore it.\n \n stringRep = JSON.stringify(value.toString()); // Encode as string literal\n } else {\n // Fallback: take all enumerable properties and format as object\n stringRep = quote(formatObject({ ...value }, options.format));\n }\n \n return `[${tag}] ${stringRep}`;\n }\n }\n \n // Fallback\n return JSON.stringify(value);\n};\n\nexport const msgTag = options => createTag(value => format(value, options));\n\nconst msg = msgTag({\n format: {\n maxDepth: 4,\n min: true,\n },\n dateFormat: 'isoUtcDateTime',\n});\n\nexport const raw = msg.raw = value => ({ [customKey]: true, type: 'raw', value });\n\nexport const custom = msg.custom = (options, value) => ({ [customKey]: true, options, value });\n\nexport default msg;\n"],"mappings":"AACA,OAAOA,UAAU,MAAM,YAAY;AACnC,SAASC,MAAM,IAAIC,YAAY,QAAQ,eAAe;;AAGtD;AACA,MAAMC,SAAS,GAAGC,MAAM,IAAI,UAACC,WAAW;EAAA,SAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAAKC,aAAa,OAAAC,KAAA,CAAAJ,IAAA,OAAAA,IAAA,WAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;IAAbF,aAAa,CAAAE,IAAA,QAAAJ,SAAA,CAAAI,IAAA;EAAA;EAAA,OACtDF,aAAa,CAACG,MAAM,CAChB,CAACC,IAAI,EAAEC,GAAG,EAAEC,CAAC,KAAKF,IAAI,GAAGT,MAAM,CAACU,G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AIC,SAAU,EAAC;IAClC;EACJ;;EAEA;EACA,OAAOhB,IAAI,CAACC,SAAS,CAACT,KAAK,CAAC;AAChC,CAAC;AAED,OAAO,MAAMyB,MAAM,GAAGvB,OAAO,IAAIxB,SAAS,CAACsB,KAAK,IAAIxB,MAAM,CAACwB,KAAK,EAAEE,OAAO,CAAC,CAAC;AAE3E,MAAMwB,GAAG,GAAGD,MAAM,CAAC;EACfjD,MAAM,EAAE;IACJmD,QAAQ,EAAE,CAAC;IACXC,GAAG,EAAE;EACT,CAAC;EACDrD,UAAU,EAAE;AAChB,CAAC,CAAC;AAEF,OAAO,MAAMsD,GAAG,GAAGH,GAAG,CAACG,GAAG,GAAG7B,KAAK,KAAK;EAAE,CAACH,SAAS,GAAG,IAAI;EAAEQ,IAAI,EAAE,KAAK;EAAEL;AAAM,CAAC,CAAC;AAEjF,OAAO,MAAM8B,MAAM,GAAGJ,GAAG,CAACI,MAAM,GAAG,CAAC5B,OAAO,EAAEF,KAAK,MAAM;EAAE,CAACH,SAAS,GAAG,IAAI;EAAEK,OAAO;EAAEF;AAAM,CAAC,CAAC;AAE9F,eAAe0B,GAAG"}
import { Config as PrettyFormatConfig } from 'pretty-format';
type MessageTag = (stringParts: TemplateStringsArray, ...substitutions: unknown[]) => string;
type CustomOptions = {
format?: Partial<PrettyFormatConfig>,
dateFormat?: string,
};
// Note: structure of the result types can be left opaque (internal structure)
export declare const raw: (value: unknown) => object;
export declare const custom: (options: CustomOptions, value: unknown) => object;
export declare const msgTag: (options: CustomOptions) => MessageTag;
declare const msg: MessageTag & {
raw: typeof raw,
custom: typeof msgTag,
};
export default msg;
import { Config as PrettyFormatConfig } from 'pretty-format';
type MessageTag = (stringParts: TemplateStringsArray, ...substitutions: unknown[]) => string;
type CustomOptions = {
format?: Partial<PrettyFormatConfig>,
dateFormat?: string,
};
// Note: structure of the result types can be left opaque (internal structure)
export declare const raw: (value: unknown) => object;
export declare const custom: (options: CustomOptions, value: unknown) => object;
export declare const msgTag: (options: CustomOptions) => MessageTag;
declare const msg: MessageTag & {
raw: typeof raw,
custom: typeof msgTag,
};
export default msg;
+7
-0
# Change Log
- v0.9
- Upgrade message-tag to use modern Node.js 14+ features.
- Drop support for Node 12.
- Use `exports` in package.json rather than `main`.
- Upgrade all dependencies to latest versions.
- Move dist files to new `dist` directory containing ESM, CommonJS, and TypeScript build files.
- v0.8

@@ -5,0 +12,0 @@ - Invalid `Date` instances are now formatted as `[invalid Date]`, rather than throwing a TypeError as before.

+21
-14
{
"name": "message-tag",
"version": "0.8.1",
"version": "0.9.0",
"author": "mkrause",

@@ -20,19 +20,26 @@ "license": "MIT",

"src/",
"lib-cjs/",
"lib-esm/",
"typings/message.d.ts"
"dist/"
],
"//": "Note: Node v14.15 'Fermium' is the first v14.x LTS release",
"engines": {
"node": ">= 12.13"
"node": ">= 14.15"
},
"main": "./lib-cjs/message.cjs",
"module": "./lib-esm/message.mjs",
"types": "./typings/message.d.ts",
"type": "module",
"exports": {
"./package.json": "./package.json",
".": {
"types": "./dist/types/message.d.ts",
"import": "./dist/node-esm/message.mjs",
"require": "./dist/node-cjs/message.cjs",
"default": "./dist/node-esm/message.mjs"
}
},
"sideEffects": false,
"scripts": {
"_build": "babel src --source-maps=true",
"build:cjs": "NODE_ENV=production BABEL_ENV=cjs npm run _build -- --out-dir lib-cjs --out-file-extension=.cjs --delete-dir-on-start",
"build:esm": "NODE_ENV=production BABEL_ENV=esm npm run _build -- --out-dir lib-esm --out-file-extension=.mjs --delete-dir-on-start",
"test": "NODE_ENV=test BABEL_ENV=cjs mocha --require @babel/register --recursive tests && tsd && echo '[tsd] success'",
"prepublishOnly": "npm run build:esm && npm run build:cjs"
"_build": "NODE_ENV=production babel src --source-maps=true --delete-dir-on-start",
"build:cjs": "BABEL_ENV=cjs npm run _build -- --out-dir=dist/node-cjs --out-file-extension=.cjs",
"build:esm": "BABEL_ENV=esm npm run _build -- --out-dir=dist/node-esm --out-file-extension=.mjs",
"build:types": "mkdir -p ./dist/types && cp src/message.d.ts ./dist/types",
"test": "NODE_ENV=test BABEL_ENV=cjs mocha --require @babel/register --recursive tests && npm run build:types && tsd --typings=src/message.d.ts --files=tests/message.test-d.ts && echo '[tsd] success'",
"prepublishOnly": "npm run build:esm && npm run build:cjs && npm run build:types"
},

@@ -51,4 +58,4 @@ "devDependencies": {

"pretty-format": "^29.5.0",
"dateformat": "^4.6.3"
"dateformat": "^5.0.3"
}
}
# message-tag
[![npm](https://img.shields.io/npm/v/message-tag.svg?style=flat-square)](https://www.npmjs.com/package/message-tag)
[![Travis](https://img.shields.io/travis/mkrause/message-tag.svg?style=flat-square)](https://travis-ci.org/mkrause/message-tag)
[![npm](https://img.shields.io/npm/v/message-tag.svg)](https://www.npmjs.com/package/message-tag)
![GitHub Actions](https://github.com/mkrause/message-tag/actions/workflows/nodejs.yml/badge.svg)
[![Types](https://img.shields.io/npm/types/message-tag)](https://img.shields.io/npm/types/message-tag)

@@ -7,0 +8,0 @@ A [template literal tag](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) to format arbitrary values in a string template. Useful for error messages, logs, etc.

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.raw = exports.msgTag = exports.default = exports.custom = void 0;
var _dateformat = _interopRequireDefault(require("dateformat"));
var _prettyFormat = require("pretty-format");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// Generic builder for template literal tags
const createTag = encode => function (stringParts) {
for (var _len = arguments.length, substitutions = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
substitutions[_key - 1] = arguments[_key];
}
return substitutions.reduce((prev, cur, i) => prev + encode(cur) + stringParts[i + 1], stringParts[0]);
};
// Version of `obj.hasOwnProperty()` that works regardless of prototype
const hasOwnProperty = (obj, propName) => Object.prototype.hasOwnProperty.call(obj, propName);
const customKey = Symbol('msg.custom');
const quote = value => `\`${value}\``;
const formatObject = (obj, options) => {
return (0, _prettyFormat.format)(obj, options).replace(/^Object /, ''); // Remove 'Object' tag
};
const format = function (value) {
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (typeof value === 'object' && value && customKey in value) {
if (value.type === 'raw') {
return value.value;
}
if (typeof value.options === 'object' && value.options) {
options = value.options;
value = value.value;
}
}
if (value === undefined) {
return quote('undefined');
} else if (value === null) {
return quote('null');
} else if (typeof value === 'boolean') {
return quote(String(value));
} else if (typeof value === 'symbol') {
return quote(value.toString()); // `Symbol(<symbol-name>)`
} else if (typeof value === 'string') {
return JSON.stringify(value); // Don't quote, just encode as a string literal
} else if (typeof value === 'number') {
if (isNaN(value)) {
return 'NaN';
} else if (value === +Infinity) {
return '+Infinity';
} else if (value === -Infinity) {
return '-Infinity';
}
return String(value);
} else if (Array.isArray(value)) {
// Currently just JSON encodes the entire array. We may want to format this a bit nicer.
return quote(JSON.stringify(value));
} else if (typeof value === 'function') {
return quote(value.toString());
} else if (value instanceof Date) {
if (Number.isNaN(value.valueOf())) {
return '[invalid Date]';
} else {
// Note: `dateFormat` throws a TypeError if the given Date is invalid (i.e. value is NaN)
return (0, _dateformat.default)(value, options.dateFormat || 'isoUtcDateTime');
}
} else if (value instanceof RegExp) {
return quote(value.toString());
} else if (value instanceof Error) {
// For error messages, print the message raw. We expect the message to be already formatted
// for display, so encoding it would mess up the formatting.
return `[${value.constructor.name}] ${value.message}`;
} else if (typeof value === 'object') {
const proto = Object.getPrototypeOf(value);
if (proto === null || proto === Object.prototype) {
// Currently just JSON encodes the entire object. We may want to format this a bit nicer.
return quote(formatObject(value, options.format));
}
if (hasOwnProperty(proto, 'constructor') && typeof proto.constructor === 'function') {
const constructor = proto.constructor;
const tag = constructor.name || 'Unknown';
let stringRep;
if ('toJSON' in value) {
// Note: `toJSON` is not included in `Object.prototype`, so will only be present in types
// that explicitly implement JSON encoding.
stringRep = quote(formatObject(value, options.format));
} else if ('toString' in value && value.toString !== Object.prototype.toString) {
// Note: `toString` is included in `Object.prototype`. However, the default implementation is
// generally not very helpful (e.g. `[Object object]`). So we explicitly ignore it.
stringRep = JSON.stringify(value.toString()); // Encode as string literal
} else {
// Fallback: take all enumerable properties and format as object
stringRep = quote(formatObject({
...value
}, options.format));
}
return `[${tag}] ${stringRep}`;
}
}
// Fallback
return JSON.stringify(value);
};
const msgTag = options => createTag(value => format(value, options));
exports.msgTag = msgTag;
const msg = msgTag({
format: {
maxDepth: 4,
min: true
},
dateFormat: 'isoUtcDateTime'
});
const raw = msg.raw = value => ({
[customKey]: true,
type: 'raw',
value
});
exports.raw = raw;
const custom = msg.custom = (options, value) => ({
[customKey]: true,
options,
value
});
exports.custom = custom;
var _default = msg;
exports.default = _default;
//# sourceMappingURL=message.cjs.map
{"version":3,"file":"message.cjs","names":["_dateformat","_interopRequireDefault","require","_prettyFormat","obj","__esModule","default","createTag","encode","stringParts","_len","arguments","length","substitutions","Array","_key","reduce","prev","cur","i","hasOwnProperty","propName","Object","prototype","call","customKey","Symbol","quote","value","formatObject","options","prettyFormat","replace","format","undefined","type","String","toString","JSON","stringify","isNaN","Infinity","isArray","Date","Number","valueOf","dateFormat","RegExp","Error","constructor","name","message","proto","getPrototypeOf","tag","stringRep","msgTag","exports","msg","maxDepth","min","raw","custom","_default"],"sources":["../src/message.js"],"sourcesContent":["\nimport dateFormat from 'dateformat';\nimport { format as prettyFormat } from 'pretty-format';\n\n\n// Generic builder for template literal tags\nconst createTag = encode => (stringParts, ...substitutions) =>\n substitutions.reduce(\n (prev, cur, i) => prev + encode(cur) + stringParts[i + 1],\n stringParts[0]\n );\n\n// Version of `obj.hasOwnProperty()` that works regardless of prototype\nconst hasOwnProperty = (obj, propName) => Object.prototype.hasOwnProperty.call(obj, propName);\n\n\nconst customKey = Symbol('msg.custom');\n\nconst quote = value => `\\`${value}\\``;\n\nconst formatObject = (obj, options) => {\n return prettyFormat(obj, options)\n .replace(/^Object /, ''); // Remove 'Object' tag\n};\n\nconst format = (value, options = {}) => {\n if (typeof value === 'object' && value && customKey in value) {\n if (value.type === 'raw') {\n return value.value;\n }\n \n if (typeof value.options === 'object' && value.options) {\n options = value.options;\n value = value.value;\n }\n }\n \n if (value === undefined) {\n return quote('undefined');\n } else if (value === null) {\n return quote('null');\n } else if (typeof value === 'boolean') {\n return quote(String(value));\n } else if (typeof value === 'symbol') {\n return quote(value.toString()); // `Symbol(<symbol-name>)`\n } else if (typeof value === 'string') {\n return JSON.stringify(value); // Don't quote, just encode as a string literal\n } else if (typeof value === 'number') {\n if (isNaN(value)) {\n return 'NaN';\n } else if (value === +Infinity) {\n return '+Infinity';\n } else if (value === -Infinity) {\n return '-Infinity';\n }\n \n return String(value);\n } else if (Array.isArray(value)) {\n // Currently just JSON encodes the entire array. We may want to format this a bit nicer.\n return quote(JSON.stringify(value));\n } else if (typeof value === 'function') {\n return quote(value.toString());\n } else if (value instanceof Date) {\n if (Number.isNaN(value.valueOf())) {\n return '[invalid Date]';\n } else {\n // Note: `dateFormat` throws a TypeError if the given Date is invalid (i.e. value is NaN)\n return dateFormat(value, options.dateFormat || 'isoUtcDateTime');\n }\n } else if (value instanceof RegExp) {\n return quote(value.toString());\n } else if (value instanceof Error) {\n // For error messages, print the message raw. We expect the message to be already formatted\n // for display, so encoding it would mess up the formatting.\n return `[${value.constructor.name}] ${value.message}`;\n } else if (typeof value === 'object') {\n const proto = Object.getPrototypeOf(value);\n if (proto === null || proto === Object.prototype) {\n // Currently just JSON encodes the entire object. We may want to format this a bit nicer.\n return quote(formatObject(value, options.format));\n }\n \n if (hasOwnProperty(proto, 'constructor') && typeof proto.constructor === 'function') {\n const constructor = proto.constructor;\n \n const tag = constructor.name || 'Unknown';\n \n let stringRep;\n if ('toJSON' in value) {\n // Note: `toJSON` is not included in `Object.prototype`, so will only be present in types\n // that explicitly implement JSON encoding.\n stringRep = quote(formatObject(value, options.format));\n } else if ('toString' in value && value.toString !== Object.prototype.toString) {\n // Note: `toString` is included in `Object.prototype`. However, the default implementation is\n // generally not very helpful (e.g. `[Object object]`). So we explicitly ignore it.\n \n stringRep = JSON.stringify(value.toString()); // Encode as string literal\n } else {\n // Fallback: take all enumerable properties and format as object\n stringRep = quote(formatObject({ ...value }, options.format));\n }\n \n return `[${tag}] ${stringRep}`;\n }\n }\n \n // Fallback\n return JSON.stringify(value);\n};\n\nexport const msgTag = options => createTag(value => format(value, options));\n\nconst msg = msgTag({\n format: {\n maxDepth: 4,\n min: true,\n },\n dateFormat: 'isoUtcDateTime',\n});\n\nexport const raw = msg.raw = value => ({ [customKey]: true, type: 'raw', value });\n\nexport const custom = msg.custom = (options, value) => ({ [customKey]: true, options, value });\n\nexport default msg;\n"],"mappings":";;;;;;AACA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AAAuD,SAAAD,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAGvD;AACA,MAAMG,SAAS,GAAGC,MAAM,IAAI,UAACC,WAAW;EAAA,SAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAAKC,aAAa,OAAAC,KAAA,CAAAJ,IAAA,OAAAA,IAAA,WAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;IAAbF,aAAa,CAAAE,IAAA,QAAAJ,SAAA,CAAAI,IAAA;EAAA;EAAA,OACtDF,aAAa,CAACG,MAAM,CAChB,CAACC,IAAI,EAAEC,GAAG,EAAEC,CAAC,KAAKF,IAAI,GAAGT,MAAM,CAACU,GAAG,CAAC,GAAGT,WAAW,CAACU,CAAC,GAAG,CAAC,CAAC,EACzDV,WAAW,CAAC,CAAC,CAAC,CACjB;AAAA;;AAEL;AACA,MAAMW,cAAc,GAAGA,CAAChB,GAAG,EAAEiB,QAAQ,KAAKC,MAAM,CAACC,SAAS,CAACH,cAAc,CAACI,IAAI,CAACpB,GAAG,EAAEiB,QAAQ,CAAC;AAG7F,MAAMI,SAAS,GAAGC,MAAM,CAAC,YAAY,CAAC;A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C;EACfvB,MAAM,EAAE;IACJ0B,QAAQ,EAAE,CAAC;IACXC,GAAG,EAAE;EACT,CAAC;EACDd,UAAU,EAAE;AAChB,CAAC,CAAC;AAEK,MAAMe,GAAG,GAAGH,GAAG,CAACG,GAAG,GAAGjC,KAAK,KAAK;EAAE,CAACH,SAAS,GAAG,IAAI;EAAEU,IAAI,EAAE,KAAK;EAAEP;AAAM,CAAC,CAAC;AAAC6B,OAAA,CAAAI,GAAA,GAAAA,GAAA;AAE3E,MAAMC,MAAM,GAAGJ,GAAG,CAACI,MAAM,GAAG,CAAChC,OAAO,EAAEF,KAAK,MAAM;EAAE,CAACH,SAAS,GAAG,IAAI;EAAEK,OAAO;EAAEF;AAAM,CAAC,CAAC;AAAC6B,OAAA,CAAAK,MAAA,GAAAA,MAAA;AAAA,IAAAC,QAAA,GAEhFL,GAAG;AAAAD,OAAA,CAAAnD,OAAA,GAAAyD,QAAA"}
import dateFormat from 'dateformat';
import { format as prettyFormat } from 'pretty-format';
// Generic builder for template literal tags
const createTag = encode => function (stringParts) {
for (var _len = arguments.length, substitutions = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
substitutions[_key - 1] = arguments[_key];
}
return substitutions.reduce((prev, cur, i) => prev + encode(cur) + stringParts[i + 1], stringParts[0]);
};
// Version of `obj.hasOwnProperty()` that works regardless of prototype
const hasOwnProperty = (obj, propName) => Object.prototype.hasOwnProperty.call(obj, propName);
const customKey = Symbol('msg.custom');
const quote = value => `\`${value}\``;
const formatObject = (obj, options) => {
return prettyFormat(obj, options).replace(/^Object /, ''); // Remove 'Object' tag
};
const format = function (value) {
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (typeof value === 'object' && value && customKey in value) {
if (value.type === 'raw') {
return value.value;
}
if (typeof value.options === 'object' && value.options) {
options = value.options;
value = value.value;
}
}
if (value === undefined) {
return quote('undefined');
} else if (value === null) {
return quote('null');
} else if (typeof value === 'boolean') {
return quote(String(value));
} else if (typeof value === 'symbol') {
return quote(value.toString()); // `Symbol(<symbol-name>)`
} else if (typeof value === 'string') {
return JSON.stringify(value); // Don't quote, just encode as a string literal
} else if (typeof value === 'number') {
if (isNaN(value)) {
return 'NaN';
} else if (value === +Infinity) {
return '+Infinity';
} else if (value === -Infinity) {
return '-Infinity';
}
return String(value);
} else if (Array.isArray(value)) {
// Currently just JSON encodes the entire array. We may want to format this a bit nicer.
return quote(JSON.stringify(value));
} else if (typeof value === 'function') {
return quote(value.toString());
} else if (value instanceof Date) {
if (Number.isNaN(value.valueOf())) {
return '[invalid Date]';
} else {
// Note: `dateFormat` throws a TypeError if the given Date is invalid (i.e. value is NaN)
return dateFormat(value, options.dateFormat || 'isoUtcDateTime');
}
} else if (value instanceof RegExp) {
return quote(value.toString());
} else if (value instanceof Error) {
// For error messages, print the message raw. We expect the message to be already formatted
// for display, so encoding it would mess up the formatting.
return `[${value.constructor.name}] ${value.message}`;
} else if (typeof value === 'object') {
const proto = Object.getPrototypeOf(value);
if (proto === null || proto === Object.prototype) {
// Currently just JSON encodes the entire object. We may want to format this a bit nicer.
return quote(formatObject(value, options.format));
}
if (hasOwnProperty(proto, 'constructor') && typeof proto.constructor === 'function') {
const constructor = proto.constructor;
const tag = constructor.name || 'Unknown';
let stringRep;
if ('toJSON' in value) {
// Note: `toJSON` is not included in `Object.prototype`, so will only be present in types
// that explicitly implement JSON encoding.
stringRep = quote(formatObject(value, options.format));
} else if ('toString' in value && value.toString !== Object.prototype.toString) {
// Note: `toString` is included in `Object.prototype`. However, the default implementation is
// generally not very helpful (e.g. `[Object object]`). So we explicitly ignore it.
stringRep = JSON.stringify(value.toString()); // Encode as string literal
} else {
// Fallback: take all enumerable properties and format as object
stringRep = quote(formatObject({
...value
}, options.format));
}
return `[${tag}] ${stringRep}`;
}
}
// Fallback
return JSON.stringify(value);
};
export const msgTag = options => createTag(value => format(value, options));
const msg = msgTag({
format: {
maxDepth: 4,
min: true
},
dateFormat: 'isoUtcDateTime'
});
export const raw = msg.raw = value => ({
[customKey]: true,
type: 'raw',
value
});
export const custom = msg.custom = (options, value) => ({
[customKey]: true,
options,
value
});
export default msg;
//# sourceMappingURL=message.mjs.map
{"version":3,"file":"message.mjs","names":["dateFormat","format","prettyFormat","createTag","encode","stringParts","_len","arguments","length","substitutions","Array","_key","reduce","prev","cur","i","hasOwnProperty","obj","propName","Object","prototype","call","customKey","Symbol","quote","value","formatObject","options","replace","undefined","type","String","toString","JSON","stringify","isNaN","Infinity","isArray","Date","Number","valueOf","RegExp","Error","constructor","name","message","proto","getPrototypeOf","tag","stringRep","msgTag","msg","maxDepth","min","raw","custom"],"sources":["../src/message.js"],"sourcesContent":["\nimport dateFormat from 'dateformat';\nimport { format as prettyFormat } from 'pretty-format';\n\n\n// Generic builder for template literal tags\nconst createTag = encode => (stringParts, ...substitutions) =>\n substitutions.reduce(\n (prev, cur, i) => prev + encode(cur) + stringParts[i + 1],\n stringParts[0]\n );\n\n// Version of `obj.hasOwnProperty()` that works regardless of prototype\nconst hasOwnProperty = (obj, propName) => Object.prototype.hasOwnProperty.call(obj, propName);\n\n\nconst customKey = Symbol('msg.custom');\n\nconst quote = value => `\\`${value}\\``;\n\nconst formatObject = (obj, options) => {\n return prettyFormat(obj, options)\n .replace(/^Object /, ''); // Remove 'Object' tag\n};\n\nconst format = (value, options = {}) => {\n if (typeof value === 'object' && value && customKey in value) {\n if (value.type === 'raw') {\n return value.value;\n }\n \n if (typeof value.options === 'object' && value.options) {\n options = value.options;\n value = value.value;\n }\n }\n \n if (value === undefined) {\n return quote('undefined');\n } else if (value === null) {\n return quote('null');\n } else if (typeof value === 'boolean') {\n return quote(String(value));\n } else if (typeof value === 'symbol') {\n return quote(value.toString()); // `Symbol(<symbol-name>)`\n } else if (typeof value === 'string') {\n return JSON.stringify(value); // Don't quote, just encode as a string literal\n } else if (typeof value === 'number') {\n if (isNaN(value)) {\n return 'NaN';\n } else if (value === +Infinity) {\n return '+Infinity';\n } else if (value === -Infinity) {\n return '-Infinity';\n }\n \n return String(value);\n } else if (Array.isArray(value)) {\n // Currently just JSON encodes the entire array. We may want to format this a bit nicer.\n return quote(JSON.stringify(value));\n } else if (typeof value === 'function') {\n return quote(value.toString());\n } else if (value instanceof Date) {\n if (Number.isNaN(value.valueOf())) {\n return '[invalid Date]';\n } else {\n // Note: `dateFormat` throws a TypeError if the given Date is invalid (i.e. value is NaN)\n return dateFormat(value, options.dateFormat || 'isoUtcDateTime');\n }\n } else if (value instanceof RegExp) {\n return quote(value.toString());\n } else if (value instanceof Error) {\n // For error messages, print the message raw. We expect the message to be already formatted\n // for display, so encoding it would mess up the formatting.\n return `[${value.constructor.name}] ${value.message}`;\n } else if (typeof value === 'object') {\n const proto = Object.getPrototypeOf(value);\n if (proto === null || proto === Object.prototype) {\n // Currently just JSON encodes the entire object. We may want to format this a bit nicer.\n return quote(formatObject(value, options.format));\n }\n \n if (hasOwnProperty(proto, 'constructor') && typeof proto.constructor === 'function') {\n const constructor = proto.constructor;\n \n const tag = constructor.name || 'Unknown';\n \n let stringRep;\n if ('toJSON' in value) {\n // Note: `toJSON` is not included in `Object.prototype`, so will only be present in types\n // that explicitly implement JSON encoding.\n stringRep = quote(formatObject(value, options.format));\n } else if ('toString' in value && value.toString !== Object.prototype.toString) {\n // Note: `toString` is included in `Object.prototype`. However, the default implementation is\n // generally not very helpful (e.g. `[Object object]`). So we explicitly ignore it.\n \n stringRep = JSON.stringify(value.toString()); // Encode as string literal\n } else {\n // Fallback: take all enumerable properties and format as object\n stringRep = quote(formatObject({ ...value }, options.format));\n }\n \n return `[${tag}] ${stringRep}`;\n }\n }\n \n // Fallback\n return JSON.stringify(value);\n};\n\nexport const msgTag = options => createTag(value => format(value, options));\n\nconst msg = msgTag({\n format: {\n maxDepth: 4,\n min: true,\n },\n dateFormat: 'isoUtcDateTime',\n});\n\nexport const raw = msg.raw = value => ({ [customKey]: true, type: 'raw', value });\n\nexport const custom = msg.custom = (options, value) => ({ [customKey]: true, options, value });\n\nexport default msg;\n"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, ...substitutions : unknown[]) => string;
type CustomOptions = {
format ?: Partial<PrettyFormatConfig>,
dateFormat ?: string,
};
// Note: structure of the result types can be left opaque (internal structure)
export declare const raw : (value : unknown) => object;
export declare const custom : (options : CustomOptions, value : unknown) => object;
export declare const msgTag : (options : CustomOptions) => MessageTag;
declare const msg : MessageTag & {
raw : typeof raw,
custom : typeof msgTag,
};
export default msg;