Newts Parading Majestically
    Have ideas to improve npm?Join in the discussion! »

    @offen/analyticstxt-parser

    1.0.2 • Public • Published

    analyticstxt-parser

    JSON schema based Node.js library and CLI tool to parse and validate analytics.txt files.


    Installation

    The package is published to npm:

    npm i @offen/analyticstxt-parser -S
    

    and provides a library and an analyticstxt CLI tool.

    Usage

    CLI Usage

    For information on how to use the CLI, refer to the help subcommand:

    analyticstxt help
    

    Usage as a library

    The following functions are exported by this module:

    validate(content, { draftName? })

    Validate the given content of an analytics.txt file. Returns null in case validation passes or an error in case it fails. If no draftName is given, the default will be used (which is the latest published I-D).

    const fs = require('fs')
    
    const { validate } = require('@offen/analyticstxt-parser')
    
    const content = fs.readFileSync('./analytics.txt', 'utf-8')
    const error = validate(content)
    if (error) {
      // given file is not valid
    }

    parse(content, { lax = false, draftName? })

    Parse the given content of an analytics.txt file into its JavaScript Object representation. Returns an Array [result, error] where either can be null. If lax: true is given, the result will not be validated against the latest schema (or the given draftName).

    const fs = require('fs')
    
    const { parse } = require('@offen/analyticstxt-parser')
    
    const content = fs.readFileSync('./analytics.txt', 'utf-8')
    const [result, error] = parse(content)
    if (error) {
      // handle error
    }
    // process result

    serialize(source, { lax = false, draftName? })

    Serialize the given JavaScript Object representation into an analytics.txt file. Returns an Array [result, error] where either can be null. If lax: true is given, the source will not be validated against the latest schema (or the given draftName).

    const fs = require('fs')
    
    const { serialize } = require('@offen/analyticstxt-parser')
    
    const source = generateSourceSomehow()
    const [result, error] = serialize(source)
    if (error) {
      // handle error
    }
    fs.writeFileSync('./analytics.txt', result, 'utf-8')

    In addition to the three base methods, the JSON schema used for validating is exported as schema, its current draft name as defaultVersion.

    Keywords

    none

    Install

    npm i @offen/analyticstxt-parser

    DownloadsWeekly Downloads

    3

    Version

    1.0.2

    License

    MPL-2.0

    Unpacked Size

    45 kB

    Total Files

    13

    Last publish

    Collaborators

    • avatar