Skip to content

Commit

Permalink
fix(general): fix build process for general consumption
Browse files Browse the repository at this point in the history
+ Fix entrypoints for NPM distribution
+ Drop Laravel Mix in favour of tsc
+ Update README to reflect changes

BREAKING CHANGE: Fix import for general consumption
  • Loading branch information
samir-araujo committed Apr 1, 2020
1 parent acf8bea commit 173a53d
Show file tree
Hide file tree
Showing 33 changed files with 3,597 additions and 3,660 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ npm install --dev faker-es6
### First name example

```ts
import { firstName } from 'faker-es6/name/firstName';
import { firstName } from 'faker-es6/lib/name/firstName';

const name = firstName(); // Random first name: Yessenia
const anotherName = firstName(); // Random first name: Marilyne
Expand All @@ -57,8 +57,8 @@ const anotherName = firstName(); // Random first name: Marilyne
### First name with locale example

```ts
import { firstName } from 'faker-es6/name/firstName';
import Locale from 'faker-es6/types/locale';
import { firstName } from 'faker-es6/lib/name/firstName';
import { Locale } from 'faker-es6/lib/types/locale';

const name = firstName(Locale.PT_BR); // Random first name in pt_BR: Bruna
const anotherName = firstName(Locale.PT_BR); // Random first name in pt_BR: Paula
Expand Down Expand Up @@ -216,8 +216,8 @@ To use a locale, just pass it as a parameter in the method you want to use.
### Localization example with TypeScript

```ts
import { firstName } from 'faker-es6/name/firstName';
import Locale from 'faker-es6/types/locale';
import { firstName } from 'faker-es6/lib/name/firstName';
import { Locale } from 'faker-es6/lib/types/locale';

const name = firstName(Locale.PT_BR); // Random first name in pt_BR: Bruna
const anotherName = firstName(Locale.PT_BR); // Random first name in pt_BR: Paula
Expand All @@ -228,7 +228,7 @@ const anotherName = firstName(Locale.PT_BR); // Random first name in pt_BR: Paul
### Localization example without TypeScript

```ts
import { firstName } from 'faker-es6/name/firstName';
import { firstName } from 'faker-es6/lib/name/firstName';

const name = firstName('pt_BR'); // Random first name in pt_BR: Bruna
const anotherName = firstName('pt_BR'); // Random first name in pt_BR: Paula
Expand Down
1 change: 0 additions & 1 deletion dist/index.js

This file was deleted.

2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
moduleFileExtensions: ['js', 'json', 'jsx', 'ts', 'tsx', 'node', 'd.ts'],
modulePathIgnorePatterns: ['<rootDir>/dist/']
modulePathIgnorePatterns: ['<rootDir>/lib/']
};
File renamed without changes.
30 changes: 30 additions & 0 deletions lib/helpers/getLocale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var locale_1 = require("../types/locale");
var get_1 = __importDefault(require("lodash/get"));
/**
* Return selectedLocale from locales collection.
* If selectedLocale is not found, it will return Locale.EN as fallback.
* If both are not present, them it will throw an error
*
* @export
* @template T
* @param {LocaleObject<T>} locales
* @param {Locale} [selectedLocale=Locale.EN]
* @returns {T}
*/
function getLocale(locales, selectedLocale) {
if (selectedLocale === void 0) { selectedLocale = locale_1.Locale.EN; }
var locale = get_1.default(locales, selectedLocale);
if (locale === undefined) {
locale = get_1.default(locales, locale_1.Locale.EN);
}
if (locale === undefined) {
throw new Error("Cannot find locale " + selectedLocale + ", nor default fallback locale " + locale_1.Locale.EN);
}
return locale;
}
exports.default = getLocale;
File renamed without changes.
10 changes: 10 additions & 0 deletions lib/helpers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var getLocale_1 = __importDefault(require("./getLocale"));
var randomArrayElement_1 = __importDefault(require("./randomArrayElement"));
var randomArrayElements_1 = __importDefault(require("./randomArrayElements"));
var randomNumber_1 = __importDefault(require("./randomNumber"));
exports.default = { getLocale: getLocale_1.default, randomArrayElement: randomArrayElement_1.default, randomArrayElements: randomArrayElements_1.default, randomNumber: randomNumber_1.default };
File renamed without changes.
21 changes: 21 additions & 0 deletions lib/helpers/randomArrayElement.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var randomNumber_1 = __importDefault(require("./randomNumber"));
/**
* Return a random element from given array
*
* @export
* @template T
* @param {T[]} collection
* @returns {T}
*/
function randomArrayElement(collection) {
var min = 0;
var max = collection.length - 1;
var index = randomNumber_1.default(min, max);
return collection[index];
}
exports.default = randomArrayElement;
File renamed without changes.
23 changes: 23 additions & 0 deletions lib/helpers/randomArrayElements.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var shuffle_1 = __importDefault(require("lodash/shuffle"));
var take_1 = __importDefault(require("lodash/take"));
/**
* Return N random items from given array.
* If the amount of items requested is greater than collection length,
* it will return as many items as possible
*
* @export
* @template T
* @param {T[]} collection
* @param {number} amount
* @returns {T[]}
*/
function randomArrayElements(collection, amount) {
var shuffledCollection = shuffle_1.default(collection);
return take_1.default(shuffledCollection, amount);
}
exports.default = randomArrayElements;
File renamed without changes.
28 changes: 28 additions & 0 deletions lib/helpers/randomNumber.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var random_1 = __importDefault(require("lodash/random"));
/**
* Return a random number between min and max values.
* By default this function returns integers numbers, but can
* return float if isFloating = true
*
* @export
* @param {number} [min]
* @param {number} [max]
* @param {boolean} [isFloating=false]
* @returns {number}
*/
function randomNumber(min, max, isFloating) {
if (isFloating === void 0) { isFloating = false; }
if (min === undefined) {
min = 0;
}
if (max === undefined) {
max = min + 100;
}
return random_1.default(min, max, isFloating);
}
exports.default = randomNumber;
2 changes: 1 addition & 1 deletion dist/index.d.ts → lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ declare const faker: {
randomNumber: typeof import("./helpers/randomNumber").default;
};
name: {
firstName: typeof import("./name/firstName/firstName").default;
firstName: typeof import("./name/firstName").default;
};
};
export default faker;
9 changes: 9 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var helpers_1 = __importDefault(require("./helpers"));
var name_1 = __importDefault(require("./name"));
var faker = { helpers: helpers_1.default, name: name_1.default };
exports.default = faker;
File renamed without changes.
22 changes: 22 additions & 0 deletions lib/name/firstName/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var getLocale_1 = __importDefault(require("../../helpers/getLocale"));
var locales_1 = __importDefault(require("./locales"));
var randomArrayElement_1 = __importDefault(require("../../helpers/randomArrayElement"));
/**
* Return a random first name.
* If a valid locale is given, it will the locale collection.
* If the given locale is not valid, it will fallback to Locale.EN
*
* @export
* @param {Locale} [selectedLocale]
* @returns {string}
*/
function firstName(selectedLocale) {
var collection = getLocale_1.default(locales_1.default, selectedLocale);
return randomArrayElement_1.default(collection);
}
exports.default = firstName;
Loading

0 comments on commit 173a53d

Please sign in to comment.