Comparing version 1.0.41 to 1.0.42
@@ -80,2 +80,19 @@ export default jsUtils; | ||
} | ||
export function createCustomErrorClass(errorName: any): { | ||
new (name: any, message: any, data: any): { | ||
name: any; | ||
data: { | ||
status: number; | ||
}; | ||
map(func: any): any; | ||
chain(func: any): any; | ||
message: string; | ||
stack?: string | undefined; | ||
cause?: unknown; | ||
}; | ||
of: typeof CustomError; | ||
captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void; | ||
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined; | ||
stackTraceLimit: number; | ||
}; | ||
export function urlCompose(gatewayUrl: any, serviceName: any, servicePath: any): { | ||
@@ -82,0 +99,0 @@ gatewayUrl: any; |
@@ -15,4 +15,4 @@ 'use strict'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.addDays = exports.subtractDays = exports.diffInDaysYYYY_MM_DD = exports.dateToObj = exports.YYYY_MM_DD_hh_mm_ss_ToUtcDate = exports.dateFormatter = exports.formatDate = exports.isStringADate = exports.isEmpty = exports.isDate = exports.fillWith = exports.memoize = exports.pushAt = exports.pushUniqueKeyOrChange = exports.pushUniqueKey = exports.transition = exports.Enum = exports.EnumMap = exports.copyPropsWithValueUsingRules = exports.copyPropsWithValue = exports.project = exports.traverseVertically = exports.traverse = exports.removeDuplicates = exports.arrayOfObjectsToObject = exports.arrayToObject = exports.notTo = exports.sleepWithFunction = exports.sleepWithValue = exports.sleep = exports.isPromise = exports.arraySorter = exports.filterFlatMap = exports.sorterByPaths = exports.setAt = exports.getAt = exports.deepFreeze = exports.findDeepKey = exports.colorByStatus = exports.colorMessageByStatus = exports.colorMessage = exports.colors = exports.indexOfNthMatch = exports.urlDecompose = exports.urlCompose = exports.CustomError = exports.queryObjToStr = exports.varSubsDoubleBracket = exports.firstCapital = exports.logWithPrefix = void 0; | ||
exports.processExit = exports.retryWithSleep = exports.loopIndexGenerator = exports.runEvery = exports.repeat = exports.cleanString = exports.replaceAll = exports.setDateToMidnight = exports.isDateMidnight = exports.getSameDateOrPreviousFridayForWeekends = exports.previousDayOfWeek = void 0; | ||
exports.subtractDays = exports.diffInDaysYYYY_MM_DD = exports.dateToObj = exports.YYYY_MM_DD_hh_mm_ss_ToUtcDate = exports.dateFormatter = exports.formatDate = exports.isStringADate = exports.isEmpty = exports.isDate = exports.fillWith = exports.memoize = exports.pushAt = exports.pushUniqueKeyOrChange = exports.pushUniqueKey = exports.transition = exports.Enum = exports.EnumMap = exports.copyPropsWithValueUsingRules = exports.copyPropsWithValue = exports.project = exports.traverseVertically = exports.traverse = exports.removeDuplicates = exports.arrayOfObjectsToObject = exports.arrayToObject = exports.notTo = exports.sleepWithFunction = exports.sleepWithValue = exports.sleep = exports.isPromise = exports.arraySorter = exports.filterFlatMap = exports.sorterByPaths = exports.setAt = exports.getAt = exports.deepFreeze = exports.findDeepKey = exports.colorByStatus = exports.colorMessageByStatus = exports.colorMessage = exports.colors = exports.indexOfNthMatch = exports.urlDecompose = exports.urlCompose = exports.createCustomErrorClass = exports.CustomError = exports.queryObjToStr = exports.varSubsDoubleBracket = exports.firstCapital = exports.logWithPrefix = void 0; | ||
exports.processExit = exports.retryWithSleep = exports.loopIndexGenerator = exports.runEvery = exports.repeat = exports.cleanString = exports.replaceAll = exports.setDateToMidnight = exports.isDateMidnight = exports.getSameDateOrPreviousFridayForWeekends = exports.previousDayOfWeek = exports.addDays = void 0; | ||
const just_clone_1 = __importDefault(require("just-clone")); | ||
@@ -64,2 +64,12 @@ const jsonpath_plus_1 = require("jsonpath-plus"); | ||
// })(divide(8,0)) //? | ||
function createCustomErrorClass(errorName) { | ||
const errorClass = class extends CustomError { | ||
constructor(name, message, data) { | ||
super(name, message, data); | ||
this.name = errorName; | ||
} | ||
}; | ||
return errorClass; | ||
} | ||
exports.createCustomErrorClass = createCustomErrorClass; | ||
class Enum { | ||
@@ -66,0 +76,0 @@ constructor(values, rules) { |
@@ -80,2 +80,19 @@ export default jsUtils; | ||
} | ||
export function createCustomErrorClass(errorName: any): { | ||
new (name: any, message: any, data: any): { | ||
name: any; | ||
data: { | ||
status: number; | ||
}; | ||
map(func: any): any; | ||
chain(func: any): any; | ||
message: string; | ||
stack?: string | undefined; | ||
cause?: unknown; | ||
}; | ||
of: typeof CustomError; | ||
captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void; | ||
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined; | ||
stackTraceLimit: number; | ||
}; | ||
export function urlCompose(gatewayUrl: any, serviceName: any, servicePath: any): { | ||
@@ -82,0 +99,0 @@ gatewayUrl: any; |
@@ -46,2 +46,11 @@ 'use strict'; | ||
// })(divide(8,0)) //? | ||
function createCustomErrorClass(errorName) { | ||
const errorClass = class extends CustomError { | ||
constructor(name, message, data) { | ||
super(name, message, data); | ||
this.name = errorName; | ||
} | ||
}; | ||
return errorClass; | ||
} | ||
class Enum { | ||
@@ -1505,2 +1514,2 @@ constructor(values, rules) { | ||
export default jsUtils; | ||
export { logWithPrefix, firstCapital, varSubsDoubleBracket, queryObjToStr, CustomError, urlCompose, urlDecompose, indexOfNthMatch, colors, colorMessage, colorMessageByStatus, colorByStatus, findDeepKey, deepFreeze, getAt, setAt, sorterByPaths, filterFlatMap, arraySorter, isPromise, sleep, sleepWithValue, sleepWithFunction, notTo, arrayToObject, arrayOfObjectsToObject, removeDuplicates, traverse, traverseVertically, project, copyPropsWithValue, copyPropsWithValueUsingRules, EnumMap, Enum, transition, pushUniqueKey, pushUniqueKeyOrChange, pushAt, memoize, fillWith, isDate, isEmpty, isStringADate, formatDate, dateFormatter, YYYY_MM_DD_hh_mm_ss_ToUtcDate, dateToObj, diffInDaysYYYY_MM_DD, subtractDays, addDays, previousDayOfWeek, getSameDateOrPreviousFridayForWeekends, isDateMidnight, setDateToMidnight, replaceAll, cleanString, repeat, runEvery, loopIndexGenerator, retryWithSleep, processExit }; | ||
export { logWithPrefix, firstCapital, varSubsDoubleBracket, queryObjToStr, CustomError, createCustomErrorClass, urlCompose, urlDecompose, indexOfNthMatch, colors, colorMessage, colorMessageByStatus, colorByStatus, findDeepKey, deepFreeze, getAt, setAt, sorterByPaths, filterFlatMap, arraySorter, isPromise, sleep, sleepWithValue, sleepWithFunction, notTo, arrayToObject, arrayOfObjectsToObject, removeDuplicates, traverse, traverseVertically, project, copyPropsWithValue, copyPropsWithValueUsingRules, EnumMap, Enum, transition, pushUniqueKey, pushUniqueKeyOrChange, pushAt, memoize, fillWith, isDate, isEmpty, isStringADate, formatDate, dateFormatter, YYYY_MM_DD_hh_mm_ss_ToUtcDate, dateToObj, diffInDaysYYYY_MM_DD, subtractDays, addDays, previousDayOfWeek, getSameDateOrPreviousFridayForWeekends, isDateMidnight, setDateToMidnight, replaceAll, cleanString, repeat, runEvery, loopIndexGenerator, retryWithSleep, processExit }; |
{ | ||
"name": "js-awe", | ||
"version": "1.0.41", | ||
"version": "1.0.42", | ||
"homepage": "https://github.com/josuamanuel/js-awe", | ||
@@ -32,7 +32,9 @@ "author": "josuamanuel@hotmail.com", | ||
"scripts": { | ||
"test": "npm run testUT", | ||
"testUT": "export CONFIG_ENV=Testing && export LOG_LEVEL=SILENT && mocha ./test/**/*.js", | ||
"test": "export CONFIG_ENV=Testing && export LOG_LEVEL=SILENT && mocha ./test/**/*.js", | ||
"buildWeb": "rollup -c && ./awkChangenNodePerf.sh", | ||
"buildLib": "tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && ./fixup", | ||
"buildTypes": "tsc -p tsconfig-types.json" | ||
"buildTypes": "tsc -p tsconfig-types.json", | ||
"copyMapsAndTypes": "rsync -av --include '*/' --include '*.d.ts.map' --exclude '*' ./genTypes/ ./types/ && rsync -av --include '*/' --include '*.d.ts' --exclude '*' --ignore-existing ./genTypes/ ./types/", | ||
"genAndCopyTypes": "npm run buildTypes && copyMapsAndTypes", | ||
"build": "npm test && npm run buildWeb && npm run buildLib && npm run genAndCopyTypes" | ||
}, | ||
@@ -39,0 +41,0 @@ "license": "MIT", |
@@ -63,10 +63,10 @@ # js-awe | ||
const result = plan().build([ | ||
const myCalc = plan().build([ | ||
val1 => Promise.resolve(val1 * 2), // fun1: 3*2 = 6 | ||
[val2 => Promise.resolve(val2 + 1), val3 => val3 + 3], // fun2A: 6 + 1 = 7; fun3: 7 + 3 = 10 | ||
[val2 => val2 + 1, val3 => Promise.resolve(val3 + 3)], // fun2A: 6 + 1 = 7; fun3: 7 + 3 = 10 | ||
[val2 => Promise.resolve(val2 - 1), val4 => val4 + 2], // fun2B: 6 - 1 = 5; fun4: 5 + 2 = 7 | ||
([val4, val5]) => val4 + val5 // fun5: 10 + 7 = 17; Promise.resolve(17) | ||
])(3) | ||
]) | ||
result.then(result => console.log(result)) //=> 17 | ||
myCalc(3).then(result => console.log(result)) //=> 17 | ||
``` | ||
@@ -82,3 +82,42 @@ | ||
***No need to handle errors in all functions.*** | ||
* Returning error or Promise.reject in a function will skip the rest of execution automatically. No need to throw exceptions. | ||
* Only add error handling when we want expressely to recover from the error at that point. | ||
```javascript | ||
const { plan } = require('js-awe') | ||
// import { plan } from 'js-awe' | ||
const result = plan().build([ | ||
(val1, val2) => | ||
val2 !==0 | ||
? Promise.resolve(val1 / val2) | ||
: Promise.reject(new Error('Zero division')), | ||
val3 => { | ||
const result = Math.sqrt(val3 - 5) | ||
return Number.isNaN(result) | ||
? new Error('Root of negative') | ||
: result | ||
} | ||
]) | ||
const handlingErrors = e => { | ||
if(e.message === 'Zero division') console.log('ooops divison by zero') | ||
if(e.message === 'Root of negative') console.log('ooops root of a negative value') | ||
if(e.message !== 'Zero division' && e.message !== 'Root of negative') console.log(e) | ||
} | ||
result(3, 0) | ||
.then(result => console.log(`result: ${result}`)) | ||
// Error handling managed in one place | ||
.catch(handlingErrors) | ||
result(4,2) | ||
.then(result => console.log(`result: ${result}`)) | ||
.catch(handlingErrors) | ||
``` | ||
***The purpose:*** | ||
Async await has done a lot to improve the readability of code when compared with callbacks style. But sometimes it is not a good construct, especially if you want to use it in a functional style!!! | ||
@@ -293,2 +332,11 @@ | ||
## build | ||
npm run build | ||
* Run the test. If it fails cancel the build. | ||
* This will build for nodeJs in ./dist with support for Module Es in mjs folder and commonjs in cjs. | ||
* Build for web in dist/js-awe.min.js | ||
* generate types and copy them to genTypes folder. see more details below | ||
## Generating types | ||
@@ -298,7 +346,7 @@ | ||
To generate types: | ||
To generate automatically a basic type definition (mainly all with generic any type) you can execute: | ||
tsc -p tsconfig-types.json | ||
npm run genAndCopyTypes | ||
This will output types in ./genTypes then we will need to copy the new type definitions into ./types/ . This is to keep the documentation that was already manually generated. | ||
This will output types in ./genTypes then it will copy the d.ts.map to ./types/ and d.ts files if they don't exist in ./types/. It is recommended to improve the automatic generation of types and to document with JsDoc. | ||
@@ -305,0 +353,0 @@ ## publishing lib to npm |
@@ -61,2 +61,14 @@ 'use strict' | ||
function createCustomErrorClass(errorName) { | ||
const errorClass = class extends CustomError { | ||
constructor(name, message, data) { | ||
super(name, message, data); | ||
this.name = errorName; | ||
} | ||
}; | ||
return errorClass; | ||
} | ||
class Enum { | ||
@@ -1832,2 +1844,3 @@ | ||
CustomError, | ||
createCustomErrorClass, | ||
urlCompose, | ||
@@ -1834,0 +1847,0 @@ urlDecompose, |
@@ -8,2 +8,3 @@ export default jsUtils; | ||
export { CustomError }; | ||
export { createCustomErrorClass } | ||
export { urlCompose }; | ||
@@ -74,2 +75,18 @@ export { urlDecompose }; | ||
} | ||
export function createCustomErrorClass(errorName: string): { | ||
new (name?: string, message?: string, data?: { status: number}): { | ||
name: string; | ||
data: { | ||
status: number; | ||
}; | ||
map(func: Function): any; | ||
chain(func: Function): any; | ||
message: string; | ||
stack?: string; | ||
}; | ||
of: typeof CustomError; | ||
captureStackTrace(targetObject: object, constructorOpt?: Function): void; | ||
prepareStackTrace?: (err: Error, stackTraces: NodeJS.CallSite[]) => any; | ||
stackTraceLimit: number; | ||
}; | ||
export function urlCompose(gatewayUrl: any, serviceName: any, servicePath: any): { | ||
@@ -76,0 +93,0 @@ gatewayUrl: any; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1136155
149
33091
354