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

add more types #2946

Closed
wants to merge 1 commit into from
Closed

add more types #2946

wants to merge 1 commit into from

Conversation

vace
Copy link
Contributor

@vace vace commented May 5, 2019

可通过以下脚本从官方文档中使用console快速提取注释信息(提出的信息可能需要手动修改部分)

function makeComment () {
	const isCallback = $('#function-callback').length
	const url = location.href
	const api = location.href.match(/wx\.(.+?)\./)[1]
	const version = $('blockquote').text().trim().match(/\d{1,3}\.\d{1,3}\.\d{1,3}/)[0]
	const txts = $('table').text().split('\n\n\n')
	const notice = $('#注意').next().text().trim().split('\n').map(row => row.trim() ? ` * - 注意: ${row}` : '').join('\n')
	const comment = txts.map(r => r.trim()).filter(s => !!s).map(row => {
		var [key, type, strs, required, desc] = row.split('\n')
		if (key === '属性' || type === '类型') return ''
		if (desc) {
			strs = `${desc} ${strs}`
			key = required === '是' ? key : (`${key}?`)
		}
		return `    /**
    * ${strs}
    */
    ${key}: ${type}`
	}).join('\n')
		
	const params = isCallback ? `callback: Function` : `Object: ${api}.Param`
	const example = $('pre').length ? ' * **示例代码:**\n *    ```javascript\n' + $('pre').text().split('\n').map(t => ` *    ${t}`).join('\n') + '\n *    ```' : ''
	
	return `
namespace ${api} {
  type Param = {
    ${comment}
  }
}

/**
 * @since ${version}
 *
 * ${$('blockquote').next().text().trim()}
 * 
${notice}
 *
${example}
 * 
 * @see ${url}
 */
 function ${api}(${params}): void
`
}

可通过以下脚本从官方文档中使用`console`快速提取注释信息(需要手动修改部分)

```javascript

function makeComment () {
	const isCallback = $('#function-callback').length
	const url = location.href
	const api = location.href.match(/wx\.(.+?)\./)[1]
	const version = $('blockquote').text().trim().match(/\d{1,3}\.\d{1,3}\.\d{1,3}/)[0]
	const txts = $('table').text().split('\n\n\n')
	const notice = $('#注意').next().text().trim().split('\n').map(row => row.trim() ? ` * - 注意: ${row}` : '').join('\n')
	const comment = txts.map(r => r.trim()).filter(s => !!s).map(row => {
		var [key, type, strs, required, desc] = row.split('\n')
		if (key === '属性' || type === '类型') return ''
		// 5 个字符
		if (desc) {
			strs = `${desc} ${strs}`
			key = required === '是' ? key : (`${key}?`)
		}
		return `    /**
    * ${strs}
    */
    ${key}: ${type}`
	}).join('\n')
		
	const params = isCallback ? `callback: Function` : `Object: ${api}.Param`
	const example = $('pre').length ? ' * **示例代码:**\n *    ```javascript\n' + $('pre').text().split('\n').map(t => ` *    ${t}`).join('\n') + '\n *    ```' : ''
	
	return `
namespace ${api} {
  type Param = {
    ${comment}
  }
}

/**
 * @SInCE ${version}
 *
 * ${$('blockquote').next().text().trim()}
 * 
${notice}
 *
${example}
 * 
 * @see ${url}
 */
 function ${api}(${params}): void
`
}
```
@luckyadam
Copy link
Member

有冲突了,能否重新提个 pr 呢

@Garfield550
Copy link
Collaborator

你好,Typings 大幅更新了,麻烦请重新到对应的文件里修改一下呢。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants