atom-nuclide
Version:
A unified developer experience for web and mobile development, built as a suite of features on top of Atom to provide hackability and the support of an active community.
31 lines (27 loc) • 932 B
JavaScript
Object.defineProperty(exports, '__esModule', {
value: true
});
exports.shortNameForAuthor = shortNameForAuthor;
/*
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the license found in the LICENSE file in
* the root directory of this source tree.
*/
// Mercurial history emails can be invalid.
var HG_EMAIL_REGEX = /\b([A-Za-z0-9._%+-]+)@[A-Za-z0-9.-]+\b/;
/**
* `hg blame` may return the 'user' name in a mix of formats:
* - foo@bar.com
* - bar@56abc2-24378f
* - Foo Bar <foo@bar.com>
* This method shortens the name in `blameName` to just
* return the beginning part of the email, iff an email is present.
* The examples above would become 'foo'.
*/
function shortNameForAuthor(blameName) {
var match = blameName.match(HG_EMAIL_REGEX);
// Index 0 will be the whole email. Index 1 is the capture group.
return match ? match[1] : blameName;
}