time-to-botec/js/node_modules/@stdlib/fs/read-json/docs/repl.txt

73 lines
1.8 KiB
Plaintext
Raw Normal View History

{{alias}}( file[, options], clbk )
Asynchronously reads a file as JSON.
Parameters
----------
file: string|Buffer|integer
Filename or file descriptor.
options: Object|string (optional)
Options. If a string, the value is the encoding.
options.encoding: string|null (optional)
Encoding. If the encoding option is set to `utf8` and the file has a
UTF-8 byte order mark (BOM), the byte order mark is *removed* before
attempting to parse as JSON. Default: null.
options.flag: string (optional)
Flag. Default: 'r'.
options.reviver: Function (optional)
JSON transformation function.
clbk: Function
Callback to invoke upon reading file contents.
Examples
--------
> function onRead( error, data ) {
... if ( error ) {
... console.error( error.message );
... } else {
... console.log( data );
... }
... };
> {{alias}}( './beep/boop.json', onRead );
{{alias}}.sync( file[, options] )
Synchronously reads a file as JSON.
Parameters
----------
file: string|Buffer|integer
Filename or file descriptor.
options: Object|string (optional)
Options. If a string, the value is the encoding.
options.encoding: string|null (optional)
Encoding. If the encoding option is set to `utf8` and the file has a
UTF-8 byte order mark (BOM), the byte order mark is *removed* before
attempting to parse as JSON. Default: null.
options.flag: string (optional)
Flag. Default: 'r'.
options.reviver: Function (optional)
JSON transformation function.
Returns
-------
out: Error|JSON
File contents.
Examples
--------
> var out = {{alias}}.sync( './beep/boop.json' );
See Also
--------