How to use the z-schema.registerFormat function in z-schema

To help you get started, we’ve selected a few z-schema examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github RiseVision / rise-node / packages / core-helpers / src / z_schema.ts View on Github external
if (!Buffer.isBuffer(str)) {
    return false;
  }
  return str.length === 32;
});

z_schema.registerFormat('csv', (str: string) => {
  try {
    const a = str.split(',');
    return a.length > 0 && a.length <= 1000;
  } catch (e) {
    return false;
  }
});

z_schema.registerFormat('signature', (str: string) => {
  return /^[a-f0-9]{128}$/i.test(str);
});

z_schema.registerFormat('signatureBuf', (buf: Buffer) => {
  if (!Buffer.isBuffer(buf)) {
    return false;
  }
  return buf.length === 64;
});

// tslint:disable-next-line no-identical-functions
z_schema.registerFormat('sha256Buf', (buf: Buffer) => {
  if (!Buffer.isBuffer(buf)) {
    return false;
  }
  return buf.length === 32;
github APIDevTools / swagger-parser / lib / validators / schema.js View on Github external
function initializeZSchema () {
  // HACK: Delete the OpenAPI schema IDs because ZSchema can't resolve them
  delete openapi.v2.id;
  delete openapi.v3.id;

  // The OpenAPI 3.0 schema uses "uri-reference" formats.
  // Assume that any non-whitespace string is valid.
  ZSchema.registerFormat("uri-reference", (value) => value.trim().length > 0);

  // Configure ZSchema
  return new ZSchema({
    breakOnFirstError: true,
    noExtraKeywords: true,
    ignoreUnknownFormats: false,
    reportPathAsArray: true
  });
}
github BTWhite / BTWChain / src / init.js View on Github external
scheme: function (cb) {
            z_schema.registerFormat("hex", function (str) {
                var b = null
                try {
                    b = new Buffer(str, "hex");
                } catch (e) {
                    return false;
                }

                return b && b.length > 0;
            });

            z_schema.registerFormat('publicKey', function (str) {
                if (str.length == 0) {
                    return true;
                }

                try {
                    var publicKey = new Buffer(str, "hex");

                    return publicKey.length == 32;
                } catch (e) {
                    return false;
                }
            });

            z_schema.registerFormat('splitarray', function (str) {
                try {
                    var a = str.split(',');
github ShiftNrg / shift / helpers / z_schema.js View on Github external
'use strict';

var ip = require('ip');
var z_schema = require('z-schema');

z_schema.registerFormat('id', function (str) {
	if (str.length === 0) {
		return true;
	}

	return /^[0-9]+$/g.test(str);
});

z_schema.registerFormat('address', function (str) {
	if (str.length === 0) {
		return true;
	}

	return /^[0-9]+[S]$/ig.test(str);
});

z_schema.registerFormat('username', function (str) {
github AraiEzzra / DDKCORE / shared / validate / z_schema.ts View on Github external
return /^[a-z0-9!@$&_.]{1,20}$/ig.test(str);
});

Validator.registerFormat('hex', (str) => {
    try {
        Buffer.from(str, 'hex');
    } catch (e) {
        return false;
    }

    return true;
});

Validator.registerFormat('publicKey', isPublicKey);

Validator.registerFormat('signature', (str) => {
    if (str.length === 0) {
        return true;
    }

    try {
        const signature = Buffer.from(str, 'hex');
        return signature.length === LENGTH.SIGNATURE_SIZE;
    } catch (e) {
        return false;
    }
});

Validator.registerFormat('version', (str) => {
    if (str.length === 0) {
        return true;
    }
github AraiEzzra / DDKCORE / shared / validate / z_schema.ts View on Github external
}
});

Validator.registerFormat('address', (str) => {
    try {
        return BigInt(str).toString(2).length <= LENGTH.ADDRESS_BINARY_SIZE;
    } catch (e) {
        return false;
    }
});

Validator.registerFormat('username', (str) => {
    return /^[a-z0-9!@$&_.]{1,20}$/ig.test(str);
});

Validator.registerFormat('hex', (str) => {
    try {
        Buffer.from(str, 'hex');
    } catch (e) {
        return false;
    }

    return true;
});

Validator.registerFormat('publicKey', isPublicKey);

Validator.registerFormat('signature', (str) => {
    if (str.length === 0) {
        return true;
    }
github AraiEzzra / DDKCORE / shared / validate / z_schema.ts View on Github external
PUBLIC_KEY_SIZE = 32,
    SIGNATURE_SIZE = 64,
    ADDRESS_BINARY_SIZE = 64,
}

const isPublicKey = (str: PublicKey) => {
    try {
        const publicKey = Buffer.from(str, 'hex');

        return publicKey.length === LENGTH.PUBLIC_KEY_SIZE;
    } catch (e) {
        return false;
    }
};

Validator.registerFormat('id', (str) => {
    try {
        const publicKey = Buffer.from(str, 'hex');
        return publicKey.length === LENGTH.PUBLIC_KEY_SIZE;
    } catch (e) {
        return false;
    }
});

Validator.registerFormat('address', (str) => {
    try {
        return BigInt(str).toString(2).length <= LENGTH.ADDRESS_BINARY_SIZE;
    } catch (e) {
        return false;
    }
});
github BTWhite / BTWChain / src / init.js View on Github external
scheme: function (cb) {
            z_schema.registerFormat("hex", function (str) {
                var b = null
                try {
                    b = new Buffer(str, "hex");
                } catch (e) {
                    return false;
                }

                return b && b.length > 0;
            });

            z_schema.registerFormat('publicKey', function (str) {
                if (str.length == 0) {
                    return true;
                }

                try {
github LiskHQ / lisk-sdk-examples / framework / src / modules / chain / helpers / z_schema.js View on Github external
Object.keys(liskFormats).forEach(formatName => {
	z_schema.registerFormat(formatName, liskFormats[formatName]);
});
github BTWhite / BTWChain / src / init.js View on Github external
z_schema.registerFormat('listDelegates', function (obj) {
                obj.limit = 101;
                return true;
            });

            z_schema.registerFormat('checkInt', function (value) {
                if (isNaN(value) || parseInt(value) != value || isNaN(parseInt(value, 10))) {
                    return false;
                }

                value = parseInt(value);
                return true;
            });

            z_schema.registerFormat('ip', function (value) {

            });

            cb(null, new z_schema())
        },