projen
Version:
CDK for software projects
94 lines (93 loc) • 3.57 kB
TypeScript
import type { BlankLineNode, CommentNode, KeyCollisions, KeyValuePairObject, NormalizeOptions, PropertiesNode, PropertyNode } from './nodes.js';
/**
* A lossless, ordered representation of a `.properties` file.
*
* Every element in the file — properties, comments, and blank lines — is
* preserved in order. Duplicate keys are all retained. The original content
* can be reconstructed exactly via {@link format}.
*/
export declare class Properties {
/** Whether the content started with a BOM character. */
readonly hasBom: boolean;
/** The end-of-line character detected from the content. */
readonly eolCharacter: string;
/** All nodes in file order. */
readonly nodes: PropertiesNode[];
/**
* Parse a `.properties` file into a lossless node structure.
*
* @param content - The content of a `.properties` file (string or Buffer).
*/
constructor(content: string | Buffer);
/**
* Get all property nodes in file order (including duplicates).
*
* @returns An array of all {@link PropertyNode} instances.
*/
getProperties(): PropertyNode[];
/**
* Get all comment nodes in file order.
*
* @returns An array of all {@link CommentNode} instances.
*/
getComments(): CommentNode[];
/**
* Get all blank line nodes in file order.
*
* @returns An array of all {@link BlankLineNode} instances.
*/
getBlankLines(): BlankLineNode[];
/**
* Get the effective key-value map (last-wins semantics for duplicate keys).
*
* @returns A plain object where each key maps to its last-occurring value.
*/
toObject(): KeyValuePairObject;
/**
* Get all property nodes for a given key (all occurrences, in file order).
*
* @param key - The unescaped key to search for.
*
* @returns An array of matching {@link PropertyNode} instances (empty if not found).
*/
getPropertyNodes(key: string): PropertyNode[];
/**
* Get the effective property node for a given key (last occurrence).
*
* @param key - The unescaped key to search for.
*
* @returns The last {@link PropertyNode} with this key, or `undefined`.
*/
getEffectiveProperty(key: string): PropertyNode | undefined;
/**
* Get keys that appear more than once, with all their property nodes.
*
* @returns An array of {@link KeyCollisions} for duplicate keys.
*/
getKeyCollisions(): KeyCollisions[];
/**
* Get comment and blank line nodes immediately preceding a property.
*
* Walks backward from the last occurrence of the given key, collecting
* comment and blank line nodes until reaching another property or the
* start of the file.
*
* @param key - The unescaped key to find leading nodes for.
*
* @returns An array of preceding {@link CommentNode} and {@link BlankLineNode} instances.
*/
getLeadingNodes(key: string): (CommentNode | BlankLineNode)[];
/**
* Format the `.properties` content as a string.
*
* Without options, produces an exact lossless reconstruction of the original
* content. With options, produces normalized output — standardize separators,
* remove comments, deduplicate keys, and more.
*
* @param options - Optional normalization options. When omitted, the output
* is a lossless round-trip of the original content.
*
* @returns The formatted `.properties` file content.
*/
format(options?: NormalizeOptions): string;
}