Loki pattern in JavaScript
npm install @sigyn/pattern
Loki pattern in JavaScript/TypeScript
- Node.js version 18 or higher
This package is available in the Node Package Repository and can be easily installed with npm or yarn
``bash`
$ npm i @sigyn/patternor
$ yarn add @sigyn/pattern
`ts
import { Pattern } from "@sigyn/pattern";
const parser = new Pattern("HTTP
const parsedLogs = parser.executeOnLogs([
"HTTP POST 200 /api/v1/dowork",
"HTTP GET 200 /api/v1/dowork"
]);
// Automatically infer types
for (const { verb, endpoint } of parsedLogs) {
console.log(verb, endpoint);
}
`
You can also provide an Array to Pattern constructor (quite helpful with long or multipart patterns).
`ts`
new Pattern([
"[schema:
"HTTP
] as const)
> [!TIP]
> Use as const to benefit from type inference
Pattern and NoopPattern both implement the same Shape using PatternShape interface.
`ts
type LokiPatternType = string | Array
interface PatternShape
compile(): (log: string) => [] | [log: LokiLiteralPattern
executeOnLogs(logs: Array
}
``