All files uuid.js

90.9% Statements 20/22
77.77% Branches 7/9
71.42% Functions 5/7
90.9% Lines 20/22

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 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50      102x 3162x 3162x 3162x       1x 1x     1x       1x       1x   1x           1x 3x             1x 6x 6x 6x   6x 4x   6x 6x    
import { shortid } from 'ray-visutil/lib/shortid';
 
export default function uuid() {
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
    const r = (Math.random() * 16) | 0;
    const v = c === 'x' ? r : (r & 0x3) | 0x8;
    return v.toString(16);
  });
}
 
export const uuidV1 = () => {
  return uuid().replace('-', '');
};
 
export const particleEmitterID = () => {
  return `SPE-Emittor-${shortid(16)}`;
};
 
export const genEleId = (prefix = '') => {
  return `${prefix}_${uuidV1()}`;
};
 
let index = 0;
 
const indexes = {};
 
/**
 * 创建 Object3D name
 * @param {String} name
 */
export const genObject3DName = (name = '_Things') => {
  return `${name}#${index++}`;
};
 
/**
 * 获取 unique name
 * @param {*} type
 */
export const getUniqueName = (type = 'Stuff') => {
  let _indexKey = type;
  Eif (_indexKey){
    _indexKey = _indexKey.toLowerCase();
  }
  if (!indexes[_indexKey]){
    indexes[_indexKey] = 0;
  }
  indexes[_indexKey] += 1;
  return `${type}#${indexes[_indexKey]}`;
};