summaryrefslogtreecommitdiff
path: root/packages/frontend-shared/js/extract-avg-color-from-blurhash.ts
blob: 992f6e9a16de373928a82de50ff368ecdceeb797 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*
 * SPDX-FileCopyrightText: syuilo and misskey-project
 * SPDX-License-Identifier: AGPL-3.0-only
 */

export function extractAvgColorFromBlurhash(hash: string) {
	return typeof hash === 'string'
		? '#' + [...hash.slice(2, 6)]
			.map(x => '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz#$%*+,-.:;=?@[]^_{|}~'.indexOf(x))
			.reduce((a, c) => a * 83 + c, 0)
			.toString(16)
			.padStart(6, '0')
		: undefined;
}