Not Particularly Meaningful

    transform-per-suffixes

    1.0.1 • Public • Published

    transform-per-suffixes

    Map object properties according to suffixes.

    NPM version Build status Dependency Status devDependency Status Coverage Status Code Climate Dependency Status

    A simple helper to transform every properties of an object having a specific suffix.

    I mainly use it to transform my JSONs according to conventional prefixes. By example, for MongoDB ObjectIds.

    API

    transform-per-suffixes

    transform-per-suffixes~transformPerSuffixes(suffixes, val) ⇒ Object | Array

    Transform every properties of an object according to given suffixes.

    Kind: inner method of transform-per-suffixes
    Returns: Object | Array - The modified object

    Param Type Description
    suffixes Array An array of suffix definitions ({value: String, transform: Function})
    val Object | Array The source Object/Array

    Example

    var object = {
      _id: 'abbacacaabbacacaabbacaca',
      creation_date: '2015-11-28T16:22:47.552Z',
      value: 'Hey!'
    };
    var suffixes = [{
      value: '_id',
      transform: castToObjectId,
    }, {
      value: '_date',
      transform: function(d) { return new Date(d) },
    }];
     
    console.log(transformPerSuffixes(suffixes, object));
    // Prints:
    // {
    //   _id: ObjectId('abbacacaabbacacaabbacaca'),
    //   creation_date: Date('2015-11-28T16:22:47.552Z'),
    //   value: 'Hey!'
    // }

    License

    MIT

    Install

    npm i transform-per-suffixes

    DownloadsWeekly Downloads

    128

    Version

    1.0.1

    License

    MIT

    Last publish

    Collaborators

    • nfroidure
    • sebastienelet