Skip to content

Commit

Permalink
Merge branch 'main' into refactor-tuple-coordinate
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 authored Mar 25, 2022
2 parents 571d2e4 + a299c22 commit d549ce8
Show file tree
Hide file tree
Showing 25 changed files with 114 additions and 68 deletions.
2 changes: 1 addition & 1 deletion docs/.vitepress/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
api-pages.mjs
api-pages.ts
9 changes: 5 additions & 4 deletions docs/.vitepress/config.mjs → docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { DefaultTheme } from 'vitepress';
import { defineConfig } from 'vitepress';
import { apiPages } from './api-pages.mjs';
import { apiPages } from './api-pages';

const nav = [
const nav: DefaultTheme.NavItem[] = [
{ text: 'Guide', link: '/guide/' },
{
text: 'Ecosystem',
Expand All @@ -14,7 +15,7 @@ const nav = [
// { text: 'Playground', link: '/playground/' },
];

const sidebar = {
const sidebar: DefaultTheme.MultiSideBarConfig = {
'/': [
{
text: 'Guide',
Expand All @@ -40,7 +41,7 @@ const sidebar = {
],
};

const algolia = {
const algolia: DefaultTheme.AlgoliaSearchOptions = {
apiKey: process.env.API_KEY,
appId: process.env.APP_ID,
indexName: 'fakerjs',
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions docs/.vitepress/theme/components/vue.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module '*.vue' {
const component: any;
export default component;
}
File renamed without changes.
6 changes: 3 additions & 3 deletions scripts/apidoc/apiDocsWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { Method } from '../../docs/.vitepress/components/api-docs/method';
import type { PageIndex } from './utils';
import { pathDocsDir, pathOutputDir } from './utils';

const pathDocsApiPages = resolve(pathDocsDir, '.vitepress', 'api-pages.mjs');
const pathDocsApiPages = resolve(pathDocsDir, '.vitepress', 'api-pages.ts');

const scriptCommand = 'pnpm run generate:api-docs';

Expand Down Expand Up @@ -133,8 +133,8 @@ export const ${lowerModuleName}: Method[] = ${JSON.stringify(
* @param pages The pages to write into the index.
*/
export function writeApiPagesIndex(pages: PageIndex): void {
// Write api-pages.mjs
console.log('Updating api-pages.mjs');
// Write api-pages.ts
console.log('Updating api-pages.ts');
pages.sort((a, b) => a.text.localeCompare(b.text));
let apiPagesContent = `
// This file is automatically generated.
Expand Down
5 changes: 1 addition & 4 deletions scripts/apidoc/signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,7 @@ function typeToText(type_: Type, short = false): string {
.sort()
.join(' | ');
case 'reference':
if (
typeof type.typeArguments === 'undefined' ||
!type.typeArguments.length
) {
if (!type.typeArguments || !type.typeArguments.length) {
return type.name;
} else {
return `${type.name}<${type.typeArguments
Expand Down
4 changes: 2 additions & 2 deletions scripts/generateLocales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function escapeField(module: string): string {
}

function containsAll(checked?: string[], expected?: string[]): boolean {
if (typeof expected === 'undefined' || typeof checked === 'undefined') {
if (expected == null || checked == null) {
return true;
}
return expected.every((c) => checked.includes(c));
Expand Down Expand Up @@ -185,7 +185,7 @@ function generateRecursiveModuleIndexes(
// Overwrite types of src/locales/<locale>/<module>/index.ts for known DEFINITIONS
if (depth === 1) {
moduleFiles = DEFINITIONS[submodule];
if (typeof moduleFiles === 'undefined') {
if (moduleFiles == null) {
moduleDefinition = 'any';
} else {
moduleDefinition = `${submodule.replace(/(^|_)([a-z])/g, (s) =>
Expand Down
2 changes: 1 addition & 1 deletion src/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class Address {
*/
zipCode(format?: string): string {
// if zip format is not specified, use the zip format defined for the locale
if (typeof format === 'undefined') {
if (format == null) {
const localeFormat = this.faker.definitions.address.postcode;
if (typeof localeFormat === 'string') {
format = localeFormat;
Expand Down
6 changes: 3 additions & 3 deletions src/datatype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class Datatype {
for (const p in options) {
opts[p] = options[p];
}
if (typeof opts.precision === 'undefined') {
if (opts.precision == null) {
opts.precision = 0.01;
}
return this.faker.datatype.number(opts);
Expand All @@ -122,11 +122,11 @@ export class Datatype {
let min = typeof options === 'number' ? undefined : options?.min;
let max = typeof options === 'number' ? options : options?.max;

if (typeof min === 'undefined' || min < minMax * -1) {
if (min == null || min < minMax * -1) {
min = Date.UTC(1990, 0);
}

if (typeof max === 'undefined' || max > minMax) {
if (max == null || max > minMax) {
max = Date.UTC(2100, 0);
}

Expand Down
14 changes: 5 additions & 9 deletions src/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,8 @@ export class _Date {
betweens(
from: string | Date | number,
to: string | Date | number,
num?: number
num: number = 3
): Date[] {
if (typeof num === 'undefined') {
num = 3;
}

const dates: Date[] = [];

while (dates.length < num) {
Expand Down Expand Up @@ -210,12 +206,12 @@ export class _Date {
const source = this.faker.definitions.date.month;
let type: keyof DateEntryDefinition;
if (abbr) {
if (context && typeof source['abbr_context'] !== 'undefined') {
if (context && source['abbr_context'] != null) {
type = 'abbr_context';
} else {
type = 'abbr';
}
} else if (context && typeof source['wide_context'] !== 'undefined') {
} else if (context && source['wide_context'] != null) {
type = 'wide_context';
} else {
type = 'wide';
Expand Down Expand Up @@ -244,12 +240,12 @@ export class _Date {
const source = this.faker.definitions.date.weekday;
let type: keyof DateEntryDefinition;
if (abbr) {
if (context && typeof source['abbr_context'] !== 'undefined') {
if (context && source['abbr_context'] != null) {
type = 'abbr_context';
} else {
type = 'abbr';
}
} else if (context && typeof source['wide_context'] !== 'undefined') {
} else if (context && source['wide_context'] != null) {
type = 'wide_context';
} else {
type = 'wide';
Expand Down
4 changes: 2 additions & 2 deletions src/fake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ export class Fake {
// split the method into module and function
const parts = method.split('.');

if (typeof this.faker[parts[0]] === 'undefined') {
if (this.faker[parts[0]] == null) {
throw new Error('Invalid module: ' + parts[0]);
}

if (typeof this.faker[parts[0]][parts[1]] === 'undefined') {
if (this.faker[parts[0]][parts[1]] == null) {
throw new Error('Invalid method: ' + parts[0] + '.' + parts[1]);
}

Expand Down
6 changes: 3 additions & 3 deletions src/faker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class Faker {
// TODO @Shinigami92 2022-01-11: Find a way to load this even more dynamically
// In a way so that we don't accidentally miss a definition
Object.entries(DEFINITIONS).forEach(([t, v]) => {
if (typeof this.definitions[t] === 'undefined') {
if (this.definitions[t] == null) {
this.definitions[t] = {};
}

Expand All @@ -109,8 +109,8 @@ export class Faker {
Object.defineProperty(this.definitions[t], p, {
get: () => {
if (
typeof this.locales[this.locale][t] === 'undefined' ||
typeof this.locales[this.locale][t][p] === 'undefined'
this.locales[this.locale][t] == null ||
this.locales[this.locale][t][p] == null
) {
// certain localization sets contain less data then others.
// in the case of a missing definition, use the default localeFallback
Expand Down
3 changes: 1 addition & 2 deletions src/finance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ export class Finance {
*/
mask(length?: number, parens?: boolean, ellipsis?: boolean): string {
// set defaults
length =
length === 0 || !length || typeof length === 'undefined' ? 4 : length;
length = length || 4;
parens = parens == null ? true : parens;
ellipsis = ellipsis == null ? true : ellipsis;

Expand Down
10 changes: 5 additions & 5 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ export class Helpers {
let tmp: number;
let repetitions: number;
let token = string.match(RANGE_REP_REG);
while (token !== null) {
while (token != null) {
min = parseInt(token[2]);
max = parseInt(token[3]);
// switch min and max
Expand All @@ -369,7 +369,7 @@ export class Helpers {
}
// Deal with repeat `{num}`
token = string.match(REP_REG);
while (token !== null) {
while (token != null) {
repetitions = parseInt(token[2]);
string =
string.slice(0, token.index) +
Expand All @@ -381,7 +381,7 @@ export class Helpers {
//TODO: implement for letters e.g. [0-9a-zA-Z] etc.

token = string.match(RANGE_REG);
while (token !== null) {
while (token != null) {
min = parseInt(token[1]); // This time we are not capturing the char before `[]`
max = parseInt(token[2]);
// switch min and max
Expand Down Expand Up @@ -412,7 +412,7 @@ export class Helpers {
* faker.helpers.shuffle(['a', 'b', 'c']) // [ 'b', 'c', 'a' ]
*/
shuffle<T>(o?: T[]): T[] {
if (typeof o === 'undefined' || o.length === 0) {
if (o == null || o.length === 0) {
return o || [];
}

Expand Down Expand Up @@ -481,7 +481,7 @@ export class Helpers {
string | ((substring: string, ...args: any[]) => string)
>
): string {
if (typeof str === 'undefined') {
if (str == null) {
return '';
}
for (const p in data) {
Expand Down
4 changes: 2 additions & 2 deletions src/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ export class Image {
width = width || 640;
height = height || 480;
let protocol = 'http://';
if (typeof https !== 'undefined' && https === true) {
if (https === true) {
protocol = 'https://';
}
let url = `${protocol}placeimg.com/${width}/${height}`;
if (typeof category !== 'undefined') {
if (category != null) {
url += '/' + category;
}

Expand Down
2 changes: 1 addition & 1 deletion src/image_providers/lorempixel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class Lorempixel {
height = height || 480;

let url = `https://lorempixel.com/${width}/${height}`;
if (typeof category !== 'undefined') {
if (category != null) {
url += '/' + category;
}

Expand Down
4 changes: 2 additions & 2 deletions src/image_providers/unsplash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ export class Unsplash {

let url = 'https://source.unsplash.com';

if (typeof category !== 'undefined') {
if (category != null) {
url += '/category/' + category;
}

url += `/${width}x${height}`;

if (typeof keyword !== 'undefined') {
if (keyword != null) {
const keywordFormat = /^([A-Za-z0-9].+,[A-Za-z0-9]+)$|^([A-Za-z0-9]+)$/;
if (keywordFormat.test(keyword)) {
url += '?' + keyword;
Expand Down
2 changes: 1 addition & 1 deletion src/internet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ export class Internet {
prefix?: string
): string {
len = len || 15;
if (typeof memorable === 'undefined') {
if (memorable == null) {
memorable = false;
}
/*
Expand Down
15 changes: 6 additions & 9 deletions src/lorem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class Lorem {
word(length?: number): string {
const hasRightLength = (word: string) => word.length === length;
let properLengthWords: readonly string[];
if (typeof length === 'undefined') {
if (length == null) {
properLengthWords = this.faker.definitions.lorem.words;
} else {
properLengthWords =
Expand All @@ -49,10 +49,7 @@ export class Lorem {
* faker.lorem.words() // 'qui praesentium pariatur'
* faker.lorem.words(10) // 'debitis consectetur voluptatem non doloremque ipsum autem totam eum ratione'
*/
words(num?: number): string {
if (typeof num === 'undefined') {
num = 3;
}
words(num: number = 3): string {
const words: string[] = [];
for (let i = 0; i < num; i++) {
words.push(this.faker.lorem.word());
Expand All @@ -70,7 +67,7 @@ export class Lorem {
* faker.lorem.sentence(5) // 'Laborum voluptatem officiis est et.'
*/
sentence(wordCount?: number): string {
if (typeof wordCount === 'undefined') {
if (wordCount == null) {
wordCount = this.faker.datatype.number({ min: 3, max: 10 });
}

Expand Down Expand Up @@ -105,10 +102,10 @@ export class Lorem {
* // Et perspiciatis ipsam omnis.'
*/
sentences(sentenceCount?: number, separator?: string): string {
if (typeof sentenceCount === 'undefined') {
if (sentenceCount == null) {
sentenceCount = this.faker.datatype.number({ min: 2, max: 6 });
}
if (typeof separator === 'undefined') {
if (separator == null) {
separator = ' ';
}
const sentences: string[] = [];
Expand Down Expand Up @@ -208,7 +205,7 @@ export class Lorem {
* // Voluptate aut aut.'
*/
lines(lineCount?: number): string {
if (typeof lineCount === 'undefined') {
if (lineCount == null) {
lineCount = this.faker.datatype.number({ min: 1, max: 5 });
}
return this.faker.lorem.sentences(lineCount, '\n');
Expand Down
12 changes: 6 additions & 6 deletions src/random.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ export class Random {
words(count?: number): string {
const words: string[] = [];

if (typeof count === 'undefined') {
if (count == null) {
count = this.faker.datatype.number({ min: 1, max: 3 });
}

Expand Down Expand Up @@ -380,22 +380,22 @@ export class Random {
| number
| { count?: number; upcase?: boolean; bannedChars?: string[] }
): string {
if (typeof options === 'undefined') {
if (options == null) {
options = {
count: 1,
};
} else if (typeof options === 'number') {
options = {
count: options,
};
} else if (typeof options.count === 'undefined') {
} else if (options.count == null) {
options.count = 1;
}

if (typeof options.upcase === 'undefined') {
if (options.upcase == null) {
options.upcase = false;
}
if (typeof options.bannedChars === 'undefined') {
if (options.bannedChars == null) {
options.bannedChars = [];
}

Expand Down Expand Up @@ -455,7 +455,7 @@ export class Random {
count: number = 1,
options: { bannedChars?: string[] } = {}
): string {
if (typeof options.bannedChars === 'undefined') {
if (options.bannedChars == null) {
options.bannedChars = [];
}

Expand Down
Loading

0 comments on commit d549ce8

Please sign in to comment.