diff --git a/dist/__tests__/faker.test.d.ts b/dist/__tests__/faker.test.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/dist/__tests__/faker.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/helpers/__tests__/getLocale.test.d.ts b/dist/helpers/__tests__/getLocale.test.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/dist/helpers/__tests__/getLocale.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/helpers/__tests__/helpers.test.d.ts b/dist/helpers/__tests__/helpers.test.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/dist/helpers/__tests__/helpers.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/helpers/__tests__/randomArrayElement.test.d.ts b/dist/helpers/__tests__/randomArrayElement.test.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/dist/helpers/__tests__/randomArrayElement.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/helpers/__tests__/randomArrayElements.d.ts b/dist/helpers/__tests__/randomArrayElements.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/dist/helpers/__tests__/randomArrayElements.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/helpers/__tests__/randomNumber.test.d.ts b/dist/helpers/__tests__/randomNumber.test.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/dist/helpers/__tests__/randomNumber.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/helpers/getLocale.d.ts b/dist/helpers/getLocale.d.ts new file mode 100644 index 0000000..63f4d6b --- /dev/null +++ b/dist/helpers/getLocale.d.ts @@ -0,0 +1,13 @@ +import { Locale, LocaleObject } from '../types/locale'; +/** + * 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} locales + * @param {Locale} [selectedLocale=Locale.EN] + * @returns {T} + */ +export default function getLocale(locales: LocaleObject, selectedLocale?: Locale): T; diff --git a/dist/helpers/index.d.ts b/dist/helpers/index.d.ts new file mode 100644 index 0000000..9a69c5f --- /dev/null +++ b/dist/helpers/index.d.ts @@ -0,0 +1,11 @@ +import getLocale from './getLocale'; +import randomArrayElement from './randomArrayElement'; +import randomArrayElements from './randomArrayElements'; +import randomNumber from './randomNumber'; +declare const _default: { + getLocale: typeof getLocale; + randomArrayElement: typeof randomArrayElement; + randomArrayElements: typeof randomArrayElements; + randomNumber: typeof randomNumber; +}; +export default _default; diff --git a/dist/helpers/randomArrayElement.d.ts b/dist/helpers/randomArrayElement.d.ts new file mode 100644 index 0000000..5cedd98 --- /dev/null +++ b/dist/helpers/randomArrayElement.d.ts @@ -0,0 +1,9 @@ +/** + * Return a random element from given array + * + * @export + * @template T + * @param {T[]} collection + * @returns {T} + */ +export default function randomArrayElement(collection: T[]): T; diff --git a/dist/helpers/randomArrayElements.d.ts b/dist/helpers/randomArrayElements.d.ts new file mode 100644 index 0000000..95a150b --- /dev/null +++ b/dist/helpers/randomArrayElements.d.ts @@ -0,0 +1,12 @@ +/** + * 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[]} + */ +export default function randomArrayElements(collection: T[], amount: number): T[]; diff --git a/dist/helpers/randomNumber.d.ts b/dist/helpers/randomNumber.d.ts new file mode 100644 index 0000000..af9178e --- /dev/null +++ b/dist/helpers/randomNumber.d.ts @@ -0,0 +1,12 @@ +/** + * 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} + */ +export default function randomNumber(min?: number, max?: number, isFloating?: boolean): number; diff --git a/dist/index.d.ts b/dist/index.d.ts new file mode 100644 index 0000000..4891bb9 --- /dev/null +++ b/dist/index.d.ts @@ -0,0 +1,12 @@ +declare const faker: { + helpers: { + getLocale: typeof import("./helpers/getLocale").default; + randomArrayElement: typeof import("./helpers/randomArrayElement").default; + randomArrayElements: typeof import("./helpers/randomArrayElements").default; + randomNumber: typeof import("./helpers/randomNumber").default; + }; + name: { + firstName: typeof import("./name/firstName/firstName").default; + }; +}; +export default faker; diff --git a/dist/index.js b/dist/index.js new file mode 100644 index 0000000..8b599cd --- /dev/null +++ b/dist/index.js @@ -0,0 +1 @@ +!function(e){var a={};function n(r){if(a[r])return a[r].exports;var i=a[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}n.m=e,n.c=a,n.d=function(e,a,r){n.o(e,a)||Object.defineProperty(e,a,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,a){if(1&a&&(e=n(e)),8&a)return e;if(4&a&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&a&&"string"!=typeof e)for(var i in e)n.d(r,i,function(a){return e[a]}.bind(null,i));return r},n.n=function(e){var a=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(a,"a",a),a},n.o=function(e,a){return Object.prototype.hasOwnProperty.call(e,a)},n.p="/",n(n.s=25)}([function(e,a){var n=Array.isArray;e.exports=n},function(e,a,n){var r=n(2),i=n(4);e.exports=function(e){return"symbol"==typeof e||i(e)&&"[object Symbol]"==r(e)}},function(e,a,n){var r=n(9),i=n(34),o=n(35),t=r?r.toStringTag:void 0;e.exports=function(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":t&&t in Object(e)?i(e):o(e)}},function(e,a,n){var r=n(11),i="object"==typeof self&&self&&self.Object===Object&&self,o=r||i||Function("return this")();e.exports=o},function(e,a){e.exports=function(e){return null!=e&&"object"==typeof e}},function(e,a,n){var r=n(12)(Object,"create");e.exports=r},function(e,a){e.exports=function(e){var a=typeof e;return null!=e&&("object"==a||"function"==a)}},function(e,a,n){var r=n(14);e.exports=function(e,a){for(var n=e.length;n--;)if(r(e[n][0],a))return n;return-1}},function(e,a,n){var r=n(60);e.exports=function(e,a){var n=e.__data__;return r(a)?n["string"==typeof a?"string":"hash"]:n.map}},function(e,a,n){var r=n(3).Symbol;e.exports=r},function(e,a,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(a,"__esModule",{value:!0});var i=n(28),o=r(n(29));a.default=function(e,a){void 0===a&&(a=i.Locale.EN);var n=o.default(e,a);if(void 0===n&&(n=o.default(e,i.Locale.EN)),void 0===n)throw new Error("Cannot find locale "+a+", nor default fallback locale "+i.Locale.EN);return n}},function(e,a,n){(function(a){var n="object"==typeof a&&a&&a.Object===Object&&a;e.exports=n}).call(this,n(33))},function(e,a,n){var r=n(43),i=n(47);e.exports=function(e,a){var n=i(e,a);return r(n)?n:void 0}},function(e,a,n){var r=n(2),i=n(6);e.exports=function(e){if(!i(e))return!1;var a=r(e);return"[object Function]"==a||"[object GeneratorFunction]"==a||"[object AsyncFunction]"==a||"[object Proxy]"==a}},function(e,a){e.exports=function(e,a){return e===a||e!=e&&a!=a}},function(e,a){e.exports=function(e,a){for(var n=-1,r=null==e?0:e.length,i=Array(r);++n-1&&e%1==0&&e<=9007199254740991}},function(e,a){var n=/^(?:0|[1-9]\d*)$/;e.exports=function(e,a){var r=typeof e;return!!(a=null==a?9007199254740991:a)&&("number"==r||"symbol"!=r&&n.test(e))&&e>-1&&e%1==0&&e-1}},function(e,a,n){var r=n(7);e.exports=function(e,a){var n=this.__data__,i=r(n,e);return i<0?(++this.size,n.push([e,a])):n[i][1]=a,this}},function(e,a,n){var r=n(12)(n(3),"Map");e.exports=r},function(e,a,n){var r=n(8);e.exports=function(e){var a=r(this,e).delete(e);return this.size-=a?1:0,a}},function(e,a){e.exports=function(e){var a=typeof e;return"string"==a||"number"==a||"symbol"==a||"boolean"==a?"__proto__"!==e:null===e}},function(e,a,n){var r=n(8);e.exports=function(e){return r(this,e).get(e)}},function(e,a,n){var r=n(8);e.exports=function(e){return r(this,e).has(e)}},function(e,a,n){var r=n(8);e.exports=function(e,a){var n=r(this,e),i=n.size;return n.set(e,a),this.size+=n.size==i?0:1,this}},function(e,a,n){var r=n(65);e.exports=function(e){return null==e?"":r(e)}},function(e,a,n){var r=n(9),i=n(15),o=n(0),t=n(1),l=r?r.prototype:void 0,s=l?l.toString:void 0;e.exports=function e(a){if("string"==typeof a)return a;if(o(a))return i(a,e)+"";if(t(a))return s?s.call(a):"";var n=a+"";return"0"==n&&1/a==-1/0?"-0":n}},function(e,a,n){var r=n(1);e.exports=function(e){if("string"==typeof e||r(e))return e;var a=e+"";return"0"==a&&1/e==-1/0?"-0":a}},function(e,a,n){var r=n(18),i=n(68),o=n(22),t=parseFloat,l=Math.min,s=Math.random;e.exports=function(e,a,n){if(n&&"boolean"!=typeof n&&i(e,a,n)&&(a=n=void 0),void 0===n&&("boolean"==typeof a?(n=a,a=void 0):"boolean"==typeof e&&(n=e,e=void 0)),void 0===e&&void 0===a?(e=0,a=1):(e=o(e),void 0===a?(a=e,e=0):a=o(a)),e>a){var u=e;e=a,a=u}if(n||e%1||a%1){var c=s();return l(e+c*(a-e+t("1e-"+((c+"").length-1))),a)}return r(e,a)}},function(e,a,n){var r=n(14),i=n(19),o=n(21),t=n(6);e.exports=function(e,a,n){if(!t(n))return!1;var l=typeof a;return!!("number"==l?i(n)&&o(a,n.length):"string"==l&&a in n)&&r(n[a],e)}},function(e,a,n){var r=n(6),i=n(1),o=/^\s+|\s+$/g,t=/^[-+]0x[0-9a-f]+$/i,l=/^0b[01]+$/i,s=/^0o[0-7]+$/i,u=parseInt;e.exports=function(e){if("number"==typeof e)return e;if(i(e))return NaN;if(r(e)){var a="function"==typeof e.valueOf?e.valueOf():e;e=r(a)?a+"":a}if("string"!=typeof e)return 0===e?e:+e;e=e.replace(o,"");var n=l.test(e);return n||s.test(e)?u(e.slice(2),n?2:8):t.test(e)?NaN:+e}},function(e,a,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(a,"__esModule",{value:!0});var i=r(n(71)),o=r(n(92));a.default=function(e,a){var n=i.default(e);return o.default(n,a)}},function(e,a,n){var r=n(72),i=n(74),o=n(0);e.exports=function(e){return(o(e)?r:i)(e)}},function(e,a,n){var r=n(73),i=n(23);e.exports=function(e){return i(r(e))}},function(e,a){e.exports=function(e,a){var n=-1,r=e.length;for(a||(a=Array(r));++ni?0:i+a),(n=n>i?i:n)<0&&(n+=i),i=a>n?0:n-a>>>0,a>>>=0;for(var o=Array(i);++r; +export default locales; diff --git a/dist/name/firstName/locales/pt_BR/collection.d.ts b/dist/name/firstName/locales/pt_BR/collection.d.ts new file mode 100644 index 0000000..71490df --- /dev/null +++ b/dist/name/firstName/locales/pt_BR/collection.d.ts @@ -0,0 +1,2 @@ +declare const collection: string[]; +export default collection; diff --git a/dist/name/index.d.ts b/dist/name/index.d.ts new file mode 100644 index 0000000..63eab18 --- /dev/null +++ b/dist/name/index.d.ts @@ -0,0 +1,5 @@ +import firstName from './firstName/firstName'; +declare const _default: { + firstName: typeof firstName; +}; +export default _default; diff --git a/dist/types/locale.d.ts b/dist/types/locale.d.ts new file mode 100644 index 0000000..d92e8c5 --- /dev/null +++ b/dist/types/locale.d.ts @@ -0,0 +1,233 @@ +export declare enum Locale { + AF = "af", + AF_ZA = "af_ZA", + AR = "ar", + AR_AE = "ar_AE", + AR_BH = "ar_BH", + AR_DZ = "ar_DZ", + AR_EG = "ar_EG", + AR_IQ = "ar_IQ", + AR_JO = "ar_JO", + AR_KW = "ar_KW", + AR_LB = "ar_LB", + AR_LY = "ar_LY", + AR_MA = "ar_MA", + AR_OM = "ar_OM", + AR_QA = "ar_QA", + AR_SA = "ar_SA", + AR_SY = "ar_SY", + AR_TN = "ar_TN", + AR_YE = "ar_YE", + AZ = "az", + AZ_AZ = "az_AZ", + BE = "be", + BE_BY = "be_BY", + BG = "bg", + BG_BG = "bg_BG", + BS_BA = "bs_BA", + CA = "ca", + CA_ES = "ca_ES", + CS = "cs", + CS_CZ = "cs_CZ", + CY = "cy", + CY_GB = "cy_GB", + DA = "da", + DA_DK = "da_DK", + DE = "de", + DE_AT = "de_AT", + DE_CH = "de_CH", + DE_DE = "de_DE", + DE_LI = "de_LI", + DE_LU = "de_LU", + DV = "dv", + DV_MV = "dv_MV", + EL = "el", + EL_GR = "el_GR", + EN = "en", + EN_AU = "en_AU", + EN_BZ = "en_BZ", + EN_CA = "en_CA", + EN_CB = "en_CB", + EN_GB = "en_GB", + EN_IE = "en_IE", + EN_JM = "en_JM", + EN_NZ = "en_NZ", + EN_PH = "en_PH", + EN_TT = "en_TT", + EN_US = "en_US", + EN_ZA = "en_ZA", + EN_ZW = "en_ZW", + EO = "eo", + ES = "es", + ES_AR = "es_AR", + ES_BO = "es_BO", + ES_CL = "es_CL", + ES_CO = "es_CO", + ES_CR = "es_CR", + ES_DO = "es_DO", + ES_EC = "es_EC", + ES_ES = "es_ES", + ES_GT = "es_GT", + ES_HN = "es_HN", + ES_MX = "es_MX", + ES_NI = "es_NI", + ES_PA = "es_PA", + ES_PE = "es_PE", + ES_PR = "es_PR", + ES_PY = "es_PY", + ES_SV = "es_SV", + ES_UY = "es_UY", + ES_VE = "es_VE", + ET = "et", + ET_EE = "et_EE", + EU = "eu", + EU_ES = "eu_ES", + FA = "fa", + FA_IR = "fa_IR", + FI = "fi", + FI_FI = "fi_FI", + FO = "fo", + FO_FO = "fo_FO", + FR = "fr", + FR_BE = "fr_BE", + FR_CA = "fr_CA", + FR_CH = "fr_CH", + FR_FR = "fr_FR", + FR_LU = "fr_LU", + FR_MC = "fr_MC", + GL = "gl", + GL_ES = "gl_ES", + GU = "gu", + GU_IN = "gu_IN", + HE = "he", + HE_IL = "he_IL", + HI = "hi", + HI_IN = "hi_IN", + HR = "hr", + HR_BA = "hr_BA", + HR_HR = "hr_HR", + HU = "hu", + HU_HU = "hu_HU", + HY = "hy", + HY_AM = "hy_AM", + ID = "id", + ID_ID = "id_ID", + IS = "is", + IS_IS = "is_IS", + IT = "it", + IT_CH = "it_CH", + IT_IT = "it_IT", + JA = "ja", + JA_JP = "ja_JP", + KA = "ka", + KA_GE = "ka_GE", + KK = "kk", + KK_KZ = "kk_KZ", + KN = "kn", + KN_IN = "kn_IN", + KO = "ko", + KO_KR = "ko_KR", + KOK = "kok", + KOK_IN = "kok_IN", + KY = "ky", + KY_KG = "ky_KG", + LT = "lt", + LT_LT = "lt_LT", + LV = "lv", + LV_LV = "lv_LV", + MI = "mi", + MI_NZ = "mi_NZ", + MK = "mk", + MK_MK = "mk_MK", + MN = "mn", + MN_MN = "mn_MN", + MR = "mr", + MR_IN = "mr_IN", + MS = "ms", + MS_BN = "ms_BN", + MS_MY = "ms_MY", + MT = "mt", + MT_MT = "mt_MT", + NB = "nb", + NB_NO = "nb_NO", + NL = "nl", + NL_BE = "nl_BE", + NL_NL = "nl_NL", + NN_NO = "nn_NO", + NS = "ns", + NS_ZA = "ns_ZA", + PA = "pa", + PA_IN = "pa_IN", + PL = "pl", + PL_PL = "pl_PL", + PS = "ps", + PS_AR = "ps_AR", + PT = "pt", + PT_BR = "pt_BR", + PT_PT = "pt_PT", + QU = "qu", + QU_BO = "qu_BO", + QU_EC = "qu_EC", + QU_PE = "qu_PE", + RO = "ro", + RO_RO = "ro_RO", + RU = "ru", + RU_RU = "ru_RU", + SA = "sa", + SA_IN = "sa_IN", + SE = "se", + SE_FI = "se_FI", + SE_NO = "se_NO", + SE_SE = "se_SE", + SK = "sk", + SK_SK = "sk_SK", + SL = "sl", + SL_SI = "sl_SI", + SQ = "sq", + SQ_AL = "sq_AL", + SR_BA = "sr_BA", + SR_SP = "sr_SP", + SV = "sv", + SV_FI = "sv_FI", + SV_SE = "sv_SE", + SW = "sw", + SW_KE = "sw_KE", + SYR = "syr", + SYR_SY = "syr_SY", + TA = "ta", + TA_IN = "ta_IN", + TE = "te", + TE_IN = "te_IN", + TH = "th", + TH_TH = "th_TH", + TL = "tl", + TL_PH = "tl_PH", + TN = "tn", + TN_ZA = "tn_ZA", + TR = "tr", + TR_TR = "tr_TR", + TS = "ts", + TT = "tt", + TT_RU = "tt_RU", + UK = "uk", + UK_UA = "uk_UA", + UR = "ur", + UR_PK = "ur_PK", + UZ = "uz", + UZ_UZ = "uz_UZ", + VI = "vi", + VI_VN = "vi_VN", + XH = "xh", + XH_ZA = "xh_ZA", + ZH = "zh", + ZH_CN = "zh_CN", + ZH_HK = "zh_HK", + ZH_MO = "zh_MO", + ZH_SG = "zh_SG", + ZH_TW = "zh_TW", + ZU = "zu", + ZU_ZA = "zu_ZA" +} +export declare type LocaleObject = { + [K in Locale]?: T; +}; diff --git a/package.json b/package.json index 304ccc3..7ff2cbc 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,8 @@ "name": "faker-es6", "version": "0.1.1", "description": "A heavily inspired lib to generate massive amounts of realistic fake data. This lib was inspired by what I would like to see in Marak/faker.js plus I though it could be a good exercise", - "main": "index.js", + "main": "dist/index.js", + "types": "dist/index.d.ts", "repository": "git@github.com:samir-araujo/faker-es6.git", "author": "Samir J M Araujo ", "license": "MIT", diff --git a/tsconfig.json b/tsconfig.json index f463b8c..69ac2e4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,11 +8,11 @@ // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ - // "declaration": true, /* Generates corresponding '.d.ts' file. */ + "declaration": true /* Generates corresponding '.d.ts' file. */, // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ // "sourceMap": true, /* Generates corresponding '.map' file. */ // "outFile": "./", /* Concatenate and emit output to single file. */ - // "outDir": "./", /* Redirect output structure to the directory. */ + "outDir": "./dist" /* Redirect output structure to the directory. */, // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ // "composite": true, /* Enable project compilation */ // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */