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

schemaglobin

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

schemaglobin - npm Package Compare versions

Comparing version 5.4.0 to 5.4.1

dist/helpers/message.d.ts

30

dist/helpers/invalid.d.ts

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

/**
* Message is a status message that is safe to show to users.
* - Basic message is neither good nor bad — should be extended to indicate a more-specific status.
*
* @param message String message that is safe to show to users.
* @param details Set of other `Message` instances describing the issue in further detail.
*/
export declare class Message {
readonly message: string;
readonly details?: Record<string, Message>;
constructor(message: string, details?: Record<string, Message>);
/** Convert the children of this `Message` into an object in `{ name: message }` format. */
get messages(): Record<string, string>;
/**
* Convert to string (equivalent to `message.details`).
* Returns a string including the main message string and a deeply nested array of child message strings.
*
* > Invalid format
* > - name: Invalid format
* > - first: Must be string
* > - last: Must be string
* > - age: Must be number
*/
toString(): string;
/** Convert a Message to a JSON format. */
toJSON(): string | Record<string, unknown>;
/** Create a Message from its corresponding JSON format. */
static fromJSON(json: unknown): Message;
}
import { Message } from "./message";
/** Specific type of `Message` returned from `validate()` when a value is invalid. */

@@ -31,0 +3,0 @@ export declare class Invalid extends Message {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Required = exports.Invalid = exports.Message = void 0;
const object_1 = require("./object");
const entryToString = ([key, message]) => `- ${key}: ${message.toString().replace("\n", "\n\t\t")}`;
const messageToString = (message) => message.message;
const messageToJSON = (message) => message.toJSON();
/**
* Message is a status message that is safe to show to users.
* - Basic message is neither good nor bad — should be extended to indicate a more-specific status.
*
* @param message String message that is safe to show to users.
* @param details Set of other `Message` instances describing the issue in further detail.
*/
class Message {
constructor(message, details) {
this.message = message;
this.details = details;
}
/** Convert the children of this `Message` into an object in `{ name: message }` format. */
get messages() {
return this.details ? object_1.mapObject(this.details, messageToString) : {};
}
/**
* Convert to string (equivalent to `message.details`).
* Returns a string including the main message string and a deeply nested array of child message strings.
*
* > Invalid format
* > - name: Invalid format
* > - first: Must be string
* > - last: Must be string
* > - age: Must be number
*/
toString() {
const messages = this.details ? Object.entries(this.details).map(entryToString).join("\n") : "";
return `${this.message}${messages ? `\n${messages}` : ""}`;
}
/** Convert a Message to a JSON format. */
toJSON() {
if (!this.details)
return this.message;
return {
message: this.message,
details: object_1.mapObject(this.details, messageToJSON),
};
}
/** Create a Message from its corresponding JSON format. */
static fromJSON(json) {
// String format is simple.
if (typeof json === "string")
return new Message(json);
// Object format is slightly more compled.
if (object_1.isObject(json) && typeof json.message === "string")
return new Message(json.message, object_1.isObject(json.details) ? object_1.mapObject(json.details, Message.fromJSON) : undefined);
// Anything else is impossible.
throw new Error("Incorrect JSON format");
}
}
exports.Message = Message;
exports.Required = exports.Invalid = void 0;
const message_1 = require("./message");
/** Specific type of `Message` returned from `validate()` when a value is invalid. */
class Invalid extends Message {
class Invalid extends message_1.Message {
}

@@ -63,0 +8,0 @@ exports.Invalid = Invalid;

@@ -21,2 +21,3 @@ export * from "./types";

export * from "./helpers/invalid";
export * from "./helpers/message";
export * from "./helpers/null";

@@ -23,0 +24,0 @@ export * from "./helpers/number";

@@ -37,2 +37,3 @@ "use strict";

__exportStar(require("./helpers/invalid"), exports);
__exportStar(require("./helpers/message"), exports);
__exportStar(require("./helpers/null"), exports);

@@ -39,0 +40,0 @@ __exportStar(require("./helpers/number"), exports);

{
"name": "schemaglobin",
"description": "Validate user-entered data.",
"version": "5.4.0",
"version": "5.4.1",
"repository": "https://github.com/dhoulb/schemaglobin",

@@ -6,0 +6,0 @@ "author": "Dave Houlbrooke <dave@shax.com>",

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