Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SOVA-71 Upgrade typings to Bot API 4.4 #27

Open
sergeysova opened this issue Aug 8, 2019 · 2 comments

Comments

@sergeysova
Copy link
Owner

commented Aug 8, 2019

Issuehunt badges

https://core.telegram.org/bots/api


IssueHunt Summary

Backers (Total: $5.00)

Become a backer now!

Or submit a pull request to get the deposits!

Tips


IssueHunt has been backed by the following sponsors. Become a sponsor

@issuehunt-app

This comment has been minimized.

Copy link

commented Aug 8, 2019

@sergeysova has funded $5.00 to this issue.


@Piterden

This comment has been minimized.

Copy link
Collaborator

commented Aug 8, 2019

const nodes = document.getElementsByTagName('h4')
const types = Array.from(nodes).filter((node) => node.innerText.match(/^(?:[A-Z][a-z]+)+$/))
const methods = Array.from(nodes).filter((node) => node.innerText.match(/^[a-z]+(?:[A-Z][a-z]+)+$/))

types.map((el) => {
  let comment = ''
  let props = ''
  let next = el

  while (next.nextElementSibling.tagName === 'P') {
    comment += next.innerText
    next = next.nextElementSibling
  }
  const tableEl = next.nextElementSibling.tagName === 'TABLE' ? next.nextElementSibling : null

  if (tableEl) {
    props = Array.from(tableEl.children[1].children).map((tr) => {
      const arr = Array.from(tr.children)

      return arr.length 
        ? arr[2].innerText.length > 72 
          ? `
  /**${arr[2].innerText.replace(/(.{1,72}\s)\s*?/g, '\n   * $1')}
   */
  ${arr[0].innerText}${arr[2].innerText.startsWith('Optional.') ? '?' : ''}: ${arr[1].innerText.replace(/Array of (\w+)/, '$1[]')},
`
          : `\n  /** ${arr[2].innerText} */\n  ${arr[0].innerText}${arr[2].innerText.startsWith('Optional.') ? '?' : ''}: ${arr[1].innerText.replace(/Array of (\w+)/, '$1[]')},\n`
        : ''
}).join('')
  }

  return `
/**
 * ${comment.replace(/(.{1,72}\s)\s*?/g, '\n * $1')}
 */
export type ${el.innerText} = {${props}}
`}).join('') + '\n\n' +
methods.map((el) => {
  let comment = ''
  let props = ''
  let next = el

  while (next.nextElementSibling.tagName === 'P') {
    comment += next.innerText
    next = next.nextElementSibling
  }
  const tableEl = next.nextElementSibling.tagName === 'TABLE' ? next.nextElementSibling : null

  if (tableEl) {
    props = Array.from(tableEl.children[1].children).map((tr) => {
      const arr = Array.from(tr.children)

      return arr.length 
        ? arr[3].innerText.length > 72 
          ? `
  /**
   * ${arr[3].innerText.replace(/(.{1,72}\s)\s*?/g, '\n   * $1')}
   */
  ${arr[0].innerText}${arr[2].innerText === 'Optional' ? '?' : ''}: ${arr[1].innerText.replace(/Array of (\w+)/, '$1[]')},
`
          : `\n  /** ${arr[3].innerText} */\n  ${arr[0].innerText}${arr[2].innerText === 'Optional' ? '?' : ''}: ${arr[1].innerText.replace(/Array of (\w+)/, '$1[]')},\n`
        : ''
}).join('')
  }

  return `
/**
 * ${comment.replace(/(.{1,72}\s)\s*?/g, '\n * $1')}
 */
export type ${el.innerText} = {${props}}
`}).join('')

@sergeysova sergeysova changed the title Upgrade typings to Bot API 4.4 SOVA-71 Upgrade typings to Bot API 4.4 Aug 9, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.