Comparing version 1.0.0-alpha.7 to 1.0.0-alpha.8
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>", |
118
README.md
@@ -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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 2 instances in 1 package
24889
1506
3
1602961