Refactor getTextCount (#3553)
Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com>
This commit is contained in:
		| @@ -10,15 +10,9 @@ import { toUnicode } from 'punycode'; | |||||||
| import syntaxHighlight from '../../../../../mfm/syntax-highlight'; | import syntaxHighlight from '../../../../../mfm/syntax-highlight'; | ||||||
|  |  | ||||||
| function getTextCount(tokens: Node[]): number { | function getTextCount(tokens: Node[]): number { | ||||||
| 	let count = 0; | 	const rootCount = sum(tokens.filter(x => x.name === 'text').map(x => length(x.props.text))); | ||||||
| 	const extract = (tokens: Node[]) => { | 	const childrenCount = sum(tokens.filter(x => x.children).map(x => getTextCount(x.children))); | ||||||
| 		count += sum(tokens.filter(x => x.name === 'text').map(x => length(x.props.text))); | 	return rootCount + childrenCount; | ||||||
| 		tokens.filter(x => x.children).forEach(x => { |  | ||||||
| 			extract(x.children); |  | ||||||
| 		}); |  | ||||||
| 	}; |  | ||||||
| 	extract(tokens); |  | ||||||
| 	return count; |  | ||||||
| } | } | ||||||
|  |  | ||||||
| function getChildrenCount(tokens: Node[]): number { | function getChildrenCount(tokens: Node[]): number { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Aya Morisawa
					Aya Morisawa