Skip to content

Commit

Permalink
Style.
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmorris committed Sep 6, 2024
1 parent bdd030b commit 8a83037
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
16 changes: 8 additions & 8 deletions Schema.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ const Schema = {
/**
* Exclusively map an object to a Record.
* Will drop any keys not present in the schema.
* @param {Object.<string, SchemaMapper>} schema - An Object holding SchemaMappers
* @param {Object.<string, SchemaMapper>} schema - An Object holding SchemaMappers
*/
xRecord(schema)
{
Expand All @@ -293,7 +293,7 @@ const Schema = {
/**
* Exclusively map an object to a Dict.
* Will drop any keys not present in the schema.
* @param {Object.<string, SchemaMapper>} schema - An Object holding SchemaMappers
* @param {Object.<string, SchemaMapper>} schema - An Object holding SchemaMappers
*/
xDict(schema)
{
Expand Down Expand Up @@ -610,7 +610,7 @@ const Schema = {

uuidString(options = {})
{
const checks = [ value => String(value).match(/^[a-z,0-9]{8}-[a-z,0-9]{4}-[a-z,0-9]{4}-[a-z,0-9]{4}-[a-z,0-9]{12}$/i) ];
const checks = [ value => String(value).match(/^[a-z,0-9]{8}-[a-z,0-9]{4}-[a-z,0-9]{4}-[a-z,0-9]{4}-[a-z,0-9]{12}$/i) ];

if(options.check)
{
Expand All @@ -634,7 +634,7 @@ const Schema = {
*/
urlString(options = {})
{
const checks = [ value => URL.canParse(value) ];
const checks = [ URL.canParse ? value => URL.canParse(value) : value => { try { new URL(value); return true; } catch { return false; } } ];

if(options.check)
{
Expand All @@ -658,7 +658,7 @@ const Schema = {
*/
emailString(options = {})
{
const checks = [ value => {
const checks = [ value => {
const atPos = value.indexOf('@');
const atPos2 = value.indexOf('@', atPos + 1);
const dotPos = value.indexOf('.', atPos);
Expand All @@ -678,7 +678,7 @@ const Schema = {

regexString(options = {})
{
const checks = [ value => { try { RegExp(value); return !!value; } catch { return false; } } ];
const checks = [ value => { try { RegExp(value); return !!value; } catch { return false; } } ];

if(options.check)
{
Expand Down Expand Up @@ -726,7 +726,7 @@ const Schema = {
*/
jsonString(options = {})
{
const checks = [ value => { try { JSON.parse(value); return true; } catch { return false; } } ];
const checks = [ value => { try { JSON.parse(value); return true; } catch { return false; } } ];

if(options.check)
{
Expand Down Expand Up @@ -970,7 +970,7 @@ const Schema = {

/**
* Map the value with the first matching SchemaMapper
* @param {...function(options):value} mappers
* @param {...function(options):value} mappers
*/
or(...mappers)
{
Expand Down
10 changes: 5 additions & 5 deletions index.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { default as Tuple } from "./Tuple.mjs";
export { default as Group } from "./Group.mjs";
export { default as Record } from "./Record.mjs";
export { default as Dict } from "./Dict.mjs";
export { default as Schema } from "./Schema.mjs";
export { default as Tuple } from './Tuple.mjs';
export { default as Group } from './Group.mjs';
export { default as Record } from './Record.mjs';
export { default as Dict } from './Dict.mjs';
export { default as Schema } from './Schema.mjs';
2 changes: 1 addition & 1 deletion test/schema.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ test('s.uuidString test', t => {
assert.throws(() => schema('this is not a uuid'), 'SchemaMapper should throw errors on bad value.');
});

test('s.urlString test', {skip: major < 18 ? 'https://developer.mozilla.org/en-US/docs/Web/API/URL/canParse_static' : false}, t => {
test('s.urlString test', t => {
const schema = s.urlString();
assert.strictEqual(s.parse(schema, 'https://example.com'), 'https://example.com');
assert.strictEqual(s.parse(schema, 'https://example.com/'), 'https://example.com/');
Expand Down

0 comments on commit 8a83037

Please sign in to comment.