How to use the quicktype-core/dist/Source.modifySource function in quicktype-core

To help you get started, we’ve selected a few quicktype-core 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 segmentio / typewriter / src / commands / gen-js / typescript.ts View on Github external
this.forEachTopLevel('leading-and-interposing', (t, name) => {
      const camelCaseName = modifySource(camelCase, name)
      this.emitDescription(this.descriptionForType(t))

      // Override sourceFor behavior to disable `{ [key: string]: any }`
      // if no properties are set for an event.
      let type = this.sourceFor(t).source
      if (t instanceof MapType) {
        type = '{}'
      }

      if (this.ajsOptions.client === Client.js) {
        this.emitLine([
          camelCaseName,
          '(props?: ',
          type,
          ', options?: SegmentOptions, callback?: AnalyticsJSCallback): void'
        ])
github segmentio / typewriter / src / commands / gen-android.ts View on Github external
withOptions: boolean
  ): void {
    // TODO: Emit a function description, once we support top-level event descriptions in JSON Schema
    const description: Sourcelike = [
      ['@see <a href="https://segment.com/docs/spec/track/">Track Documentation</a>']
    ]
    if (hasProperties) {
      description.unshift([
        '@param props {@link ',
        name,
        '} to add extra information to this call.'
      ])
    }
    this.emitDescriptionBlock(description)

    const camelCaseName = modifySource(camelCase, name)
    this.emitBlock(
      [
        'public void ',
        camelCaseName,
        '(',
        ...(hasProperties ? ['final @Nullable ', name, ' props'] : []),
        hasProperties &amp;&amp; withOptions ? ', ' : '',
        withOptions ? 'final @Nullable Options options' : '',
        ')'
      ],
      () =&gt; {
        this.emitLine([
          'this.analytics.track("',
          getRawName(name),
          '", ',
          hasProperties ? 'props.toProperties()' : 'new Properties()',
github segmentio / typewriter / src / commands / gen-js / typescript.ts View on Github external
this.emitPropertyTable(c, (_, jsonName, p) => {
      const t = p.type
      return [
        [modifySource(quotePropertyName, jsonName), p.isOptional ? '?' : '', ': '],
        [this.sourceFor(t).source, ';']
      ]
    })
  }
github segmentio / typewriter / src / commands / gen-ts.ts View on Github external
this.forEachTopLevel('leading-and-interposing', (t, name) => {
      const camelCaseName = modifySource(camelCase, name)
      const typeMap = this.typeMapTypeFor(t)
      this.emitBlock(
        [
          'export function ',
          camelCaseName,
          '(props: ',
          this.sourceFor(t).source,
          ', context?: any): void'
        ],
        '',
        () => {
          this.emitLine('const payload = transform(props, ', typeMap, ', jsToJSONProps, typeMap);')

          const rawEventName = name
            .proposeUnstyledNames(null)
            .values()