<commit_before>// region import
const View = require('./view')
const {CompositeDisposable, Disposable} = require('atom')
// endregion

// region Count
class Count {
	activate (state) {
		if (state) {
			atom.deserializers.deserialize(state)
		} else {
			this.count = 0
			this.key = 'none'
			this.fullKey = 'none'
		}
		this.format = atom.config.get('count.format')
		this.view = new View()
		this.view.initialize()

		// config change listeners
		atom.config.onDidChange('count.format', ({newValue}) => {
			this.format = newValue
			this.refresh()
		})

		// keypress listener
		const ref = this
		this.disposables = new CompositeDisposable()
		this.disposables.add(
			new Disposable(
				atom.views.getView(atom.workspace).addEventListener('keydown', event => {
					ref.count++
					ref.key = event.key

					// full keys
					const keys = []
					if (event.altKey) keys.push('alt')
					if (event.ctrlKey) keys.push('ctrl')
					if (event.metaKey) keys.push('command')
					if (event.shiftKey) keys.push('shift')
					keys.push(event.key)
					ref.fullKey = keys.join('+')

					// reload
					ref.refresh()
				})
			)
		)

		// render
		this.refresh()
	}

	refresh () {
		this.view.set(this.format
			.replace(/\%c/g, this.count)
			.replace(/\%f/g, this.fullKey)
			.replace(/\%k/g, this.key)
		)
	}

	deactivate () {
		this.subscriptions.dispose()
		this.view.destroy()
		this.statusBarTile.destroy() // TODO
	}

	addStatusBar (statusBar) {
		this.statusBar = statusBar
		this.statusBarTile = this.statusBar.addLeftTile({
			item: this.view,
			priority: 50
		})
	}

	parse ({count, fullKey, key}) {
		this.count = count || 0
		this.fullKey = fullKey || 'none'
		this.key = key || 'none'
	}

	serialize () {
		return {
			count: this.count,
			deserializer: 'state',
			fullKey: this.fullKey,
			key: this.key
		}
	}
}
// endregion

// region config
const instance = new Count()
instance.config = {
	format: {
		type: 'string',
		default: '%c %f',
		description: 'Display format. %c = count, %k = key, %f = full key'
	}
}<commit_msg>fix NaN<commit_after>// region import
const View = require('./view')
const {CompositeDisposable, Disposable} = require('atom')
// endregion

// region Count
class Count {
	activate (state) {
		if (state) {
			atom.deserializers.deserialize(state)
		} else {
			this.count = 0
			this.key = 'none'
			this.fullKey = 'none'
		}
		this.format = atom.config.get('count.format')
		this.view = new View()
		this.view.initialize()

		// config change listeners
		atom.config.onDidChange('count.format', ({newValue}) => {
			this.format = newValue
			this.refresh()
		})

		// keypress listener
		const ref = this
		this.disposables = new CompositeDisposable()
		this.disposables.add(
			new Disposable(
				atom.views.getView(atom.workspace).addEventListener('keydown', event => {
					ref.count++
					ref.key = event.key

					// full keys
					const keys = []
					if (event.altKey) keys.push('alt')
					if (event.ctrlKey) keys.push('ctrl')
					if (event.metaKey) keys.push('command')
					if (event.shiftKey) keys.push('shift')
					keys.push(event.key)
					ref.fullKey = keys.join('+')

					// reload
					ref.refresh()
				})
			)
		)

		// render
		this.refresh()
	}

	refresh () {
		this.view.set(this.format
			.replace(/\%c/g, this.count)
			.replace(/\%f/g, this.fullKey)
			.replace(/\%k/g, this.key)
		)
	}

	deactivate () {
		this.subscriptions.dispose()
		this.view.destroy()
		this.statusBarTile.destroy() // TODO
	}

	addStatusBar (statusBar) {
		this.statusBar = statusBar
		this.statusBarTile = this.statusBar.addLeftTile({
			item: this.view,
			priority: 50
		})
	}

	parse ({count, fullKey, key}) {
		this.count = count || 0
		this.fullKey = fullKey || 'none'
		this.key = key || 'none'

		if (Number.isNaN(this.count)) this.count = 0
	}

	serialize () {
		return {
			count: this.count,
			deserializer: 'state',
			fullKey: this.fullKey,
			key: this.key
		}
	}
}
// endregion

// region config
const instance = new Count()
instance.config = {
	format: {
		type: 'string',
		default: '%c %f',
		description: 'Display format. %c = count, %k = key, %f = full key'
	}
}
{'fraction_non_alphanumeric': 0.16311713455953533, 'fraction_numerical': 0.0021781219748305907, 'mean_word_length': 2.8233117483811285, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '298023', 'n_tokens_mistral': 1746, 'n_tokens_neox': 1464, 'n_words': 305}