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

divhide

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

divhide - npm Package Compare versions

Comparing version 1.0.0-alpha.7 to 1.0.0-alpha.8

.readme/includes/Schema/SchemaSerializationExample.js

60

.readme/includes/Schema/SchemaStringExample.js
var Schema = Divhide.Schema;
var serialized =
Schema.object({
"name" : "",
"friends" : Schema.array([
{
name: ""
}
]).optional(),
})
.required()
.serialize();
/// String schema
var schema = Schema.string()
.required()
.min(3)
.max(5);
/// deserialize the object
var schema = Schema.deserialize(serialized);
/// let's get the object
var value = schema.value({
id: 1,
name: "Oscar",
friends: [{ name: "Solange" }]
});
/// returns the value
var value = schema.value("hello");
expect(value).toBe("hello");
expect(value).equals({
name: "Oscar",
friends: [{ name: "Solange" }]
});
/// value is required!
expect(
function(){
schema.value();
})
.toThrow(new Error("Value is required."));
/// value is required!
expect(
function(){
schema.value("hello world");
})
.toThrow(new Error("The maximum value allowed is 5."));
/// Check if is valid
var isValid = schema.isValid("");
expect(isValid).toBe(false);
var isValid = schema.isValid("hello");
expect(isValid).toBe(true);
var isValid = schema.isValid("hello world");
expect(isValid).toBe(false);

@@ -6,3 +6,3 @@ {

"license": "MIT",
"version": "1.0.0-alpha.7",
"version": "1.0.0-alpha.8",

@@ -9,0 +9,0 @@ "authors": [

{
"name": "divhide",
"description": "Divhide javascript core components for NodeJs, Browser, Titanium, ... and everything that runs javascript.",
"version": "1.0.0-alpha.7",
"version": "1.0.0-alpha.8",
"author": {

@@ -6,0 +6,0 @@ "name": "Oscar Brito <aetheon@gmail.com>",

@@ -600,3 +600,11 @@ # [![Divhide](http://blog.divhide.com/assets/images/divhide_128px.png)](http://divhide.com/) divhide-core

`.serialize()`
<br />
Gets the serialized schema representation.
`.deserialize(value)`
<br />
Gets the Schema from the given value.
**Example** overview

@@ -648,47 +656,33 @@

var serialized =
Schema.object({
"name" : "",
"friends" : Schema.array([
{
name: ""
}
]).optional(),
})
.required()
.serialize();
/// String schema
var schema = Schema.string()
.required()
.min(3)
.max(5);
/// deserialize the object
var schema = Schema.deserialize(serialized);
/// let's get the object
var value = schema.value({
id: 1,
name: "Oscar",
friends: [{ name: "Solange" }]
});
/// returns the value
var value = schema.value("hello");
expect(value).toBe("hello");
expect(value).equals({
name: "Oscar",
friends: [{ name: "Solange" }]
});
/// value is required!
expect(
function(){
schema.value();
})
.toThrow(new Error("Value is required."));
/// value is required!
expect(
function(){
schema.value("hello world");
})
.toThrow(new Error("The maximum value allowed is 5."));
/// Check if is valid
var isValid = schema.isValid("");
expect(isValid).toBe(false);
var isValid = schema.isValid("hello");
expect(isValid).toBe(true);
var isValid = schema.isValid("hello world");
expect(isValid).toBe(false);
```

@@ -760,3 +754,3 @@

**Example** Any Schema
**Example** Schema (de)serialization

@@ -768,29 +762,47 @@ ```js

var schema = Schema
.any()
.required()
.compile();
/// String schema
var schema = Schema.string()
.required()
.min(3)
.max(5);
/// valid string value!
var value = schema.value("str");
expect(value).equals(value);
/// returns the value
var value = schema.value("hello");
expect(value).toBe("hello");
/// valid array value!
value = schema.value([1,2]);
expect(value).equals([1,2]);
/// value is required!
expect(
function(){
schema.value();
})
.toThrow(new Error("Value is required."));
/// because its required it fails
/// value is required!
expect(
function(){
schema.value(null);
schema.value("hello world");
})
.toThrow(
new Error("Value is required.")
);
.toThrow(new Error("The maximum value allowed is 5."));
/// Check if is valid
var isValid = schema.isValid("");
expect(isValid).toBe(false);
var isValid = schema.isValid("hello");
expect(isValid).toBe(true);
var isValid = schema.isValid("hello world");
expect(isValid).toBe(false);
```

@@ -797,0 +809,0 @@

@@ -74,3 +74,11 @@

`.serialize()`
<br />
Gets the serialized schema representation.
`.deserialize(value)`
<br />
Gets the Schema from the given value.
**Example** overview

@@ -105,7 +113,7 @@

**Example** Any Schema
**Example** Schema (de)serialization
```js
{%= _.include("Schema/SchemaAnyExample.js") %}
{%= _.include("Schema/SchemaSerializationExample.js") %}

@@ -112,0 +120,0 @@

@@ -61,26 +61,27 @@ "use strict";

ArrExample : function() { require("../.readme/includes/Arr/ArrExample"); },
AssertionExample : function() { require("../.readme/includes/Assertion/AssertionExample"); },
AssertExample : function() { require("../.readme/includes/Assert/AssertExample"); },
ChainExample : function() { require("../.readme/includes/Chain/ChainExample"); },
ExceptionDocExample : function() { require("../.readme/includes/Exception/ExceptionDocExample"); },
ExceptionListDocExample : function() { require("../.readme/includes/Exception/ExceptionListDocExample"); },
I18NStringDocExample : function() { require("../.readme/includes/I18N/I18NStringDocExample"); },
ObjExample : function() { require("../.readme/includes/Obj/ObjExample"); },
SafeArrayExample : function() { require("../.readme/includes/Safe/SafeArrayExample"); },
SafeBooleanExample : function() { require("../.readme/includes/Safe/SafeBooleanExample"); },
SafeFunctionExample : function() { require("../.readme/includes/Safe/SafeFunctionExample"); },
SafeLengthExample : function() { require("../.readme/includes/Safe/SafeLengthExample"); },
SafeNumberExample : function() { require("../.readme/includes/Safe/SafeNumberExample"); },
SafeObjectExample : function() { require("../.readme/includes/Safe/SafeObjectExample"); },
SafeRegexExample : function() { require("../.readme/includes/Safe/SafeRegexExample"); },
SafeStringExample : function() { require("../.readme/includes/Safe/SafeStringExample"); },
SafeValueExample : function() { require("../.readme/includes/Safe/SafeValueExample"); },
SchemaAnyExample : function() { require("../.readme/includes/Schema/SchemaAnyExample"); },
SchemaArrayExample : function() { require("../.readme/includes/Schema/SchemaArrayExample"); },
SchemaNumberExample : function() { require("../.readme/includes/Schema/SchemaNumberExample"); },
SchemaObjectExample : function() { require("../.readme/includes/Schema/SchemaObjectExample"); },
SchemaOverview : function() { require("../.readme/includes/Schema/SchemaOverview"); },
SchemaStringExample : function() { require("../.readme/includes/Schema/SchemaStringExample"); },
TypeExample : function() { require("../.readme/includes/Type/TypeExample"); },
ArrExample : function() { require("../.readme/includes/Arr/ArrExample"); },
AssertionExample : function() { require("../.readme/includes/Assertion/AssertionExample"); },
AssertExample : function() { require("../.readme/includes/Assert/AssertExample"); },
ChainExample : function() { require("../.readme/includes/Chain/ChainExample"); },
ExceptionDocExample : function() { require("../.readme/includes/Exception/ExceptionDocExample"); },
ExceptionListDocExample : function() { require("../.readme/includes/Exception/ExceptionListDocExample"); },
I18NStringDocExample : function() { require("../.readme/includes/I18N/I18NStringDocExample"); },
ObjExample : function() { require("../.readme/includes/Obj/ObjExample"); },
SafeArrayExample : function() { require("../.readme/includes/Safe/SafeArrayExample"); },
SafeBooleanExample : function() { require("../.readme/includes/Safe/SafeBooleanExample"); },
SafeFunctionExample : function() { require("../.readme/includes/Safe/SafeFunctionExample"); },
SafeLengthExample : function() { require("../.readme/includes/Safe/SafeLengthExample"); },
SafeNumberExample : function() { require("../.readme/includes/Safe/SafeNumberExample"); },
SafeObjectExample : function() { require("../.readme/includes/Safe/SafeObjectExample"); },
SafeRegexExample : function() { require("../.readme/includes/Safe/SafeRegexExample"); },
SafeStringExample : function() { require("../.readme/includes/Safe/SafeStringExample"); },
SafeValueExample : function() { require("../.readme/includes/Safe/SafeValueExample"); },
SchemaAnyExample : function() { require("../.readme/includes/Schema/SchemaAnyExample"); },
SchemaArrayExample : function() { require("../.readme/includes/Schema/SchemaArrayExample"); },
SchemaNumberExample : function() { require("../.readme/includes/Schema/SchemaNumberExample"); },
SchemaObjectExample : function() { require("../.readme/includes/Schema/SchemaObjectExample"); },
SchemaOverview : function() { require("../.readme/includes/Schema/SchemaOverview"); },
SchemaStringExample : function() { require("../.readme/includes/Schema/SchemaStringExample"); },
SchemaSerializationExample : function() { require("../.readme/includes/Schema/SchemaSerializationExample"); },
TypeExample : function() { require("../.readme/includes/Type/TypeExample"); },

@@ -87,0 +88,0 @@ }

Sorry, the diff of this file is too big to display

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