jeremyfa / yaml.js

Standalone JavaScript YAML 1.2 Parser & Encoder. Works under node.js and all major browsers. Also brings command line YAML/JSON conversion tools.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow Date formatting when dumping

zachwhaley opened this issue · comments

I'd like to be able to dump a Date object in a desired format, personally YYYY-MM-DD with no time stamp.

I thought I could use the objectEncoder, but there appears to be an exception for Date objects https://github.com/jeremyfa/yaml.js/blob/develop/lib/Inline.js#L97

If there was no exception made for Date objects, this would become possible and we'd be able to use any date formatting library without adding a dependency to yaml.js

e.g.

    type = typeof value;
    if (type === 'object') {
      if (objectEncoder != null) {
        result = objectEncoder(value);
        if (typeof result === 'string' || (result != null)) {
          return result;
        }
      }
      if (value instanceof Date) {
        return value.toISOString();
      }
      return this.dumpObject(value);
    }