Back to Lowdefy

Utils Overview

code-docs/utils/overview.md

5.2.03.5 KB
Original Source

Utils Overview

Shared utility packages used throughout Lowdefy.

Package Summary

PackagePurposeRuntime
@lowdefy/helpersCore helper functionsUniversal
@lowdefy/node-utilsNode.js file/process utilitiesNode.js
@lowdefy/loggerLogging utilities (node, dev, cli, browser)Universal
@lowdefy/ajvJSON Schema validationUniversal
@lowdefy/block-utilsBlock runtime utilitiesBrowser
@lowdefy/block-devBlock testing utilitiesNode.js
@lowdefy/e2e-utilsPlaywright e2e testing for appsNode.js
@lowdefy/nunjucksTemplate engine wrapperUniversal
@lowdefy/jest-yaml-transformYAML Jest transformerNode.js

Dependency Graph

helpers (no deps)
    ↓
node-utils, block-utils, nunjucks, block-dev, logger
    ↓
ajv (depends on nunjucks)

jest-yaml-transform (standalone)

Common Use Cases

Data Manipulation

javascript
import { get, set, mergeObjects, serializer } from '@lowdefy/helpers';

// Deep property access
const name = get(user, 'profile.name', { default: 'Anonymous' });

// Deep property assignment
set(state, 'user.profile.name', 'John');

// Merge objects
const merged = mergeObjects([defaults, overrides]);

// Serialize/deserialize
const json = serializer.serializeToString(data);
const data = serializer.deserializeFromString(json);

Type Checking

javascript
import { type } from '@lowdefy/helpers';

type.isArray(value);
type.isObject(value);
type.isString(value);
type.isDate(value);
type.enforceType('array', value);

File Operations

javascript
import { readFile, writeFile, spawnProcess } from '@lowdefy/node-utils';

const content = await readFile('config.yaml');
await writeFile('output.json', JSON.stringify(data));
await spawnProcess({ command: 'npm', args: ['install'] });

Schema Validation

javascript
import { validate } from '@lowdefy/ajv';

const result = validate({ schema, data });
if (!result.valid) {
  console.error(result.errors);
}

Block Development

javascript
import { ErrorBoundary, cn } from '@lowdefy/block-utils';
import { mockBlock, runBlockSchemaTests } from '@lowdefy/block-dev';

// Test blocks
const block = mockBlock({ meta, schema });
runBlockSchemaTests({ examples, schema });

Templates

javascript
import { nunjucksString, nunjucksFunction } from '@lowdefy/nunjucks';

// One-off render
const result = nunjucksString('Hello {{ name }}!', { name: 'World' });

// Reusable template
const template = nunjucksFunction('Hello {{ name }}!');
const result = template({ name: 'World' });

Version

All packages are at version 4.4.0 and follow the monorepo versioning.

See Also