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

Method alpha

src/modules/string/index.ts:173–247  ·  view source on GitHub ↗

* Generating a string consisting of letters in the English alphabet. * * @param options Either the length of the string to generate or the optional options object. * @param options.length The length of the string to generate either as a fixed length or as a length range. Defaults to `1`.

(
    options:
      | number
      | {
          /**
           * The length of the string to generate either as a fixed length or as a length range.
           *
           * @default 1
           */
          length?:
            | number
            | {
                /**
                 * The minimum length of the string to generate.
                 */
                min: number;
                /**
                 * The maximum length of the string to generate.
                 */
                max: number;
              };
          /**
           * The casing of the characters.
           *
           * @default 'mixed'
           */
          casing?: Casing;
          /**
           * An array with characters which should be excluded in the generated string.
           *
           * @default []
           */
          exclude?: ReadonlyArray<LiteralUnion<AlphaChar>> | string;
        } = {}
  )

Source from the content-addressed store, hash-verified

171 * @since 8.0.0
172 */
173 alpha(
174 options:
175 | number
176 | {
177 /**
178 * The length of the string to generate either as a fixed length or as a length range.
179 *
180 * @default 1
181 */
182 length?:
183 | number
184 | {
185 /**
186 * The minimum length of the string to generate.
187 */
188 min: number;
189 /**
190 * The maximum length of the string to generate.
191 */
192 max: number;
193 };
194 /**
195 * The casing of the characters.
196 *
197 * @default 'mixed'
198 */
199 casing?: Casing;
200 /**
201 * An array with characters which should be excluded in the generated string.
202 *
203 * @default []
204 */
205 exclude?: ReadonlyArray<LiteralUnion<AlphaChar>> | string;
206 } = {}
207 ): string {
208 if (typeof options === 'number') {
209 options = {
210 length: options,
211 };
212 }
213
214 const length = this.faker.helpers.rangeToNumber(options.length ?? 1);
215 if (length <= 0) {
216 return '';
217 }
218
219 const { casing = 'mixed' } = options;
220 let { exclude = [] } = options;
221
222 if (typeof exclude === 'string') {
223 exclude = [...exclude];
224 }
225
226 let charsArray: string[];
227 switch (casing) {
228 case 'upper': {
229 charsArray = [...UPPER_CHARS];
230 break;

Callers 6

string.spec.tsFile · 0.80
bicMethod · 0.80
vinMethod · 0.80
vrmMethod · 0.80
makeValidDomainWordSlugFunction · 0.80

Calls 2

fromCharactersMethod · 0.95
rangeToNumberMethod · 0.80

Tested by

no test coverage detected