mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-30 00:55:49 +00:00
Reduce dependencies on lodash (#1467)
* assign -> Object.assign * replace isundefined * remove forEach * remove some * remove reduce * remove keys * remove map * remove includes * remove filter * remove last * remove isstring * remove every * remove rearg * remove indexOf * remove values * remove startswith * remove first and pick * build smaller lodash * remove lodash.isequal package * add lodash-cli dev dependency * add lodash script * test fix * Revert "build smaller lodash" This reverts commit 979446e57f60b29cb5d377b54efe91cfbeae0707. * upgrade npm * change ===/!== undefined to ==/!= null
This commit is contained in:
@@ -126,7 +126,7 @@ function loadSchemas() {
|
||||
require('./schemas/input/combine.json')
|
||||
]
|
||||
const titles = schemas.map((schema) => schema.title)
|
||||
const duplicates = _.keys(_.pickBy(_.countBy(titles), (count) => count > 1))
|
||||
const duplicates = Object.keys(_.pickBy(_.countBy(titles), (count) => count > 1))
|
||||
assert.ok(duplicates.length === 0, 'Duplicate schemas for: ' + duplicates)
|
||||
const validator = new Validator()
|
||||
// Register custom format validators that ignore undefined instances
|
||||
@@ -135,7 +135,7 @@ function loadSchemas() {
|
||||
|
||||
// This relies on "format": "xAddress" in `x-address.json`!
|
||||
validator.customFormats.xAddress = function (instance) {
|
||||
if (instance === undefined) {
|
||||
if (instance == null) {
|
||||
return true
|
||||
}
|
||||
return isValidXAddress(instance)
|
||||
@@ -143,21 +143,21 @@ function loadSchemas() {
|
||||
|
||||
// This relies on "format": "classicAddress" in `classic-address.json`!
|
||||
validator.customFormats.classicAddress = function (instance) {
|
||||
if (instance === undefined) {
|
||||
if (instance == null) {
|
||||
return true
|
||||
}
|
||||
return isValidAddress(instance)
|
||||
}
|
||||
|
||||
validator.customFormats.secret = function (instance) {
|
||||
if (instance === undefined) {
|
||||
if (instance == null) {
|
||||
return true
|
||||
}
|
||||
return isValidSecret(instance)
|
||||
}
|
||||
|
||||
// Register under the root URI '/'
|
||||
_.forEach(schemas, (schema) =>
|
||||
schemas.forEach((schema) =>
|
||||
validator.addSchema(schema, '/' + schema.title)
|
||||
)
|
||||
return validator
|
||||
@@ -168,7 +168,7 @@ const schemaValidator = loadSchemas()
|
||||
function schemaValidate(schemaName: string, object: any): void {
|
||||
// Lookup under the root URI '/'
|
||||
const schema = schemaValidator.getSchema('/' + schemaName)
|
||||
if (schema === undefined) {
|
||||
if (schema == null) {
|
||||
throw new ValidationError('no schema for ' + schemaName)
|
||||
}
|
||||
const result = schemaValidator.validate(object, schema)
|
||||
|
||||
Reference in New Issue
Block a user