Ignore:
Timestamp:
12/12/24 17:06:06 (6 weeks ago)
Author:
stefan toskovski <stefantoska84@…>
Branches:
main
Children:
79a0317
Parents:
d565449
Message:

Pred finalna verzija

Location:
imaps-frontend/node_modules/nanoid/async
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified imaps-frontend/node_modules/nanoid/async/index.browser.cjs

    rd565449 r0c6b92a  
    11let random = async bytes => crypto.getRandomValues(new Uint8Array(bytes))
     2
    23let customAlphabet = (alphabet, defaultSize = 21) => {
     4  // First, a bitmask is necessary to generate the ID. The bitmask makes bytes
     5  // values closer to the alphabet size. The bitmask calculates the closest
     6  // `2^31 - 1` number, which exceeds the alphabet size.
     7  // For example, the bitmask for the alphabet size 30 is 31 (00011111).
     8  // `Math.clz32` is not used, because it is not available in browsers.
    39  let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
     10  // Though, the bitmask solution is not perfect since the bytes exceeding
     11  // the alphabet size are refused. Therefore, to reliably generate the ID,
     12  // the random bytes redundancy has to be satisfied.
     13
     14  // Note: every hardware random generator call is performance expensive,
     15  // because the system call for entropy collection takes a lot of time.
     16  // So, to avoid additional system calls, extra bytes are requested in advance.
     17
     18  // Next, a step determines how many random bytes to generate.
     19  // The number of random bytes gets decided upon the ID size, mask,
     20  // alphabet size, and magic number 1.6 (using 1.6 peaks at performance
     21  // according to benchmarks).
     22
     23  // `-~f => Math.ceil(f)` if f is a float
     24  // `-~i => i + 1` if i is an integer
    425  let step = -~((1.6 * mask * defaultSize) / alphabet.length)
     26
    527  return async (size = defaultSize) => {
    628    let id = ''
    729    while (true) {
    830      let bytes = crypto.getRandomValues(new Uint8Array(step))
    9       let i = step
     31      // A compact alternative for `for (var i = 0; i < step; i++)`.
     32      let i = step | 0
    1033      while (i--) {
     34        // Adding `|| ''` refuses a random byte that exceeds the alphabet size.
    1135        id += alphabet[bytes[i] & mask] || ''
    1236        if (id.length === size) return id
     
    1539  }
    1640}
     41
    1742let nanoid = async (size = 21) => {
    1843  let id = ''
    19   let bytes = crypto.getRandomValues(new Uint8Array(size))
     44  let bytes = crypto.getRandomValues(new Uint8Array((size |= 0)))
     45
     46  // A compact alternative for `for (var i = 0; i < step; i++)`.
    2047  while (size--) {
     48    // It is incorrect to use bytes exceeding the alphabet size.
     49    // The following mask reduces the random byte in the 0-255 value
     50    // range to the 0-63 value range. Therefore, adding hacks, such
     51    // as empty string fallback or magic numbers, is unneccessary because
     52    // the bitmask trims bytes down to the alphabet size.
    2153    let byte = bytes[size] & 63
    2254    if (byte < 36) {
     55      // `0-9a-z`
    2356      id += byte.toString(36)
    2457    } else if (byte < 62) {
     58      // `A-Z`
    2559      id += (byte - 26).toString(36).toUpperCase()
    2660    } else if (byte < 63) {
     
    3266  return id
    3367}
     68
    3469module.exports = { nanoid, customAlphabet, random }
  • TabularUnified imaps-frontend/node_modules/nanoid/async/index.browser.js

    rd565449 r0c6b92a  
    11let random = async bytes => crypto.getRandomValues(new Uint8Array(bytes))
     2
    23let customAlphabet = (alphabet, defaultSize = 21) => {
     4  // First, a bitmask is necessary to generate the ID. The bitmask makes bytes
     5  // values closer to the alphabet size. The bitmask calculates the closest
     6  // `2^31 - 1` number, which exceeds the alphabet size.
     7  // For example, the bitmask for the alphabet size 30 is 31 (00011111).
     8  // `Math.clz32` is not used, because it is not available in browsers.
    39  let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
     10  // Though, the bitmask solution is not perfect since the bytes exceeding
     11  // the alphabet size are refused. Therefore, to reliably generate the ID,
     12  // the random bytes redundancy has to be satisfied.
     13
     14  // Note: every hardware random generator call is performance expensive,
     15  // because the system call for entropy collection takes a lot of time.
     16  // So, to avoid additional system calls, extra bytes are requested in advance.
     17
     18  // Next, a step determines how many random bytes to generate.
     19  // The number of random bytes gets decided upon the ID size, mask,
     20  // alphabet size, and magic number 1.6 (using 1.6 peaks at performance
     21  // according to benchmarks).
     22
     23  // `-~f => Math.ceil(f)` if f is a float
     24  // `-~i => i + 1` if i is an integer
    425  let step = -~((1.6 * mask * defaultSize) / alphabet.length)
     26
    527  return async (size = defaultSize) => {
    628    let id = ''
    729    while (true) {
    830      let bytes = crypto.getRandomValues(new Uint8Array(step))
    9       let i = step
     31      // A compact alternative for `for (var i = 0; i < step; i++)`.
     32      let i = step | 0
    1033      while (i--) {
     34        // Adding `|| ''` refuses a random byte that exceeds the alphabet size.
    1135        id += alphabet[bytes[i] & mask] || ''
    1236        if (id.length === size) return id
     
    1539  }
    1640}
     41
    1742let nanoid = async (size = 21) => {
    1843  let id = ''
    19   let bytes = crypto.getRandomValues(new Uint8Array(size))
     44  let bytes = crypto.getRandomValues(new Uint8Array((size |= 0)))
     45
     46  // A compact alternative for `for (var i = 0; i < step; i++)`.
    2047  while (size--) {
     48    // It is incorrect to use bytes exceeding the alphabet size.
     49    // The following mask reduces the random byte in the 0-255 value
     50    // range to the 0-63 value range. Therefore, adding hacks, such
     51    // as empty string fallback or magic numbers, is unneccessary because
     52    // the bitmask trims bytes down to the alphabet size.
    2153    let byte = bytes[size] & 63
    2254    if (byte < 36) {
     55      // `0-9a-z`
    2356      id += byte.toString(36)
    2457    } else if (byte < 62) {
     58      // `A-Z`
    2559      id += (byte - 26).toString(36).toUpperCase()
    2660    } else if (byte < 63) {
     
    3266  return id
    3367}
     68
    3469export { nanoid, customAlphabet, random }
  • TabularUnified imaps-frontend/node_modules/nanoid/async/index.cjs

    rd565449 r0c6b92a  
    11let crypto = require('crypto')
     2
    23let { urlAlphabet } = require('../url-alphabet/index.cjs')
     4
     5// `crypto.randomFill()` is a little faster than `crypto.randomBytes()`,
     6// because it is possible to use in combination with `Buffer.allocUnsafe()`.
    37let random = bytes =>
    48  new Promise((resolve, reject) => {
     9    // `Buffer.allocUnsafe()` is faster because it doesn’t flush the memory.
     10    // Memory flushing is unnecessary since the buffer allocation itself resets
     11    // the memory with the new bytes.
    512    crypto.randomFill(Buffer.allocUnsafe(bytes), (err, buf) => {
    613      if (err) {
     
    1118    })
    1219  })
     20
    1321let customAlphabet = (alphabet, defaultSize = 21) => {
     22  // First, a bitmask is necessary to generate the ID. The bitmask makes bytes
     23  // values closer to the alphabet size. The bitmask calculates the closest
     24  // `2^31 - 1` number, which exceeds the alphabet size.
     25  // For example, the bitmask for the alphabet size 30 is 31 (00011111).
    1426  let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
     27  // Though, the bitmask solution is not perfect since the bytes exceeding
     28  // the alphabet size are refused. Therefore, to reliably generate the ID,
     29  // the random bytes redundancy has to be satisfied.
     30
     31  // Note: every hardware random generator call is performance expensive,
     32  // because the system call for entropy collection takes a lot of time.
     33  // So, to avoid additional system calls, extra bytes are requested in advance.
     34
     35  // Next, a step determines how many random bytes to generate.
     36  // The number of random bytes gets decided upon the ID size, mask,
     37  // alphabet size, and magic number 1.6 (using 1.6 peaks at performance
     38  // according to benchmarks).
    1539  let step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length)
     40
    1641  let tick = (id, size = defaultSize) =>
    1742    random(step).then(bytes => {
     43      // A compact alternative for `for (var i = 0; i < step; i++)`.
    1844      let i = step
    1945      while (i--) {
     46        // Adding `|| ''` refuses a random byte that exceeds the alphabet size.
    2047        id += alphabet[bytes[i] & mask] || ''
    21         if (id.length === size) return id
     48        if (id.length >= size) return id
    2249      }
    2350      return tick(id, size)
    2451    })
     52
    2553  return size => tick('', size)
    2654}
     55
    2756let nanoid = (size = 21) =>
    28   random(size).then(bytes => {
     57  random((size |= 0)).then(bytes => {
    2958    let id = ''
     59    // A compact alternative for `for (var i = 0; i < step; i++)`.
    3060    while (size--) {
     61      // It is incorrect to use bytes exceeding the alphabet size.
     62      // The following mask reduces the random byte in the 0-255 value
     63      // range to the 0-63 value range. Therefore, adding hacks, such
     64      // as empty string fallback or magic numbers, is unneccessary because
     65      // the bitmask trims bytes down to the alphabet size.
    3166      id += urlAlphabet[bytes[size] & 63]
    3267    }
    3368    return id
    3469  })
     70
    3571module.exports = { nanoid, customAlphabet, random }
  • TabularUnified imaps-frontend/node_modules/nanoid/async/index.js

    rd565449 r0c6b92a  
    11import crypto from 'crypto'
     2
    23import { urlAlphabet } from '../url-alphabet/index.js'
     4
     5// `crypto.randomFill()` is a little faster than `crypto.randomBytes()`,
     6// because it is possible to use in combination with `Buffer.allocUnsafe()`.
    37let random = bytes =>
    48  new Promise((resolve, reject) => {
     9    // `Buffer.allocUnsafe()` is faster because it doesn’t flush the memory.
     10    // Memory flushing is unnecessary since the buffer allocation itself resets
     11    // the memory with the new bytes.
    512    crypto.randomFill(Buffer.allocUnsafe(bytes), (err, buf) => {
    613      if (err) {
     
    1118    })
    1219  })
     20
    1321let customAlphabet = (alphabet, defaultSize = 21) => {
     22  // First, a bitmask is necessary to generate the ID. The bitmask makes bytes
     23  // values closer to the alphabet size. The bitmask calculates the closest
     24  // `2^31 - 1` number, which exceeds the alphabet size.
     25  // For example, the bitmask for the alphabet size 30 is 31 (00011111).
    1426  let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
     27  // Though, the bitmask solution is not perfect since the bytes exceeding
     28  // the alphabet size are refused. Therefore, to reliably generate the ID,
     29  // the random bytes redundancy has to be satisfied.
     30
     31  // Note: every hardware random generator call is performance expensive,
     32  // because the system call for entropy collection takes a lot of time.
     33  // So, to avoid additional system calls, extra bytes are requested in advance.
     34
     35  // Next, a step determines how many random bytes to generate.
     36  // The number of random bytes gets decided upon the ID size, mask,
     37  // alphabet size, and magic number 1.6 (using 1.6 peaks at performance
     38  // according to benchmarks).
    1539  let step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length)
     40
    1641  let tick = (id, size = defaultSize) =>
    1742    random(step).then(bytes => {
     43      // A compact alternative for `for (var i = 0; i < step; i++)`.
    1844      let i = step
    1945      while (i--) {
     46        // Adding `|| ''` refuses a random byte that exceeds the alphabet size.
    2047        id += alphabet[bytes[i] & mask] || ''
    21         if (id.length === size) return id
     48        if (id.length >= size) return id
    2249      }
    2350      return tick(id, size)
    2451    })
     52
    2553  return size => tick('', size)
    2654}
     55
    2756let nanoid = (size = 21) =>
    28   random(size).then(bytes => {
     57  random((size |= 0)).then(bytes => {
    2958    let id = ''
     59    // A compact alternative for `for (var i = 0; i < step; i++)`.
    3060    while (size--) {
     61      // It is incorrect to use bytes exceeding the alphabet size.
     62      // The following mask reduces the random byte in the 0-255 value
     63      // range to the 0-63 value range. Therefore, adding hacks, such
     64      // as empty string fallback or magic numbers, is unneccessary because
     65      // the bitmask trims bytes down to the alphabet size.
    3166      id += urlAlphabet[bytes[size] & 63]
    3267    }
    3368    return id
    3469  })
     70
    3571export { nanoid, customAlphabet, random }
  • TabularUnified imaps-frontend/node_modules/nanoid/async/index.native.js

    rd565449 r0c6b92a  
    11import { getRandomBytesAsync } from 'expo-random'
     2
    23import { urlAlphabet } from '../url-alphabet/index.js'
     4
    35let random = getRandomBytesAsync
     6
    47let customAlphabet = (alphabet, defaultSize = 21) => {
     8  // First, a bitmask is necessary to generate the ID. The bitmask makes bytes
     9  // values closer to the alphabet size. The bitmask calculates the closest
     10  // `2^31 - 1` number, which exceeds the alphabet size.
     11  // For example, the bitmask for the alphabet size 30 is 31 (00011111).
    512  let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
     13  // Though, the bitmask solution is not perfect since the bytes exceeding
     14  // the alphabet size are refused. Therefore, to reliably generate the ID,
     15  // the random bytes redundancy has to be satisfied.
     16
     17  // Note: every hardware random generator call is performance expensive,
     18  // because the system call for entropy collection takes a lot of time.
     19  // So, to avoid additional system calls, extra bytes are requested in advance.
     20
     21  // Next, a step determines how many random bytes to generate.
     22  // The number of random bytes gets decided upon the ID size, mask,
     23  // alphabet size, and magic number 1.6 (using 1.6 peaks at performance
     24  // according to benchmarks).
    625  let step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length)
     26
    727  let tick = (id, size = defaultSize) =>
    828    random(step).then(bytes => {
     29      // A compact alternative for `for (var i = 0; i < step; i++)`.
    930      let i = step
    1031      while (i--) {
     32        // Adding `|| ''` refuses a random byte that exceeds the alphabet size.
    1133        id += alphabet[bytes[i] & mask] || ''
    12         if (id.length === size) return id
     34        if (id.length >= size) return id
    1335      }
    1436      return tick(id, size)
    1537    })
     38
    1639  return size => tick('', size)
    1740}
     41
    1842let nanoid = (size = 21) =>
    19   random(size).then(bytes => {
     43  random((size |= 0)).then(bytes => {
    2044    let id = ''
     45    // A compact alternative for `for (var i = 0; i < step; i++)`.
    2146    while (size--) {
     47      // It is incorrect to use bytes exceeding the alphabet size.
     48      // The following mask reduces the random byte in the 0-255 value
     49      // range to the 0-63 value range. Therefore, adding hacks, such
     50      // as empty string fallback or magic numbers, is unneccessary because
     51      // the bitmask trims bytes down to the alphabet size.
    2252      id += urlAlphabet[bytes[size] & 63]
    2353    }
    2454    return id
    2555  })
     56
    2657export { nanoid, customAlphabet, random }
Note: See TracChangeset for help on using the changeset viewer.