Registry / devops / keyf
library0.0.2jsnpmunverified

Key formatting library for generating formatted keys from function arguments with placeholders (positional, property paths, pre-defined values). Current version 0.0.2. Minimal API surface with a single function. Differentiates from template engines by tight integration with function argument patterns, using {0}, {this.foo}, {1.bar} syntax. No updates since 2015; considered feature-complete but unmaintained.

npm install keyf
INSTALL
IMPORT
SIG · KEYF
K
keyf
devopsjavascriptv0.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import keyf from 'keyf'
const { keyf } = require('keyf')
Default export; named import via destructured require is incorrect
default (CommonJS)
const keyf = require('keyf')
const keyf = require('keyf').default
CJS require returns the function directly, not as default property
keyf
const keyf = require('keyf')
import { keyf } from 'keyf'
ESM default import works, but named import for 'keyf' does not exist

Shows how to create a formatter with a template string and pre-defined values, then call it with a context and arguments.

const keyf = require('keyf'); const formatter = keyf('session:{_user_}:{0}:{this.id}', { '_user_': 'alice' }); const obj = { id: 42 }; const result = formatter.call(obj, ['extra']); console.log(result); // session:alice:extra:42
Debug
Known issues
gotchaPlaceholder syntax supports pre-defined values but they must be passed in options object as second argument to keyf()
fix
Pass all static mappings in the options object when creating the formatter
affects: >=0.0.0
gotchaThe formatter expects `this` context for `{this.*}` placeholders; forgetting .call() or .apply() results in undefined values
fix
Always invoke the formatter with `formatter.call(context, arguments)`
affects: >=0.0.0
gotchaNumbered placeholders like {0} refer to elements of the arguments object, not a separate array; passing an array as first argument will misinterpret it
fix
Use the `arguments` object directly (or an array-like) when calling the formatter
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: formatter(...) is not a function
Misunderstanding of module export; importing as named export instead of default
fix
Use `const keyf = require('keyf')` or `import keyf from 'keyf'`
ReferenceError: _user_ is not defined
Pre-defined placeholder not provided in options object
fix
Pass pre-defined values as second argument to keyf(), e.g. keyf('{_user_}', { _user_: 'alice' })
Upgrade
Version history
0.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources
packagekeyf
keyf — npm install keyf · libregistry