creditu-common-library 2.3.7-beta.0 → 2.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintrc.js ADDED
@@ -0,0 +1,60 @@
1
+ module.exports = {
2
+ parser: '@typescript-eslint/parser',
3
+ parserOptions: {
4
+ ecmaVersion: 12,
5
+ sourceType: 'module'
6
+ },
7
+ plugins: [
8
+ '@typescript-eslint',
9
+ '@typescript-eslint/eslint-plugin'
10
+ ],
11
+ extends: ['airbnb-base'],
12
+ root: true,
13
+ env: {
14
+ node: true,
15
+ es2021: true,
16
+ jest: true
17
+ },
18
+ rules: {
19
+ '@typescript-eslint/member-delimiter-style': [
20
+ 'error', { multiline: { delimiter: 'semi', requireLast: true } }
21
+ ],
22
+ '@typescript-eslint/type-annotation-spacing': ['error', { before: false, after: true }],
23
+ '@typescript-eslint/no-explicit-any': 'off',
24
+ '@typescript-eslint/no-empty-function': 'off',
25
+ '@typescript-eslint/indent': ['error', 2],
26
+ '@typescript-eslint/no-unused-vars': ['error'],
27
+ '@typescript-eslint/space-infix-ops': ['error'],
28
+ 'no-useless-constructor': 'off',
29
+ 'no-empty-function': 'off',
30
+ 'no-shadow': 'off',
31
+ 'import/prefer-default-export': 'off',
32
+ 'import/extensions': ['error', 'never', { ignorePackages: true }],
33
+ 'object-curly-newline': ['error', { consistent: true }],
34
+ 'object-property-newline': ['error', { allowAllPropertiesOnSameLine: true }],
35
+ 'arrow-parens': ['error', 'as-needed'],
36
+ 'array-bracket-spacing': ['error'],
37
+ 'no-trailing-spaces': 'error',
38
+ 'semi-spacing': 'error',
39
+ 'max-len': ['error', { code: 150 }],
40
+ 'space-before-function-paren': [
41
+ 'error', { anonymous: 'never', named: 'never', asyncArrow: 'always' }
42
+ ],
43
+ 'arrow-spacing': ['error'],
44
+ 'key-spacing': 'error',
45
+ 'space-in-parens': 'error',
46
+ 'no-spaced-func': 'error',
47
+ 'keyword-spacing': 'error',
48
+ 'comma-spacing': ['error', { before: false, after: true }],
49
+ 'comma-dangle': ['error', 'never'],
50
+ 'no-console': ['error'],
51
+ 'no-underscore-dangle': ['error', { allow: ['_value'] }],
52
+ quotes: ['error', 'single', { avoidEscape: true }],
53
+ 'class-methods-use-this': 'off'
54
+ },
55
+ settings: {
56
+ 'import/resolver': {
57
+ node: { extensions: ['.js', '.ts'] }
58
+ }
59
+ }
60
+ };
package/README.md ADDED
@@ -0,0 +1,121 @@
1
+ # Creditú CommonLibrary
2
+
3
+ ## Descripción
4
+ Esta librería, contiene los módulos y funciones matemáticas y financerias para el manejo de cálculos en el producto digital.
5
+
6
+ ## Instalar en tu repositorio
7
+
8
+ ```shell
9
+ npm i creditu-common-library
10
+ ```
11
+
12
+ ## Uso en tu repositorio
13
+ La librería tiene dos módulos:
14
+
15
+ - `Math`: expone el service `MathService`, que tiene funciones para realizar operaciones matemáticas básicas:
16
+ - add: (Suma) `add = (...numbers: number[]): number`
17
+ - substract: (Resta) `subtract = (...numbers: number[]): number`
18
+ - multiply: (Multiplicación) `multiply = (...numbers: number[]): number`
19
+ - divide: (División) `divide = (...numbers: number[]): number`
20
+ - round: (Redondeo) `round = (num: number, resolution: number): number`
21
+
22
+ - `Finance`: expone varios servicios orientados a un dominio específico, y cuyas funciones resuelven diversas fórmulas financieras en su ámbito.
23
+ Los services expuestos son:
24
+ - `ConstantsService`: es un servicio auxiliar, que contiene funciones que calculan constantes que, a su vez, agrupan parametros conocidos para diversos propósitos en cálculos financieros.
25
+ - `CreditInsuranceService`: este servicio tiene funciones de cálculo para el dominio `Seguros`.
26
+ - `FinanceService`: este servicio auxiliar tiene funciones genéricas de funciones financieras, como interés anual, mensual, etc.
27
+ - `PaymentService`: este servicio tiene funciones de cálculo para el dominio `Dividendo`.
28
+ - `LoanToValueService`: este servicio tiene funciones de cálculo para el dominio `LTV`.
29
+ - `MaximumLocalService`: este servicio tiene funciones de cálculo para el dominio `Máximos Locales`.
30
+ - `OfferService`: este servicio tiene funciones de cálculo para el dominio `Oferta`.
31
+ - `OperationalExpensesService`: este servicio tiene funciones de cálculo para el dominio `Gastos Operacionales`.
32
+
33
+ Además, existen models que sirven de apoyo para estandarizar los parámetros de algunas funciones.
34
+
35
+
36
+ Para más información sobre las funciones, sus usos, parámetros de entrada y salida, puedes revisar cada servicio y su comentario expecífico.
37
+ La mayoría de estas funciones, tienen una definición matemática asociada. Encontrarás un link con esa definición junto con cada función.
38
+
39
+ ## Uso de módulos y servicios en tu repositorio
40
+
41
+ ### Módulo Math:
42
+ ```shell
43
+ import { MathService } from 'creditu-common-library/math';
44
+ ...
45
+ const mathService = new MathService(true, 10);
46
+ ...
47
+ const result = mathService.add(1,2);
48
+ ...
49
+ ```
50
+
51
+ ### Módulo Finance:
52
+
53
+ Services:
54
+ ```shell
55
+ import { OfferService } from 'creditu-common-library/finance/services';
56
+ ```
57
+
58
+ Models:
59
+ ```shell
60
+ import { OfferInputs } from 'creditu-common-library/finance/models';
61
+ ```
62
+
63
+ Functions:
64
+ ```shell
65
+ ...
66
+ import { OfferService } from 'creditu-common-library/finance/services';
67
+ import { OfferInputs } from 'creditu-common-library/finance/models';
68
+ import { OfferParams } from 'creditu-common-library/finance/models';
69
+
70
+ ...
71
+ private offerService: OfferService;
72
+
73
+ ...
74
+ const offerInputs: OfferInputs = ...
75
+ const offerParams: OfferParams = ...
76
+ const result = this.offerService.calculateCreditAmountToOffer(offerInputs, offerParams);
77
+
78
+ ...
79
+ ```
80
+
81
+ ## Desarrollo local
82
+ 1. Crea un **symlink** global para una dependencia con `npm link`.
83
+ 2. Hazle saber al proyecto donde probarás tu paquete que use el enlace simbólico global con `npm link creditu-common-library`.
84
+
85
+ ### Uso
86
+ Entonces en el directorio del paquete en desarrollo creditu-common-library ejecutaremos.
87
+
88
+ ```shell
89
+ $ npm link # paso 1
90
+ ```
91
+
92
+ Luego en el directorio del proyecto donde probarás el paquete:
93
+ ```shell
94
+ npm link creditu-common-library # paso 2
95
+ ```
96
+ ### Trouble shouting
97
+ > En caso de problemas,
98
+ > - Verificar que la version de node debe ser la misma que el enlace creado en el proyecto utilizado.
99
+ > - Para crear el enlace simbólico copiar el archivo `package.json` en el directorio `lib`, y en este ejecutar `npm link`.
100
+
101
+ Ahora puedes editar, transpilar o ejecutar pruebas en creditu-common-library.
102
+ Todo mientras lo pruebas en un proyecto real. Los enlaces simbólicos son locales y no serás commiteados en git.
103
+ Y cuando estés listo para compartir tu código, puedes publicar los cambios de creditu-common-library en un registry npm.
104
+
105
+ ### De vuelta a la normalidad
106
+ Cuando ya no desees utilizar la versión local de creditu-common-library, elimina el enlace simbólico.
107
+ Pero cuidado, npm unlink es un alias para la desinstalación de npm (npm uninstall),
108
+ no refleja el comportamiento de npm link.
109
+
110
+ Por eso en el directorio del proyecto donde estabas probando el paquete:
111
+ ```shell
112
+ npm unlink --no-save creditu-common-library && npm install
113
+ ```
114
+
115
+ Luego puedes limpiar el enlace global, aunque su presencia no interferirá con nada.
116
+ En el directorio del paquete en desarollo:
117
+
118
+ ```shell
119
+ npm unlink # elimina el symlink
120
+ ```
121
+
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ presets: [
3
+ ['@babel/preset-env', { targets: { node: 'current' } }],
4
+ '@babel/preset-typescript',
5
+ ],
6
+ };
@@ -0,0 +1,199 @@
1
+ import type { Config } from 'jest';
2
+
3
+ const config: Config = {
4
+ // All imported modules in your tests should be mocked automatically
5
+ // automock: false,
6
+
7
+ // Stop running tests after `n` failures
8
+ // bail: 0,
9
+
10
+ // The directory where Jest should store its cached dependency information
11
+ // cacheDirectory: "/tmp/jest_rs",
12
+
13
+ // Automatically clear mock calls and instances between every test
14
+ clearMocks: true,
15
+
16
+ // Indicates whether the coverage information should be collected while executing the test
17
+ collectCoverage: false,
18
+
19
+ // An array of glob patterns indicating a set of files for which coverage information should be collected
20
+ // collectCoverageFrom: undefined,
21
+
22
+ // The directory where Jest should output its coverage files
23
+ coverageDirectory: 'coverage',
24
+
25
+ // An array of regexp pattern strings used to skip coverage collection
26
+ // coveragePathIgnorePatterns: [
27
+ // "/node_modules/"
28
+ // ],
29
+
30
+ // Indicates which provider should be used to instrument code for coverage
31
+ coverageProvider: 'v8',
32
+
33
+ // A list of reporter names that Jest uses when writing coverage reports
34
+ // coverageReporters: [
35
+ // "json",
36
+ // "text",
37
+ // "lcov",
38
+ // "clover"
39
+ // ],
40
+
41
+ // An object that configures minimum threshold enforcement for coverage results
42
+ // coverageThreshold: undefined,
43
+
44
+ // A path to a custom dependency extractor
45
+ // dependencyExtractor: undefined,
46
+
47
+ // Make calling deprecated APIs throw helpful error messages
48
+ // errorOnDeprecated: false,
49
+
50
+ // Force coverage collection from ignored files using an array of glob patterns
51
+ // forceCoverageMatch: [],
52
+
53
+ // A path to a module which exports an async function that is triggered once before all test suites
54
+ // globalSetup: undefined,
55
+
56
+ // A path to a module which exports an async function that is triggered once after all test suites
57
+ // globalTeardown: undefined,
58
+
59
+ // A set of global variables that need to be available in all test environments
60
+ // globals: {},
61
+
62
+ // The maximum amount of workers used to run your tests. Can be specified as % or a number.
63
+ // E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
64
+ // maxWorkers: "50%",
65
+
66
+ // An array of directory names to be searched recursively up from the requiring module's location
67
+ // moduleDirectories: [
68
+ // "node_modules"
69
+ // ],
70
+
71
+ // An array of file extensions your modules use
72
+ moduleFileExtensions: [
73
+ 'js',
74
+ // "json",
75
+ // "jsx",
76
+ 'ts'
77
+ // "tsx",
78
+ // "node"
79
+ ],
80
+
81
+ // A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
82
+ // moduleNameMapper: {},
83
+
84
+ // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
85
+ // modulePathIgnorePatterns: [],
86
+
87
+ // Activates notifications for test results
88
+ // notify: false,
89
+
90
+ // An enum that specifies notification mode. Requires { notify: true }
91
+ // notifyMode: "failure-change",
92
+
93
+ // A preset that is used as a base for Jest's configuration
94
+ // preset: undefined,
95
+
96
+ // Run tests from one or more projects
97
+ // projects: undefined,
98
+
99
+ // Use this configuration option to add custom reporters to Jest
100
+ // reporters: undefined,
101
+
102
+ // Automatically reset mock state between every test
103
+ // resetMocks: false,
104
+
105
+ // Reset the module registry before running each individual test
106
+ // resetModules: false,
107
+
108
+ // A path to a custom resolver
109
+ // resolver: undefined,
110
+
111
+ // Automatically restore mock state between every test
112
+ restoreMocks: true,
113
+
114
+ // The root directory that Jest should scan for tests and modules within
115
+ rootDir: './test',
116
+
117
+ // A list of paths to directories that Jest should use to search for files in
118
+ // roots: [
119
+ // "<rootDir>"
120
+ // ],
121
+
122
+ // Allows you to use a custom runner instead of Jest's default test runner
123
+ // runner: "jest-runner",
124
+
125
+ // The paths to modules that run some code to configure or set up the testing environment before each test
126
+ // setupFiles: [],
127
+
128
+ // A list of paths to modules that run some code to configure or set up the testing framework before each test
129
+ // setupFilesAfterEnv: [],
130
+
131
+ // The number of seconds after which a test is considered as slow and reported as such in the results.
132
+ // slowTestThreshold: 5,
133
+
134
+ // A list of paths to snapshot serializer modules Jest should use for snapshot testing
135
+ // snapshotSerializers: [],
136
+
137
+ // The test environment that will be used for testing
138
+ testEnvironment: 'node',
139
+
140
+ // Options that will be passed to the testEnvironment
141
+ // testEnvironmentOptions: {},
142
+
143
+ // Adds a location field to test results
144
+ // testLocationInResults: false,
145
+
146
+ // The glob patterns Jest uses to detect test files
147
+ // testMatch: [
148
+ // "**/__tests__/**/*.[jt]s?(x)",
149
+ // "**/?(*.)+(spec|test).[tj]s?(x)"
150
+ // ],
151
+
152
+ // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
153
+ // testPathIgnorePatterns: [
154
+ // "/node_modules/"
155
+ // ],
156
+
157
+ // The regexp pattern or array of patterns that Jest uses to detect test files
158
+ testRegex: [
159
+ '.spec.ts$'
160
+ ],
161
+
162
+ // This option allows the use of a custom results processor
163
+ // testResultsProcessor: undefined,
164
+
165
+ // This option allows use of a custom test runner
166
+ // testRunner: "jasmine2",
167
+
168
+ // This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
169
+ // testURL: "http://localhost",
170
+
171
+ // Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
172
+ // timers: "real",
173
+
174
+ // A map from regular expressions to paths to transformers
175
+ transform: {
176
+ '^.+\\.(t|j)s$': 'ts-jest'
177
+ },
178
+
179
+ // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
180
+ // transformIgnorePatterns: [
181
+ // "/node_modules/",
182
+ // "\\.pnp\\.[^\\/]+$"
183
+ // ],
184
+
185
+ // An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
186
+ // unmockedModulePathPatterns: undefined,
187
+
188
+ // Indicates whether each individual test should be reported during the run
189
+ // verbose: undefined,
190
+
191
+ // An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
192
+ // watchPathIgnorePatterns: [],
193
+
194
+ // Whether to use watchman for file crawling
195
+ // watchman: true,
196
+
197
+ testTimeout: 10000
198
+ };
199
+ export default config;
package/jest.config.ts ADDED
@@ -0,0 +1,210 @@
1
+ import type { Config } from 'jest';
2
+
3
+ const config: Config = {
4
+ // All imported modules in your tests should be mocked automatically
5
+ // automock: false,
6
+
7
+ // Stop running tests after `n` failures
8
+ // bail: 0,
9
+
10
+ // The directory where Jest should store its cached dependency information
11
+ // cacheDirectory: "/tmp/jest_rs",
12
+
13
+ // Automatically clear mock calls and instances between every test
14
+ clearMocks: true,
15
+
16
+ // Indicates whether the coverage information should be collected while executing the test
17
+ collectCoverage: false,
18
+
19
+ // An array of glob patterns indicating a set of files for which coverage information should be collected
20
+ // collectCoverageFrom: undefined,
21
+
22
+ // The directory where Jest should output its coverage files
23
+ coverageDirectory: 'coverage',
24
+
25
+ // An array of regexp pattern strings used to skip coverage collection
26
+ // coveragePathIgnorePatterns: [
27
+ // "/node_modules/"
28
+ // ],
29
+
30
+ // Indicates which provider should be used to instrument code for coverage
31
+ coverageProvider: 'v8',
32
+
33
+ // A list of reporter names that Jest uses when writing coverage reports
34
+ // coverageReporters: [
35
+ // "json",
36
+ // "text",
37
+ // "lcov",
38
+ // "clover"
39
+ // ],
40
+
41
+ // An object that configures minimum threshold enforcement for coverage results
42
+ coverageThreshold: {
43
+ global: {
44
+ branches: 80,
45
+ functions: 80,
46
+ lines: 80,
47
+ statements: 80
48
+ }
49
+ },
50
+
51
+ // A path to a custom dependency extractor
52
+ // dependencyExtractor: undefined,
53
+
54
+ // Make calling deprecated APIs throw helpful error messages
55
+ // errorOnDeprecated: false,
56
+
57
+ // Force coverage collection from ignored files using an array of glob patterns
58
+ // forceCoverageMatch: [],
59
+
60
+ // A path to a module which exports an async function that is triggered once before all test suites
61
+ // globalSetup: undefined,
62
+
63
+ // A path to a module which exports an async function that is triggered once after all test suites
64
+ // globalTeardown: undefined,
65
+
66
+ // A set of global variables that need to be available in all test environments
67
+ // globals: {},
68
+
69
+ // The maximum amount of workers used to run your tests.
70
+ // Can be specified as % or a number.
71
+ // E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number.
72
+ // maxWorkers: 2 will use a maximum of 2 workers.
73
+ // maxWorkers: "50%",
74
+
75
+ // An array of directory names to be searched recursively up from the requiring module's location
76
+ // moduleDirectories: [
77
+ // "node_modules"
78
+ // ],
79
+
80
+ // An array of file extensions your modules use
81
+ moduleFileExtensions: [
82
+ 'js',
83
+ 'json',
84
+ // "jsx",
85
+ 'ts'
86
+ // "tsx",
87
+ // "node"
88
+ ],
89
+
90
+ // A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
91
+ // moduleNameMapper: {},
92
+
93
+ // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
94
+ modulePathIgnorePatterns: [
95
+ 'test'
96
+ ],
97
+
98
+ // Activates notifications for test results
99
+ // notify: false,
100
+
101
+ // An enum that specifies notification mode. Requires { notify: true }
102
+ // notifyMode: "failure-change",
103
+
104
+ // A preset that is used as a base for Jest's configuration
105
+ // preset: undefined,
106
+
107
+ // Run tests from one or more projects
108
+ // projects: undefined,
109
+
110
+ // Use this configuration option to add custom reporters to Jest
111
+ // reporters: undefined,
112
+
113
+ // Automatically reset mock state between every test
114
+ // resetMocks: false,
115
+
116
+ // Reset the module registry before running each individual test
117
+ // resetModules: false,
118
+
119
+ // A path to a custom resolver
120
+ // resolver: undefined,
121
+
122
+ // Automatically restore mock state between every test
123
+ restoreMocks: true,
124
+
125
+ // The root directory that Jest should scan for tests and modules within
126
+ rootDir: '.',
127
+
128
+ // A list of paths to directories that Jest should use to search for files in
129
+ // roots: [
130
+ // "<rootDir>"
131
+ // ],
132
+
133
+ // Allows you to use a custom runner instead of Jest's default test runner
134
+ // runner: "jest-runner",
135
+
136
+ // The paths to modules that run some code to configure or set up the testing environment before each test
137
+ // setupFiles: [],
138
+
139
+ // A list of paths to modules that run some code to configure or set up the testing framework before each test
140
+ // setupFilesAfterEnv: [],
141
+
142
+ // The number of seconds after which a test is considered as slow and reported as such in the results.
143
+ // slowTestThreshold: 5,
144
+
145
+ // A list of paths to snapshot serializer modules Jest should use for snapshot testing
146
+ // snapshotSerializers: [],
147
+
148
+ // The test environment that will be used for testing
149
+ testEnvironment: 'node',
150
+
151
+ // Options that will be passed to the testEnvironment
152
+ // testEnvironmentOptions: {},
153
+
154
+ // Adds a location field to test results
155
+ // testLocationInResults: false,
156
+
157
+ // The glob patterns Jest uses to detect test files
158
+ // testMatch: [
159
+ // "**/__tests__/**/*.[jt]s?(x)",
160
+ // "**/?(*.)+(spec|test).[tj]s?(x)"
161
+ // ],
162
+
163
+ // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
164
+ // testPathIgnorePatterns: [
165
+ // "/node_modules/"
166
+ // ],
167
+
168
+ // The regexp pattern or array of patterns that Jest uses to detect test files
169
+ testRegex: [
170
+ '.spec.ts$'
171
+ ],
172
+
173
+ // This option allows the use of a custom results processor
174
+ // testResultsProcessor: undefined,
175
+
176
+ // This option allows use of a custom test runner
177
+ // testRunner: "jasmine2",
178
+
179
+ // This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
180
+ // testURL: "http://localhost",
181
+
182
+ // Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
183
+ // timers: "real",
184
+
185
+ // A map from regular expressions to paths to transformers
186
+ transform: {
187
+ '^.+\\.(t|j)s$': 'ts-jest'
188
+ },
189
+
190
+ // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
191
+ // transformIgnorePatterns: [
192
+ // "/node_modules/",
193
+ // "\\.pnp\\.[^\\/]+$"
194
+ // ],
195
+
196
+ // An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
197
+ // unmockedModulePathPatterns: undefined,
198
+
199
+ // Indicates whether each individual test should be reported during the run
200
+ // verbose: undefined,
201
+
202
+ // An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
203
+ // watchPathIgnorePatterns: [],
204
+
205
+ // Whether to use watchman for file crawling
206
+ // watchman: true,
207
+
208
+ testTimeout: 10000
209
+ };
210
+ export default config;
@@ -92,10 +92,10 @@ var InstallmentService = /** @class */ (function () {
92
92
  var appliedInterest = this.finance.applyCompoundInterest(1, monthlyInterestRate, numberOfPeriods);
93
93
  var adjustment = this.math.divide(1, appliedInterest);
94
94
  var divisor = this.math.subtract(1, adjustment);
95
- var factor = this.math.divide(monthlyInterestRate, divisor);
96
95
  if (monthlyInterestRate === 0) {
97
96
  return this.math.divide(baseBalance, numberOfPeriods);
98
97
  }
98
+ var factor = this.math.divide(monthlyInterestRate, divisor);
99
99
  return this.math.multiply(baseBalance, factor);
100
100
  };
101
101
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "creditu-common-library",
3
- "version": "2.3.7-beta.0",
3
+ "version": "2.3.7",
4
4
  "description": "Common library for Creditu applications",
5
5
  "main": "lib/index.js",
6
6
  "files": [