当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Strands.toString方法代码示例

本文整理汇总了TypeScript中strands.Strands.toString方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Strands.toString方法的具体用法?TypeScript Strands.toString怎么用?TypeScript Strands.toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在strands.Strands的用法示例。


在下文中一共展示了Strands.toString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: getClient

 public getClient() {
   this.generateRequiresAndGlobalFunctions();
   this.createClientClass();
   this.createChildren();
   this.generateStaticMethodsAndExport();
   return this.buffer.toString();
 }
开发者ID:mulesoft-labs,项目名称:raml-javascript-generator,代码行数:7,代码来源:index.js.ts

示例2: toParamsFunction

 private toParamsFunction(child: NestedResource, client: string, isChild: boolean, attach?: string) {
   const className = `${this.currentPath.join('.')}.${uppercamelcase(child.methodName)}`;
   const func2Return = new Strands();
   const path = isChild ? 'this.path + ' : '';
   func2Return.multiline(`(uriParams) => new ${className}(
     ${client},
     ${path}template(${javascriptStringify(child.relativeUri)},
       Object.assign(${javascriptStringify(getDefaultParameters(child.uriParameters))}, uriParams))
   ),${attach}`);
   return func2Return.toString();
 }
开发者ID:mulesoft-labs,项目名称:raml-javascript-generator,代码行数:11,代码来源:index.js.ts

示例3: toParamsMethod

  private toParamsMethod(child: NestedResource, client: string, isChild: boolean) {
    const className = this.currentPath.concat([uppercamelcase(child.methodName)]).join('.');
    const func2Return = new Strands();
    const path = isChild ? 'this.path + ' : '';

    func2Return.multiline(`(uriParams) {
    return new ${className}(
      ${client},
      ${path}template(${javascriptStringify(child.relativeUri)},
        Object.assign(${this.formatJSON(getDefaultParameters(child.uriParameters), 2, 8)}, uriParams))
    );
  }`);
    return func2Return.toString();
  }
开发者ID:mulesoft-labs,项目名称:raml-javascript-generator,代码行数:14,代码来源:index.js.ts

示例4: function


//.........这里部分代码省略.........
  }

  createProtoResources(withParams, noParams, 'Client')
  createProtoMethods(nestedTree.methods, 'Client', 'this', `''`)
  createChildren(nestedTree.children)

  // Interface for mapped nested resources.
  interface KeyedNestedResources {
    [key: string]: NestedResource
  }

  // Create prototype methods.
  function createProtoMethods (methods: NestedMethod[], id: string, _client: string, _path: string) {
    for (const method of methods) {
      const headers = getDefaultParameters(method.headers)
      const type = isQueryMethod(method) ? 'query' : 'body'

      s.line(`${id}.prototype.${camelCase(method.method)} = function (${type}, opts) {`)
      s.line(`  var options = extend({ ${type}: ${type}, headers: ${stringify(headers)} }, opts)`)
      s.line(`  return request(${_client}, ${stringify(method.method)}, ${_path}, options)`)
      s.line(`}`)
    }
  }

  // Split children by "type" of method that needs to be created.
  function separateChildren (resource: NestedResource) {
    const withParams: KeyedNestedResources = {}
    const noParams: KeyedNestedResources = {}

    // Split apart children types.
    for (const key of Object.keys(resource.children)) {
      const child = resource.children[key]

      if (Object.keys(child.uriParameters).length) {
        withParams[child.methodName] = child
      } else {
        noParams[child.methodName] = child
      }
    }

    return { withParams, noParams }
  }

  function toParamsFunction (child: NestedResource, _client: string, _prefix: string) {
    return `function (uriParams) { return new ${child.id}(${_client}, ${_prefix}template(${stringify(child.relativeUri)}, extend(${stringify(getDefaultParameters(child.uriParameters))}, uriParams))) }`
  }

  // Create prototype resources.
  function createProtoResources (withParams: KeyedNestedResources, noParams: KeyedNestedResources, id: string) {
    for (const key of Object.keys(withParams)) {
      const child = withParams[key]

      // Skip inlined entries.
      if (noParams[key] != null) {
        continue
      }

      s.line(`${id}.prototype.${child.methodName} = ${toParamsFunction(child, 'this._client', 'this._path + ')}`)
    }
  }

  // Create nested resource instances.
  function createResource (resource: NestedResource) {
    const { withParams, noParams } = separateChildren(resource)

    s.line(`function ${resource.id} (client, path) {`)
    s.line(`  this._client = client`)
    s.line(`  this._path = path`)

    createThisResources(withParams, noParams, 'this._client', 'this._path + ')

    s.line(`}`)

    createProtoResources(withParams, noParams, resource.id)
    createProtoMethods(resource.methods, resource.id, 'this._client', 'this._path')
    createChildren(resource.children)
  }

  // Generate all children.
  function createChildren (children: KeyedNestedResources) {
    for (const key of Object.keys(children)) {
      createResource(children[key])
    }
  }

  function createThisResources (withParams: KeyedNestedResources, noParams: KeyedNestedResources, _client: string, _prefix: string) {
    for (const key of Object.keys(noParams)) {
      const child = noParams[key]
      const constructor = `new ${child.id}(${_client}, ${_prefix}${stringify(child.relativeUri)})`

      if (withParams[key] == null) {
        s.line(`  this.${child.methodName} = ${constructor}`)
      } else {
        s.line(`  this.${child.methodName} = setprototypeof(${toParamsFunction(withParams[key], _client, _prefix)}, ${constructor})`)
      }
    }
  }

  return s.toString()
}
开发者ID:blzjns,项目名称:raml-javascript-generator,代码行数:101,代码来源:index.js.ts

示例5: function


//.........这里部分代码省略.........
\`\`\`sh
npm install ${projectName} --save
\`\`\`

## Usage

\`\`\`js
var ${className} = require('${projectName}')

var client = new ${className}()
\`\`\`
`)

  if (hasSecurity(api, 'OAuth 2.0')) {
    s.multiline(`### Authentication

#### OAuth 2.0

This API supports authentication with [OAuth 2.0](https://github.com/mulesoft/js-client-oauth2). Initialize the \`OAuth2\` instance with the application client id, client secret and a redirect uri to authenticate with users.

\`\`\`js
var auth = new ${className}.security.<method>({
  clientId:     '123',
  clientSecret: 'abc',
  redirectUri:  'http://example.com/auth/callback'
});

// Available methods for OAuth 2.0:`)

    for (const scheme of getSecuritySchemes(api)) {
      if (scheme.type === 'OAuth 2.0') {
        s.line(` - ${camelCase(scheme.name)}`)
      }
    }

    s.line('```')
  }

  s.multiline(`### Options

You can set options when you initialize a client or at any time with the \`options\` property. You may also override options per request by passing an object as the last argument of request methods. For example:

\`\`\`javascript
var client = new ${className}({ ... })

client('GET', '/', {
  baseUri: 'http://example.com',
  headers: {
    'Content-Type': 'application/json'
  }
})
\`\`\`

#### Base URI

You can override the base URI by setting the \`baseUri\` property, or initializing a client with a base URI. For example:

\`\`\`javascript
new ${className}({
  baseUri: 'https://example.com'
});
\`\`\`

### Helpers

Exports \`${className}.form\`, which exposes a cross-platform \`FormData\` interface that can be used with request bodies.

### Methods

All methods return a HTTP request instance of [Popsicle](https://github.com/blakeembrey/popsicle), which allows the use of promises (and streaming in node).
`)

  for (const resource of allResources(api)) {
    for (const method of resource.methods) {
      s.line(`#### ${getDisplayName(method, resource)}`)
      s.line()

      if (Object.keys(resource.uriParameters).length) {
        s.line(getUriParametersSnippet(resource))
        s.line()
      }

      if (method.description) {
        s.multiline(method.description.trim())
        s.line()
      }

      s.multiline(`\`\`\`js
client.${getRequestSnippet(method, resource)}.then(...)
\`\`\`
  `)
    }
  }

  s.line('## License')
  s.line()
  s.line('Apache 2.0')

  return s.toString()
}
开发者ID:blzjns,项目名称:raml-javascript-generator,代码行数:101,代码来源:README.md.ts


注:本文中的strands.Strands.toString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。