Skip to content

Instantly share code, notes, and snippets.

@spellew
Created March 1, 2018 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spellew/a3b25269cadb2455820471509347a5b6 to your computer and use it in GitHub Desktop.
Save spellew/a3b25269cadb2455820471509347a5b6 to your computer and use it in GitHub Desktop.
/*
* Copyright (C) 2018 Shamroy Pellew
*
* This file is part of MusicBrainz, the open internet music database,
* and is licensed under the GPL version 2, or (at your option) any
* later version: http://www.gnu.org/licenses/gpl-2.0.txt
*/
const React = require('react');
exports.formatPercentage = (n) => {
return n.toLocaleString($c.stash.current_language,
{maximumFractionDigits: 2, minimumFractionDigits: 2, style: 'percent'});
};
exports.formatCount = (n) => {
return n.toLocaleString($c.stash.current_language);
};
exports.LinkSearchableProperty = ({
searchField,
searchValue,
entityType,
text,
}) => {
const params = {limit: 25, method: 'advanced', query: searchField + ':"' + searchValue + '"', type: entityType};
return (
<a href={'/search?' + encodeURIComponent(Object.keys(params).map(key => key + '=' + params[key]).join('&'))}>
{text ? text : searchValue}
</a>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment