logger-fp-ts
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -5,2 +5,11 @@ # Changelog | ||
### [0.1.2](https://github.com/thewilkybarkid/logger-fp-ts/compare/v0.1.1...v0.1.2) (2022-03-23) | ||
### Features | ||
* add LogEntry instances ([186b141](https://github.com/thewilkybarkid/logger-fp-ts/commit/186b141b400e23cac8c345e7a93d52eabe969147)) | ||
* add show constructor ([2e43d75](https://github.com/thewilkybarkid/logger-fp-ts/commit/2e43d75a8979f1907718c2104e4cabbf2cf97e31)) | ||
* colourise Show ([825ee5b](https://github.com/thewilkybarkid/logger-fp-ts/commit/825ee5be3d02d94af44a715b09dde346e1118e98)) | ||
### [0.1.1](https://github.com/thewilkybarkid/logger-fp-ts/compare/v0.1.0...v0.1.1) (2022-03-22) | ||
@@ -7,0 +16,0 @@ |
@@ -1,9 +0,10 @@ | ||
/** | ||
* @since 0.1.0 | ||
*/ | ||
import { ClockEnv } from 'clock-ts'; | ||
import * as RIO from 'fp-ts-contrib/ReaderIO'; | ||
import * as E from 'fp-ts/Eq'; | ||
import * as S from 'fp-ts/Show'; | ||
import * as L from 'logging-ts/lib/IO'; | ||
import Eq = E.Eq; | ||
import LoggerIO = L.LoggerIO; | ||
import ReaderIO = RIO.ReaderIO; | ||
import Show = S.Show; | ||
/** | ||
@@ -41,3 +42,42 @@ * @category model | ||
/** | ||
* @example | ||
* import * as C from 'fp-ts/Console' | ||
* import { pipe } from 'fp-ts/function' | ||
* import * as L from 'logger-fp-ts' | ||
* | ||
* const logger = pipe(C.log, L.withShow(L.ShowLogEntry)) | ||
* | ||
* @category constructors | ||
* @since 0.1.2 | ||
*/ | ||
export declare const withShow: (show: Show<LogEntry>) => (fa: LoggerIO<string>) => Logger; | ||
/** | ||
* @category destructors | ||
* @since 0.1.2 | ||
*/ | ||
export declare const match: <R>(patterns: { | ||
readonly DEBUG: (entry: LogEntry) => R; | ||
readonly INFO: (entry: LogEntry) => R; | ||
readonly WARN: (entry: LogEntry) => R; | ||
readonly ERROR: (entry: LogEntry) => R; | ||
}) => (entry: LogEntry) => R; | ||
/** | ||
* @category instances | ||
* @since 0.1.2 | ||
*/ | ||
export declare const ShowLogEntry: Show<LogEntry>; | ||
/** | ||
* Colorizes log entries based on the level. | ||
* | ||
* @category instances | ||
* @since 0.1.2 | ||
*/ | ||
export declare const getColoredShow: (show: Show<LogEntry>) => Show<LogEntry>; | ||
/** | ||
* @category instances | ||
* @since 0.1.2 | ||
*/ | ||
export declare const EqLogEntry: Eq<LogEntry>; | ||
/** | ||
* @category instances | ||
* @since 0.1.0 | ||
@@ -44,0 +84,0 @@ */ |
@@ -25,10 +25,18 @@ "use strict"; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.error = exports.warn = exports.info = exports.debug = exports.LogEntry = void 0; | ||
exports.error = exports.warn = exports.info = exports.debug = exports.EqLogEntry = exports.getColoredShow = exports.ShowLogEntry = exports.match = exports.withShow = exports.LogEntry = void 0; | ||
/** | ||
* @since 0.1.0 | ||
*/ | ||
const chalk_1 = __importDefault(require("chalk")); | ||
const clock_ts_1 = require("clock-ts"); | ||
const RIO = __importStar(require("fp-ts-contrib/ReaderIO")); | ||
const d = __importStar(require("fp-ts/Date")); | ||
const E = __importStar(require("fp-ts/Eq")); | ||
const function_1 = require("fp-ts/function"); | ||
const s = __importStar(require("fp-ts/string")); | ||
const L = __importStar(require("logging-ts/lib/IO")); | ||
// ------------------------------------------------------------------------------------- | ||
@@ -47,3 +55,27 @@ // constructors | ||
exports.LogEntry = LogEntry; | ||
/** | ||
* @example | ||
* import * as C from 'fp-ts/Console' | ||
* import { pipe } from 'fp-ts/function' | ||
* import * as L from 'logger-fp-ts' | ||
* | ||
* const logger = pipe(C.log, L.withShow(L.ShowLogEntry)) | ||
* | ||
* @category constructors | ||
* @since 0.1.2 | ||
*/ | ||
const withShow = (show) => L.contramap(show.show); | ||
exports.withShow = withShow; | ||
// ------------------------------------------------------------------------------------- | ||
// destructors | ||
// ------------------------------------------------------------------------------------- | ||
/** | ||
* @category destructors | ||
* @since 0.1.2 | ||
*/ | ||
const match = (patterns) => (entry) => { | ||
return patterns[entry.level](entry); | ||
}; | ||
exports.match = match; | ||
// ------------------------------------------------------------------------------------- | ||
// utils | ||
@@ -63,2 +95,33 @@ // ------------------------------------------------------------------------------------- | ||
* @category instances | ||
* @since 0.1.2 | ||
*/ | ||
exports.ShowLogEntry = { | ||
show: ({ message, date, level }) => `${date.toISOString()} | ${level} | ${message}`, | ||
}; | ||
/** | ||
* Colorizes log entries based on the level. | ||
* | ||
* @category instances | ||
* @since 0.1.2 | ||
*/ | ||
const getColoredShow = ({ show }) => ({ | ||
show: (0, exports.match)({ | ||
DEBUG: (0, function_1.flow)(show, chalk_1.default.cyan), | ||
INFO: (0, function_1.flow)(show, chalk_1.default.magenta), | ||
WARN: (0, function_1.flow)(show, chalk_1.default.yellow), | ||
ERROR: (0, function_1.flow)(show, chalk_1.default.red), | ||
}), | ||
}); | ||
exports.getColoredShow = getColoredShow; | ||
/** | ||
* @category instances | ||
* @since 0.1.2 | ||
*/ | ||
exports.EqLogEntry = E.struct({ | ||
message: s.Eq, | ||
date: d.Eq, | ||
level: s.Eq, | ||
}); | ||
/** | ||
* @category instances | ||
* @since 0.1.0 | ||
@@ -65,0 +128,0 @@ */ |
{ | ||
"name": "logger-fp-ts", | ||
"description": "A logger for use with fp-ts.", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"license": "MIT", | ||
@@ -12,2 +12,5 @@ "homepage": "https://github.com/thewilkybarkid/logger-fp-ts", | ||
"sideEffects": false, | ||
"dependencies": { | ||
"chalk": "^4.1.2" | ||
}, | ||
"peerDependencies": { | ||
@@ -14,0 +17,0 @@ "clock-ts": "^0.1.0", |
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
11223
240
5
+ Addedchalk@^4.1.2
+ Addedansi-styles@4.3.0(transitive)
+ Addedchalk@4.1.2(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedsupports-color@7.2.0(transitive)