Skip to content

Commit

Permalink
Merge branch 'main' into downgrade-npm-to-6
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT authored Apr 1, 2022
2 parents d44156a + 802998b commit 3808f0b
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 62 deletions.
14 changes: 7 additions & 7 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# These owners will be the default owners for everything in the repo.
# Unless a later match takes precedence, @faker-js/maintainers will
# Unless a later match takes precedence, @faker-js/maintainers will
# be requested for review when someone opens a pull request.

* @faker-js/maintainers
* @faker-js/maintainers

# ================================================
# Docs owners ...
# ================================================

/docs/ @faker-js/maintainers-docs
netlify.toml @faker-js/maintainers-docs
README.md @faker-js/maintainers-docs @faker-js/maintainers
CONTRIBUTING.md @faker-js/maintainers-docs
/docs/ @faker-js/maintainers-docs @faker-js/maintainers
netlify.toml @faker-js/maintainers-docs @faker-js/maintainers
README.md @faker-js/maintainers-docs @faker-js/maintainers
CONTRIBUTING.md @faker-js/maintainers-docs @faker-js/maintainers

# ================================================
# CODEOWNERS owners ...
# ================================================

/.github/CODEOWNERS @faker-js/maintainers
/.github/CODEOWNERS @faker-js/maintainers
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@
"typedoc-plugin-missing-exports": "~0.22.6",
"typescript": "~4.6.3",
"validator": "~13.7.0",
"vite": "~2.9.0",
"vite": "~2.9.1",
"vitepress": "~0.22.3",
"vitest": "~0.8.0"
},
"packageManager": "[email protected].3",
"packageManager": "[email protected].4",
"engines": {
"node": ">=14.0.0",
"npm": ">=6.0.0"
Expand Down
18 changes: 9 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 13 additions & 16 deletions src/address.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import type { Faker } from '.';
import type { Fake } from './fake';
import type { Helpers } from './helpers';

let f: Fake['fake'];

/**
* Converts degrees to radians.
Expand Down Expand Up @@ -77,12 +73,7 @@ function coordinateWithOffset(
* Module to generate addresses and locations.
*/
export class Address {
readonly Helpers: Helpers;

constructor(private readonly faker: Faker) {
f = this.faker.fake;
this.Helpers = this.faker.helpers;

// Bind `this` so namespaced is working correctly
for (const name of Object.getOwnPropertyNames(Address.prototype)) {
if (name === 'constructor' || typeof this[name] !== 'function') {
Expand Down Expand Up @@ -116,7 +107,7 @@ export class Address {
format = this.faker.random.arrayElement(localeFormat);
}
}
return this.Helpers.replaceSymbols(format);
return this.faker.helpers.replaceSymbols(format);
}

/**
Expand Down Expand Up @@ -177,7 +168,7 @@ export class Address {
format = this.faker.datatype.number(formats.length - 1);
}

return f(formats[format]);
return this.faker.fake(formats[format]);
}

/**
Expand Down Expand Up @@ -256,19 +247,19 @@ export class Address {
switch (this.faker.datatype.number(2)) {
case 0:
address =
this.Helpers.replaceSymbolWithNumber('#####') +
this.faker.helpers.replaceSymbolWithNumber('#####') +
' ' +
this.faker.address.streetName();
break;
case 1:
address =
this.Helpers.replaceSymbolWithNumber('####') +
this.faker.helpers.replaceSymbolWithNumber('####') +
' ' +
this.faker.address.streetName();
break;
case 2:
address =
this.Helpers.replaceSymbolWithNumber('###') +
this.faker.helpers.replaceSymbolWithNumber('###') +
' ' +
this.faker.address.streetName();
break;
Expand Down Expand Up @@ -309,7 +300,7 @@ export class Address {
* faker.address.secondaryAddress() // 'Apt. 861'
*/
secondaryAddress(): string {
return this.Helpers.replaceSymbolWithNumber(
return this.faker.helpers.replaceSymbolWithNumber(
this.faker.random.arrayElement(
this.faker.definitions.address.secondary_address
)
Expand Down Expand Up @@ -538,7 +529,13 @@ export class Address {
// This approach will likely result in a higher density of points near the center.
const randomCoord = coordinateWithOffset(
coordinate,
degreesToRadians(Math.random() * 360.0),
degreesToRadians(
this.faker.datatype.number({
min: 0,
max: 360,
precision: 1e-4,
})
),
radius,
isMetric
);
Expand Down
28 changes: 0 additions & 28 deletions src/commerce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,34 +89,6 @@ export class Commerce {
);
}

// TODO @Shinigami92 2022-01-12: unimplemented member functions

/*
categories (num) {
var categories = [];
do {
var category = this.faker.random.arrayElement(this.faker.definitions.commerce.department);
if(categories.indexOf(category) === -1) {
categories.push(category);
}
} while(categories.length < num);
return categories;
};
*/
/*
mergeCategories (categories) {
var separator = this.faker.definitions.separator || " &";
// TODO: find undefined here
categories = categories || this.faker.definitions.commerce.categories;
var commaSeparated = categories.slice(0, -1).join(', ');
return [commaSeparated, categories[categories.length - 1]].join(separator + " ");
};
*/

/**
* Returns an adjective describing a product.
*
Expand Down
14 changes: 14 additions & 0 deletions test/address.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const seededRuns = [
cardinalDirection: 'East',
cardinalDirectionAbbr: 'E',
timeZone: 'Europe/Amsterdam',
nearbyGpsCoordinates: ['-0.0394', '0.0396'],
},
},
{
Expand Down Expand Up @@ -58,6 +59,7 @@ const seededRuns = [
cardinalDirection: 'East',
cardinalDirectionAbbr: 'E',
timeZone: 'Africa/Casablanca',
nearbyGpsCoordinates: ['-0.0042', '0.0557'],
},
},
{
Expand Down Expand Up @@ -87,6 +89,7 @@ const seededRuns = [
cardinalDirection: 'West',
cardinalDirectionAbbr: 'W',
timeZone: 'Asia/Magadan',
nearbyGpsCoordinates: ['0.0503', '-0.0242'],
},
},
];
Expand Down Expand Up @@ -333,6 +336,17 @@ describe('address', () => {
expect(timeZone).toEqual(expectations.timeZone);
});
});

describe('nearbyGPSCoordinate()', () => {
it('returns expected coordinates', () => {
faker.seed(seed);

// this input is required for all expected results for this function
const coordsInput: [number, number] = [0, 0];
const coords = faker.address.nearbyGPSCoordinate(coordsInput);
expect(coords).toEqual(expectations.nearbyGpsCoordinates);
});
});
});
}

Expand Down

0 comments on commit 3808f0b

Please sign in to comment.