
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
octocode-utils
Advanced tools
Shared utilities for Octocode MCP packages
Essential utilities for building MCP (Model Context Protocol) applications with advanced content processing and AI optimization capabilities.
npm install octocode-utils
# or
yarn add octocode-utils
Converts JSON data to YAML format with configurable key sorting and forced string quoting for optimal token efficiency and AI consumption.
import { jsonToYamlString, YamlConversionConfig } from 'octocode-utils';
const data = {
name: "John Doe",
age: 30,
id: "user-123",
active: true,
roles: ["admin", "user"],
settings: {
theme: "dark",
notifications: true,
id: "settings-456"
}
};
// Default behavior (preserves original key order)
console.log(jsonToYamlString(data));
// Output:
// name: "John Doe"
// age: 30
// id: "user-123"
// active: true
// roles:
// - "admin"
// - "user"
// settings:
// theme: "dark"
// notifications: true
// id: "settings-456"
// With priority-based sorting (applied recursively to all nested objects)
const config: YamlConversionConfig = {
keysPriority: ["id", "name"]
};
console.log(jsonToYamlString(data, config));
// Output:
// id: "user-123" <- Priority key first
// name: "John Doe" <- Priority key second
// active: true <- Remaining keys alphabetically
// age: 30
// roles:
// - "admin"
// - "user"
// settings:
// id: "settings-456" <- Priority applied to nested objects too
// name: "John Doe" <- Priority applied to nested objects too
// notifications: true <- Remaining keys alphabetically
// theme: "dark"
sortKeys: true)keysPriority arrayforceQuotes: truefunction jsonToYamlString(
jsonObject: unknown,
config?: YamlConversionConfig
): string
interface YamlConversionConfig {
/** Whether to sort keys alphabetically (false by default) */
sortKeys?: boolean;
/**
* Priority order for keys - missing keys will be added at the end alphabetically.
* This configuration is applied RECURSIVELY to ALL nested objects at every level.
* Each object (root, nested, arrays of objects) will have its keys sorted according
* to the same priority rules, ensuring consistent structure throughout the entire data tree.
*/
keysPriority?: string[];
}
// No sorting (default) - preserves original key order
jsonToYamlString(data);
// Alphabetical sorting at all levels
jsonToYamlString(data, { sortKeys: true });
// Priority-based sorting (recursive to all nested objects)
jsonToYamlString(data, {
keysPriority: ["id", "name", "type", "status", "version"]
});
// Priority takes precedence over sortKeys
jsonToYamlString(data, {
sortKeys: true, // This is ignored
keysPriority: ["id", "name"] // This is used instead
});
The keysPriority configuration is applied recursively to every object at every nesting level:
const complexData = {
// Root level
environment: "production",
name: "MyApp",
id: "app-123",
// Level 1: database config
database: {
timeout: 30000,
name: "myapp_db",
host: "localhost",
id: "db-456",
// Level 2: nested credentials
credentials: {
password: "secret",
id: "cred-789",
username: "admin",
name: "DB Admin"
}
},
// Level 1: array of objects
users: [
{
email: "alice@example.com",
name: "Alice",
id: "user-1",
role: "admin"
}
]
};
const config = { keysPriority: ["id", "name"] };
const yaml = jsonToYamlString(complexData, config);
// Result: Every object gets its keys sorted by the same priority rules
// Root level: id → name → (alphabetical)
// database: id → name → (alphabetical)
// credentials: id → name → (alphabetical)
// users[0]: id → name → (alphabetical)
This ensures consistent structure throughout your entire data tree, making it much easier for LLMs to process and understand your data efficiently.
Large Language Models process data more efficiently when it follows predictable patterns. Here's why the recursive key sorting approach is particularly beneficial for AI systems:
// Without keysPriority - LLM must scan each object differently
{
user: { email: "...", name: "...", id: "..." }, // id at position 3
profile: { bio: "...", id: "...", avatar: "..." }, // id at position 2
settings: { theme: "...", id: "...", enabled: "..." } // id at position 2
}
// With keysPriority - LLM knows exactly where to find key information
{
user: { id: "...", name: "...", email: "..." }, // id always first
profile: { id: "...", name: "...", avatar: "..." }, // id always first
settings: { id: "...", name: "...", enabled: "..." } // id always first
}
This approach transforms chaotic, unpredictable data structures into clean, learnable patterns that LLMs can process with maximum efficiency and accuracy.
Utility Functions:
// Compare efficiency between JSON and YAML
function compareJsonYamlEfficiency(jsonObject: unknown): {
json: string;
yaml: string;
jsonLength: number;
yamlLength: number;
reductionPercentage: number;
reductionRatio: string;
}
// Check if object is suitable for YAML conversion
function isYamlConvertible(value: unknown): boolean
Advanced content minification with intelligent strategy selection based on file type.
import { minifyContent } from 'octocode-utils';
const result = await minifyContent(
'const x = 1; // comment\n\nconst y = 2;',
'example.js'
);
console.log(result);
// Output:
// {
// content: 'const x=1;const y=2',
// failed: false,
// type: 'terser'
// }
JavaScript/TypeScript Family (Terser optimization):
.js, .ts, .jsx, .tsx, .mjs, .cjsIndentation-Sensitive (Conservative approach):
.py, .yaml, .yml, .coffee, .sass, .styl, .pugMarkup & Styles (Aggressive optimization):
.html, .htm, .xml, .svg, .css, .less, .scssProgramming Languages (Comment removal + whitespace):
.go, .java, .c, .cpp, .cs, .rust, .swift, .php, .rbData Formats (Specialized handling):
.json - JSON parsing and compression.md - Markdown-aware minificationAnd 50+ more file types with intelligent strategy selection.
async function minifyContent(
content: string,
filePath: string
): Promise<{
content: string;
failed: boolean;
type: 'terser' | 'conservative' | 'aggressive' | 'json' | 'general' | 'markdown' | 'failed';
reason?: string;
}>
# Install dependencies
yarn install
# Build the package
yarn build
# Run tests
yarn test
# Run tests in watch mode
yarn test:watch
# Run tests with coverage
yarn test:coverage
# Lint code
yarn lint
# Format code
yarn format
This package provides core utilities used across the Octocode MCP ecosystem:
src/
├── index.ts # Main exports
├── jsonToYamlString.ts # JSON to YAML conversion with token optimization
└── minifier.ts # Advanced content minification
This package is part of the Octocode MCP project. Contributions are welcome!
MIT - See LICENSE for details.
FAQs
Shared utilities for Octocode MCP packages
We found that octocode-utils demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.