A lightweight, zero-dependency JavaScript library for handling APON (Aspectran Parameters Object Notation). This library provides an intuitive API to parse APON strings into JavaScript objects and stringify JavaScript objects back into APON strings, similar to the native JSON.parse()
and JSON.stringify()
APIs.
This library is designed to bring the readability and convenience of APON to the web environment, making it easy to manage configurations or structured data on the client-side.
- Parse APON: Convert any valid APON string into a standard JavaScript object.
- Stringify Objects: Convert JavaScript objects into clean, readable APON strings.
- Zero Dependencies: Written in plain JavaScript (ES6) for maximum compatibility.
- APON Spec Compliant: Accurately handles comments, nested structures, arrays, multi-line text, and automatic quoting based on the official Java implementation.
- Lightweight: A single file with a small footprint, perfect for web applications.
This library is not yet published to npm. Once published, you will be able to install it via:
npm install apon
For now, you can include apon.js
directly in your HTML file:
<script src="apon.js"></script>
Parses an APON string, constructing the JavaScript value or object described by the string.
text
:string
- The string to parse as APON.- Returns:
object
- The object corresponding to the given APON text.
Example:
const aponText = `
# User profile
user: {
name: "John Doe"
age(int): 30
active: true
roles: [
Admin
Editor
]
}
`;
const userObject = APON.parse(aponText);
console.log(userObject);
// { user: { name: 'John Doe', age: 30, active: true, roles: [ 'Admin', 'Editor' ] } }
Converts a JavaScript object into an APON formatted string.
obj
:object
- The object to convert. The top-level value must be a non-array object.options
(optional):object
ornumber
- An object that contains options, or the number of spaces to use for indentation.indent
:string
- The string to use for indentation (e.g.,' '
or' '
). Defaults to' '
.
Example:
const myObject = {
database: {
host: "localhost",
port: 5432,
users: ["admin", "readonly"]
},
debugMode: false
};
// Stringify with an indent of 2 spaces
const aponString = APON.stringify(myObject, { indent: ' ' });
console.log(aponString);
/*
database: {
host: localhost
port: 5432
users: [
admin
readonly
]
}
debugMode: false
*/
This project is licensed under the Apache License 2.0. See the LICENSE file for details.