Coder Social home page Coder Social logo

Comments (8)

SeyZ avatar SeyZ commented on August 21, 2024

Yes, I agree with the concept @xbill82.

I suggest to have an option which is a function that maps the attribute instead of having options like dasherize: true or camelCase:true or even underscore: true.

Something like:

keyForAttribute: function (attribute) { return camelCase(attribute); }

Thoughts?

from jsonapi-serializer.

xbill82 avatar xbill82 commented on August 21, 2024

Yeah, sounds fair!
So, this way the attributes field would become an object instead of an array? I say this because of the key: function structure you suggest...

from jsonapi-serializer.

xbill82 avatar xbill82 commented on August 21, 2024

And, also, there could be a couple of dasherize(attr), camelCase(attr) and underscore(attr) functions provided by the main JsonApiSerializer class, e.g.

new JsonApiSerializer('users', dataSet, {
    apiEndpoint: 'http://localhost:3000/api',
    attributes: {'firstName': function(attr){ return JsonApiSerializer.camelCase(attr)} },
  }

from jsonapi-serializer.

SeyZ avatar SeyZ commented on August 21, 2024

@xbill82 The master branch has been updated to have this new feature. Example:

var inflection = require('inflection');

new JsonApiSerializer('users', dataSet, {
    apiEndpoint: 'http://localhost:3000/api',
    attributes: ['firstName', 'lastName'],
    keyForAttribute: function (attribute) {
      return inflection.camelCase(attribute);
    }
  }

Thoughts? Does it fix your problem?

from jsonapi-serializer.

xbill82 avatar xbill82 commented on August 21, 2024

Sounds terrific. 👍
Just one thing: are you sure the name keyForAttribute would be easy to understand? I think we're dealing with attribute key transform, so I'd suggest something like transformAttributeKeys or something similar.
Would be happy to read your thoughts about it.

from jsonapi-serializer.

SeyZ avatar SeyZ commented on August 21, 2024

No, I'm not sure :) Ember.js uses this name to do the same thing:
http://emberjs.com/api/data/classes/DS.JSONSerializer.html#method_keyForAttribute

from jsonapi-serializer.

xbill82 avatar xbill82 commented on August 21, 2024

Good point! Ember is a great source of inspiration for conventions and habits! Great job!

from jsonapi-serializer.

SeyZ avatar SeyZ commented on August 21, 2024

Thanks @xbill82 !

from jsonapi-serializer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.