Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lbu/stdlib

Package Overview
Dependencies
Maintainers
1
Versions
102
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lbu/stdlib - npm Package Compare versions

Comparing version 0.0.20 to 0.0.21

6

package.json
{
"name": "@lbu/stdlib",
"version": "0.0.20",
"version": "0.0.21",
"description": "All kinds of utility functions",

@@ -16,3 +16,3 @@ "main": "./index.js",

"dependencies": {
"@lbu/insight": "^0.0.20",
"@lbu/insight": "^0.0.21",
"dotenv": "8.2.0",

@@ -35,3 +35,3 @@ "lodash.merge": "4.6.2"

},
"gitHead": "87bbba853bb050f7897c50ea291233297e2366e1"
"gitHead": "b81b7a87aa31416c815ff2105990c7455de4846b"
}

@@ -9,15 +9,8 @@ # @lbu/stdlib

## Why
Here at [lightbase](https://lightbase.nl) we had a constantly growing
boilerplate for new projects. To facilitate our needs more and to stop copying
and pasting things around this project was born. This project is for now
tailored at smaller & monolithic projects.
## Features
- Minimal API project boilerplate
- Minimal project boilerplate
- Script runner, can watch & reload almost anything (via nodemon)
- Flexible code generators supporting routers, validators, api clients, mocks
and more in the future.
- Flexible code generators supporting routers, validators, api clients, mocks,
CRUD queries and more in the future.
- Opinionated structured logging

@@ -28,5 +21,88 @@ - Common Koa middleware wrapped in a single function

## Requirements
- Node.js >= 14
- Yarn 1.x.x
## Why
Here at [lightbase](https://lightbase.nl) we had a constantly growing
boilerplate for new projects. To facilitate our needs more and to stop copying
and pasting things around this project was born. This project is for now
tailored at monolithic projects.
## Features breakdown
**@lbu/cli**:
- Run user scripts (in watch mode)
- Run the linter or tests
- A LBU based boilerplate
**@lbu/lint-config**:
- All necessary ESLint and Prettier dependencies
- Default configuration for ESLint and Prettier
**@lbu/insight**:
- A structured logger
- Writing newline delimited JSON in production
- Pretty printing for development
- Various utilities to get insight in the running process
- Parser to process production logs in an external process
**@lbu/stdlib**:
- Various lodash inspired utilities (isNil, isPlainObject, ...)
- Wrappers for child_process execution and spawning
- Basic templating system
- A `mainFn` wrapper that reads `.env` and calls the provided function if the
file is the process entrypoint
- Replacements for CommonJS `__dirname` and `__filename`
**@lbu/server**:
- Wrapper around Koa instance creation
- 404 en error handling
- Handle CORS
- Send file helper
- Re-exports koa-session and koa-compose
**@lbu/store**:
- Wrapper around the Minio S3 client
- Wrapper around Postgres connection
- Utilities for providing temporary databases in a test environment
- Postgres migrations
- Postgres and S3 combined for file storage
- Caching files from S3 in memory or on local disk
- Postgres powered JobQueue implementation
- Supports priority, scheduling, multiple async workers
- koa-session compatible SessionStore backed by Postgres
**@lbu/code-gen**:
- Code generators for the following:
- router, with wildcard and path parameter support
- validators, with pre- and postValidate hooks
- queries, CRUD postgres queries
- Axios based api client
- Typescript or JSDoc types
- Generated mocks
- An extendable set of types:
- boolean, number, string;
- object, array, any;
- date, uuid;
- generic, anyOf, reference;
- Remote structure loader
- OpenAPI to LBU converter
- Generate stubs (types and structure only) so packages can also use LBU
- router structure
- api client structure (Typescript supported)
- and of course the normal types generator
## Docs
See [/docs](/docs/README.md)
See [/docs](/docs/README.md) for all available APIs and various guides.

@@ -33,0 +109,0 @@ ## Development

@@ -5,5 +5,6 @@ import { v4 } from "./vendor/uuid.js";

* Return a new uuid v4
*
* @function
* @return {string}
* @returns {string}
*/
export const uuid = v4;

@@ -10,5 +10,6 @@ import { isNil } from "./lodash.js";

* Create a new AppError
*
* @param {string} key
* @param {number} status
* @param {Object} [info={}]
* @param {object} [info={}]
* @param {Error} [originalError]

@@ -41,5 +42,6 @@ */

* Throw a new 404 not found error
* @param {Object} [info={}]
*
* @param {object} [info={}]
* @param {Error} [error]
* @return {AppError}
* @returns {AppError}
*/

@@ -52,5 +54,6 @@ static notFound(info = {}, error = undefined) {

* Throw a new 405 Not implemented error
* @param {Object} [info={}]
*
* @param {object} [info={}]
* @param {Error} [error]
* @return {AppError}
* @returns {AppError}
*/

@@ -63,5 +66,6 @@ static notImplemented(info = {}, error = undefined) {

* Throw a new 500 internal server error
* @param {Object} [info={}]
*
* @param {object} [info={}]
* @param {Error} [error]
* @return {AppError}
* @returns {AppError}
*/

@@ -74,6 +78,7 @@ static serverError(info = {}, error = undefined) {

* Throw a new 400 validation error
*
* @param {string} key
* @param {Object} [info={}]
* @param {object} [info={}]
* @param {Error} [error]
* @return {AppError}
* @returns {AppError}
*/

@@ -80,0 +85,0 @@ static validationError(key, info = {}, error = undefined) {

@@ -5,2 +5,3 @@ import lodashMerge from "lodash.merge";

* Check if item is null or undefined
*
* @param {*=} item

@@ -16,2 +17,3 @@ * @returns {boolean}

* Not completely bullet proof
*
* @param {*=} item

@@ -34,5 +36,5 @@ * @returns {boolean}

*
* @param {Object} object The destination object.
* @param {...Object} [sources] The source objects.
* @returns {Object} Returns `object`.
* @param {object} object The destination object.
* @param {...object} [sources] The source objects.
* @returns {object} Returns `object`.
*/

@@ -43,6 +45,7 @@ export const merge = lodashMerge;

* Flattens the given nested object, skipping anything that is not a plain object
* @param {Object} data The object to serialize
*
* @param {object} data The object to serialize
* @param [result]
* @param [path]
* @return {Object.<string, *>}
* @returns {object.<string, *>}
*/

@@ -69,4 +72,5 @@ export function flatten(data, result = {}, path = "") {

* Opposite of flatten
* @param {Object} data
* @return {Object}
*
* @param {object} data
* @returns {object}
*/

@@ -92,2 +96,5 @@ export function unFlatten(data) {

/**
* @param input
*/
export function camelToSnakeCase(input) {

@@ -94,0 +101,0 @@ return input

@@ -11,5 +11,6 @@ import { exec as cpExec, spawn as cpSpawn } from "child_process";

* Promisify version of child_process#exec
*
* @callback Exec
* @param {string} command
* @returns {Promise<Object<{stdout: string, stderr: string}>>}
* @returns {Promise<object<{stdout: string, stderr: string}>>}
*/

@@ -22,5 +23,6 @@ export function exec(command) {

* A promise wrapper around child_process#spawn
*
* @param {string} command
* @param {string[]} args
* @param {Object} [opts={}]
* @param {object} [opts={}]
* @returns {Promise<{code: number|undefined}>}

@@ -40,3 +42,5 @@ */

/**
* @typedef {object} ProcessDirectoryOptions
* @name ProcessDirectoryOptions
*
* @typedef {object}
* @property {boolean} [skipNodeModules] Skip node_modules directory, true by default

@@ -50,2 +54,3 @@ * @property {boolean} [skipDotFiles] Skip files and directories starting with a '.', true

* By default skips node_modules and files starting with a dot
*
* @param {string} dir

@@ -83,5 +88,6 @@ * @param {Function} cb

* Sync version of processDirectoryRecursive
*
* @param {string} dir
* @param {Function} cb
* @param {Object} [opts={}]
* @param {object} [opts={}]
* @param {boolean} [opts.skipNodeModules=true]

@@ -88,0 +94,0 @@ * @param {boolean} [opts.skipDotFiles=true]

@@ -12,5 +12,7 @@ import { promises, readFileSync } from "fs";

/**
* @typedef {object} TemplateContext
* @property {object<string, function>} globals
* @property {Map<string, function>} templates
* @name TemplateContext
*
* @typedef {object}
* @property {object<string, Function>} globals
* @property {Map<string, Function>} templates
* @property {boolean} strict

@@ -20,3 +22,3 @@ */

/**
* @return {TemplateContext}
* @returns {TemplateContext}
*/

@@ -101,4 +103,8 @@ export function newTemplateContext() {

return p.join('')
.replace(/^(\\s*\\r?\\n){2,}/gm, '\\n') // Replace multiple new lines
.replace(/^\\s*\\*\\s*([^\\n\\/\\*]+)\\s*\\n+/gm, ' * $1\\n '); // replace empty lines in JSDoc
.replace(/[ \\t\\r]+/g, ' ') // Replace all multiple spaces, with a single
.replace(/^[ \\t\\r]+/gm, '') // Replace spaces at start of sentence with nothing
.replace(/^(\\s*\\r?\\n){1,}/gm, '\\n') // Replace multiple new lines
.replace(/^\\s*\\*\\s*([^\\n\\/\\*]+)\\s*\\n+/gm, ' * $1\\n ') // replace empty lines in JSDoc
.replace(/\\n\\n/gm, '\\n') // Remove empty lines
.replace(/\\(\\(newline\\)\\)/g, '\\n\\n'); // Controlled newlines
`,

@@ -105,0 +111,0 @@ ),

@@ -11,2 +11,3 @@ import dotenv from "dotenv";

* Return seconds since unix epoch
*
* @returns {number}

@@ -20,3 +21,4 @@ */

* An empty function, doing exactly nothing but returning undefined.
* @return {undefined}
*
* @returns {undefined}
*/

@@ -57,2 +59,3 @@ export function noop() {

* Another side effect is that a process listener is added for warnings
*
* @param {ImportMeta} meta

@@ -74,4 +77,5 @@ * @param {Logger} logger

* Alternative to CommonJS __filename
*
* @param {ImportMeta} meta
* @return {string}
* @returns {string}
*/

@@ -85,4 +89,5 @@ export function filenameForModule(meta) {

* Alternative to CommonJS __dirname
*
* @param {ImportMeta} meta
* @return {string}
* @returns {string}
*/

@@ -95,3 +100,3 @@ export function dirnameForModule(meta) {

* @param {ImportMeta} meta
* @return {boolean}
* @returns {boolean}
*/

@@ -122,4 +127,7 @@ function isMainFn(meta) {

/**
* @param logger
*/
function setupProcessListeners(logger) {
process.on("warning", (err) => logger.error(err));
}

@@ -39,2 +39,5 @@ /*

* XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
*
* @param buf
* @param offset
*/

@@ -72,2 +75,5 @@ function bytesToUuid(buf, offset) {

/**
*
*/
export function v4() {

@@ -74,0 +80,0 @@ const rnds = randomFillSync(rnds8);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc