MCPcopy
hub / github.com/faker-js/faker / binary

Method binary

src/modules/string/index.ts:362–394  ·  view source on GitHub ↗

* Returns a [binary](https://en.wikipedia.org/wiki/Binary_number) string. * * @param options The optional options object. * @param options.length The length of the string (excluding the prefix) to generate either as a fixed length or as a length range. Defaults to `1`. * @param options.p

(
    options: {
      /**
       * The length of the string (excluding the prefix) to generate either as a fixed length or as a length range.
       *
       * @default 1
       */
      length?:
        | number
        | {
            /**
             * The minimum length of the string (excluding the prefix) to generate.
             */
            min: number;
            /**
             * The maximum length of the string (excluding the prefix) to generate.
             */
            max: number;
          };
      /**
       * Prefix for the generated number.
       *
       * @default '0b'
       */
      prefix?: string;
    } = {}
  )

Source from the content-addressed store, hash-verified

360 * @since 8.0.0
361 */
362 binary(
363 options: {
364 /**
365 * The length of the string (excluding the prefix) to generate either as a fixed length or as a length range.
366 *
367 * @default 1
368 */
369 length?:
370 | number
371 | {
372 /**
373 * The minimum length of the string (excluding the prefix) to generate.
374 */
375 min: number;
376 /**
377 * The maximum length of the string (excluding the prefix) to generate.
378 */
379 max: number;
380 };
381 /**
382 * Prefix for the generated number.
383 *
384 * @default '0b'
385 */
386 prefix?: string;
387 } = {}
388 ): string {
389 const { prefix = '0b' } = options;
390
391 let result = prefix;
392 result += this.fromCharacters(['0', '1'], options.length ?? 1);
393 return result;
394 }
395
396 /**
397 * Returns an [octal](https://en.wikipedia.org/wiki/Octal) string.

Callers

nothing calls this directly

Calls 1

fromCharactersMethod · 0.95

Tested by

no test coverage detected