mirror of
https://github.com/aleleba/chartjs-2-react.git
synced 2025-07-02 11:48:17 -06:00
Se sube a version 1.0.10 Se sube a GitHub 1.0.10 Se sube a NPM 1.0.10
25 lines
901 B
JavaScript
25 lines
901 B
JavaScript
// Generate unique IDs for use as pseudo-private/protected names.
|
|
// Similar in concept to
|
|
// <http://wiki.ecmascript.org/doku.php?id=strawman:names>.
|
|
//
|
|
// The goals of this function are twofold:
|
|
//
|
|
// * Provide a way to generate a string guaranteed to be unique when compared
|
|
// to other strings generated by this function.
|
|
// * Make the string complex enough that it is highly unlikely to be
|
|
// accidentally duplicated by hand (this is key if you're using `ID`
|
|
// as a private/protected name on an object).
|
|
//
|
|
// Use:
|
|
//
|
|
// var privateName = ID();
|
|
// var o = { 'public': 'foo' };
|
|
// o[privateName] = 'bar';
|
|
var ID = function () {
|
|
// Math.random should be unique because of its seeding algorithm.
|
|
// Convert it to base 36 (numbers + letters), and grab the first 9 characters
|
|
// after the decimal.
|
|
return '_' + Math.random().toString(36).substr(2, 9);
|
|
};
|
|
|
|
export default ID |