All files / ee/app/assets/javascripts/audit_events token_utils.js

100% Statements 10/10
100% Branches 11/11
100% Functions 5/5
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20          26x 27x   26x   26x 3x   26x   26x        
// These methods need to be separate from `./utils.js` to avoid a circular dependency.
 
import { MIN_USERNAME_LENGTH } from '~/lib/utils/constants';
import { isNumeric } from '~/lib/utils/number_utils';
 
export const parseUsername = (username) =>
  username && String(username).startsWith('@') ? username.slice(1) : username;
 
export const displayUsername = (username) => (username ? `@${username}` : null);
 
export const isValidUsername = (username) =>
  Boolean(username) && username.length >= MIN_USERNAME_LENGTH;
 
export const isValidEntityId = (id) => Boolean(id) && isNumeric(id) && parseInt(id, 10) > 0;
 
export const createToken = ({ type, data }) => ({
  type,
  value: { data, operator: '=' },
});