FCF 2.0 development in progress...
> > > >
[News] [Packages API] [Downloads] [Donate to the project] [Contacts]

fcf.id() function

string fcf.id(integer a_size = 32, boolean a_safeFirstChar = false)

Package: fcf-framework-core

File: fcf-framework-core:fcf.js

Available from version: 2.0.2

Creates a string from random characters in hex format

Arguments

a_size integer = 32
- Generated string length

boolean a_safeFirstChar = false
- If true, then the first character takes values from a-f. If false, then the first character takes values from 0-f.
Result
string
- Returns a string of random characters in hex format
Detailed description

By default, the function produces a random string with the first character equal to from a to f, this mode is especially relevant when using unique identifiers in DOM selectors and other elements where there are strict requirements for the first character of the identifier.

Example: Default mode

console.log(fcf.id());

Output:

a195145c84dccd930d10b7dc5f79780e

Example: Safe mode with length

console.log(fcf.id(8, true)); console.log(fcf.id(8, true)); console.log(fcf.id(8, true)); console.log(fcf.id(8, true)); console.log(fcf.id(8, true));

Output:

b6e501f8 a4038cb2 cd6b7730 caf4e2df f0778e08

Example: Unsafe mode with length

console.log(fcf.id(8, false)); console.log(fcf.id(8, false)); console.log(fcf.id(8, false)); console.log(fcf.id(8, false)); console.log(fcf.id(8, false));

Output:

81652eb4 e93f5046 09d0ab46 7db3e4a0 f19bd344