Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'use strict'
const { struct, superstruct } = require('superstruct')
const { optional, list } = struct
// Define custom types
const s = superstruct({
types: {
transport: value => {
if (value.length === 0) return 'ERROR_EMPTY'
value.forEach(i => {
if (!i.dial) return 'ERR_NOT_A_TRANSPORT'
})
return true
},
protector: value => {
if (!value.protect) return 'ERR_NOT_A_PROTECTOR'
return true
}
}
})
const modulesSchema = s({
/* eslint no-unused-vars: "off" */
/* eslint new-cap: "off" */
/* eslint camelcase: "off" */
const S = require('superstruct')
const isUrl = require('is-url')
const struct = S.superstruct({
types: {
url: isUrl,
empty: v => v === ''
}
})
const ResultElement = struct({
Text: 'string',
Icon: {
Width: 'empty | number',
Height: 'empty | number',
URL: 'empty | url'
},
FirstURL: 'url',
Result: 'string'
})
import { superstruct } from 'superstruct'
import isEmail from 'is-email'
import isUuid from 'is-uuid'
import isUrl from 'is-url'
// Define a `struct` with custom types.
const struct = superstruct({
types: {
uuid: v => isUuid.v4(v),
email: v => {
if (!isEmail(v)) return `not_email`
if (v.length >= 256) return 'too_long'
return true
},
url: v => isUrl(v) && v.length < 2048,
},
})
// Define a struct to validate with.
const User = struct({
id: 'uuid',
name: 'string',
email: 'email',
/* eslint import/no-unresolved: [2, { ignore: ['\.config.js$'] }] */
/* eslint import/no-unassigned-import: "off" */
/* eslint new-cap: "off" */
const S = require('superstruct')
const isUrl = require('is-url')
const entities = ['Book', 'BookSeries', 'EducationalOrganization', 'Event', 'GovernmentOrganization', 'LocalBusiness', 'Movie', 'MovieSeries', 'MusicAlbum', 'MusicGroup', 'MusicRecording', 'Organization', 'Periodical', 'Person', 'Place', 'SportsTeam', 'TVEpisode', 'TVSeries', 'VideoGame', 'VideoGameSeries', 'WebSite']
const struct = S.superstruct({
types: {
url: isUrl,
EntitySearchResult: v => v === 'EntitySearchResult',
ItemList: v => v === 'ItemList'
}
})
const EntitySearchResult = struct({
'@type': 'EntitySearchResult',
result: {
'@id': 'string',
name: 'string',
'@type': ['string'],
description: 'string',
detailedDescription: struct.optional({
articleBody: 'string',
const superstruct = require('superstruct').superstruct
export const struct = superstruct({
types: {
uuid: value => /^[0-9a-f]{8}-[0-9a-f]{4}-[4][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(value),
yearMonth: value => /^[0-9]{4}-(?:1[0-2]|0[1-9])$/.test(value),
date: value => /^[0-9]{4}-(?:1[0-2]|0[1-9])-(?:3[01]|[12]\d|0[1-9])$/.test(value),
timestamp: value => /^((?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(\.[0-9]+)?(Z)?$/.test(value)
}
})
export const minAPIParameterDefintion = { accessToken: 'string', apiUrl: 'string' }
export const minAPIParameterValidator = struct.interface(minAPIParameterDefintion)
'use strict'
const Multiaddr = require('multiaddr')
const mafmt = require('mafmt')
const { struct, superstruct } = require('superstruct')
const { isTest } = require('ipfs-utils/src/env')
const { optional, union } = struct
const s = superstruct({
types: {
multiaddr: v => {
if (v === null) {
return `multiaddr invalid, value must be a string, Buffer, or another Multiaddr got ${v}`
}
try {
Multiaddr(v)
} catch (err) {
return `multiaddr invalid, ${err.message}`
}
return true
},
'multiaddr-ipfs': v => mafmt.IPFS.matches(v) ? true : 'multiaddr IPFS invalid'
}
import { superstruct } from 'superstruct'
export function isRdfLiteral (value) {
return (typeof value === 'string' && value.charAt(0) === '"')
}
export function isRdfValue (value) {
return (typeof value === 'string' && value.charAt(0) === '"')
}
export function isRdfValueOrLiteral (value) {
return isRdfValue(value) || isRdfLiteral(value)
}
const struct = superstruct({
types: {
rdfLiteral: isRdfLiteral,
rdfValue: isRdfValue,
rdfValueOrLiteral: isRdfValueOrLiteral
}
})
const Triple = struct({
subject: 'rdfValueOrLiteral',
object: 'rdfValueOrLiteral',
predicate: 'rdfValueOrLiteral'
})
const SomeEntityType = struct({
id: 'id',
someProp: 'rdfValueOrLiteral',
import { Model, snakeCaseMappers } from 'objection'
import Role from './role'
import { superstruct } from 'superstruct'
import isEmail from 'is-email'
import JsonSerializer from '../helpers/json-serializer'
const struct = superstruct({
types: {
email: isEmail,
}
})
/*
json-api-serializer
*/
const schema = 'user'
const jsonSerializerConfig = {
jsonapiObject: false,
whitelistOnDeserialize: ['id', 'password', 'name', 'email'],
unconvertCase: 'camelCase',
convertCase: 'camelCase',
relationships: {
roles: {