How to use the superstruct.struct.dict function in superstruct

To help you get started, we’ve selected a few superstruct 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 jxnblk / figma-theme / index.js View on Github external
const FILL = 'FILL'
const TEXT = 'TEXT'

const flatten = (arr = []) => arr.reduce((a, b) => {
  return [
    ...a,
    b,
    ...flatten(b.children)
  ]
}, [])

// schema
const Theme = struct({
  colors: 'object',
  textStyles: struct.dict([
    'string',
    struct({
      fontFamily: 'string',
      fontSize: 'number',
      fontWeight: 'number',
      lineHeight: 'number',
    })
  ]),
  fonts: 'array',
  fontSizes: 'array',
  fontWeights: 'array',
  lineHeights: 'array',
  metadata: 'object?'
})

const Data = struct.partial({
github jxnblk / figma-theme / index.js View on Github external
]),
  fonts: 'array',
  fontSizes: 'array',
  fontWeights: 'array',
  lineHeights: 'array',
  metadata: 'object?'
})

const Data = struct.partial({
  name: 'string',
  lastModified: 'string',
  thumbnailUrl: 'string',
  document: struct.partial({
    children: struct.list([ 'object' ]),
  }),
  styles: struct.dict([
    'string',
    struct.partial({
      name: 'string',
      styleType: 'string',
    })
  ])
})

const unique = arr => [...new Set(arr)]

module.exports = (data, opts = {}) => {
  Data(data)
  const {
    styles = {},
    document: {
      children: tree = []
github puzzle-js / puzzle-js / src / configurator.ts View on Github external
const gatewayFragmentVersionStructure = struct({
    assets: [gatewayFragmentAssetsStructure],
    dependencies: [gatewayFragmentDependenctStructure],
    handler: 'string?'
});


const gatewayFragmentStructure = struct({
    name: 'string',
    testCookie: 'string',
    prg: struct.optional('boolean'),
    render: gatewayRenderStructure,
    warden: struct.optional('object'),
    version: 'string',
    versionMatcher: 'string?',
    versions: struct.dict(['string', gatewayFragmentVersionStructure])
});

const gatewayStructure = struct({
    name: 'string',
    url: 'string',
    serverOptions: serverOptionsStructure,
    fragments: [gatewayFragmentStructure],
    api: [apiStructure],
    isMobile: 'boolean?',
    authToken: 'string?',
    fragmentsFolder: 'string',
    corsDomains: struct.optional(['string']),
    corsMaxAge: 'number?',
    customHeaders: struct.optional([customHeaderStructure])
});