How to use the jsonapi-serializer.Serializer function in jsonapi-serializer

To help you get started, we’ve selected a few jsonapi-serializer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / types / jsonapi-serializer / jsonapi-serializer-tests.ts View on Github external
import { Serializer, Deserializer, Error } from "jsonapi-serializer";

declare let firstName: string;
declare let lastName: string;

const UserSerializer = new Serializer("users", {
    id: "id",
    attributes: ["firstName", "lastName"],
    keyForAttribute: "camelCase",
    pluralizeType: false
});

const users = UserSerializer.serialize({ firstName, lastName });

const UserDeserializer = new Deserializer({
    id: "id",
    keyForAttribute: "camelCase",
    pluralizeType: false,
    typeAsAttribute: true
});

UserDeserializer.deserialize(users);
github mansona / express-autoroute-json / lib / serialise.js View on Github external
if (Array.isArray(data)) {
        data.forEach(item => _.assign(item, { [key]: '****' }));
      } else {
        _.assign(data, { [key]: '****' });
      }

      schema[key] = {
        ref: function(object) {
          return object._id;
        },
      };
    });
  }

  var serializer = new JSONAPISerializer(type, schema);

  return serializer.serialize(data);
};
github ForestAdmin / forest-express / src / integrations / intercom / serializers / intercom-attributes.js View on Github external
function IntercomAttributesSerializer(attributes, collectionName, meta) {
  const type = `${collectionName}_intercom_attributes`;

  return new JSONAPISerializer(type, attributes, {
    attributes: ['session_count', 'last_seen_ip', 'created_at', 'updated_at',
      'signed_up_at', 'last_request_at', 'country', 'city', 'user_agent',
      'companies', 'segments', 'tags', 'browser', 'platform', 'geoloc'],
    keyForAttribute(key) { return key; },
    meta,
  });
}
github ForestAdmin / forest-express-sequelize / serializers / stripe-invoices.js View on Github external
if (invoice.period_start) {
      invoice.period_start =  new Date(invoice.period_start * 1000);
    }

    if (invoice.period_end) {
      invoice.period_end =  new Date(invoice.period_end * 1000);
    }

    if (invoice.subtotal) { invoice.subtotal /= 100; }
    if (invoice.total) { invoice.total /= 100; }

    return invoice;
  });

  return new JSONAPISerializer('stripe-invoices', invoices, {
    attributes: ['amount_due', 'attempt_count', 'attempted', 'closed',
      'currency', 'date', 'forgiven', 'paid', 'period_start', 'period_end',
      'subtotal', 'total', 'application_fee', 'tax', 'tax_percent',
      'customer'],
    customer: {
      ref: 'id',
      attributes: customerAttributes
    },
    keyForAttribute: function (key) {
      return Inflector.underscore(key);
    },
    typeForAttribute: function (attr) {
      if (attr === 'customer') { return customerCollectionName; }
      return attr;
    },
    meta: meta
github ForestAdmin / forest-express-sequelize / serializers / resource.js View on Github external
}

    var serializationOptions = {
      attributes: _.map(schema.fields, 'field'),
      keyForAttribute: function (key) {
        return key;
      },
      typeForAttribute: function (attribute) {
        return typeForAttributes[attribute] || attribute;
      },
      meta: meta
    };

    getAttributesFor(serializationOptions, schema.fields);

    return new JSONAPISerializer(schema.name, records,
      serializationOptions);
  };
}
github villeristi / koa-api-boilerplate / src / config / middleware.js View on Github external
ctx.serializer = (type, opts) => {
    return new Serializer(type, opts);
  };
github mathcoll / t6 / serializers / rule.js View on Github external
this.serialize = function () {
	return new JSONAPISerializer("rule", {
		keyForAttribute: "underscore_case",
		attributes: ["name", "user_id", "id", "rule", "active", "meta"],
		rule: {
			attributes: ["conditions", "event", "priority"],
		},
		topLevelLinks : {
			parent : sprintf("%s/v%s/rules", baseUrl_https, version),
			self : rule.pageSelf!==undefined?sprintf("%s/v%s/rules/?page=%s&size=%s", baseUrl_https, version, rule.pageSelf, rule.size):undefined,
			first : rule.pageFirst!==undefined?sprintf("%s/v%s/rules/?page=%s&size=%s", baseUrl_https, version, rule.pageFirst, rule.size):undefined,
			prev : rule.pagePrev!==undefined?sprintf("%s/v%s/rules/?page=%s&size=%s", baseUrl_https, version, rule.pagePrev, rule.size):undefined,
			last : rule.pageLast!==undefined?sprintf("%s/v%s/rules/?page=%s&size=%s", baseUrl_https, version, rule.pageLast, rule.size):undefined,
			next : rule.pageNext!==undefined?sprintf("%s/v%s/rules/?page=%s&size=%s", baseUrl_https, version, rule.pageNext, rule.size):undefined,
		},
		dataLinks : {
			self : function(rule) {
				return sprintf("%s/v%s/rules/%s", baseUrl_https, version, rule.id);
github ForestAdmin / forest-express / src / serializers / resource.js View on Github external
      .then(() => new JSONAPISerializer(schema.name, records, serializationOptions));
  };
github mathcoll / t6 / serializers / snippet.js View on Github external
this.serialize = function () {
		return new JSONAPISerializer("snippet", {
			keyForAttribute: "underscore_case",
			attributes: ["name", "user_id", "description", "type", "icon", "color", "flows", "meta"],
			topLevelLinks : {
				parent : sprintf("%s/v%s/snippets", baseUrl_https, version),
				self : snippet.pageSelf!==undefined?sprintf("%s/v%s/snippets/?page=%s&size=%s", baseUrl_https, version, snippet.pageSelf, snippet.size):undefined,
				first : snippet.pageFirst!==undefined?sprintf("%s/v%s/snippets/?page=%s&size=%s", baseUrl_https, version, snippet.pageFirst, snippet.size):undefined,
				prev : snippet.pagePrev!==undefined?sprintf("%s/v%s/snippets/?page=%s&size=%s", baseUrl_https, version, snippet.pagePrev, snippet.size):undefined,
				last : snippet.pageLast!==undefined?sprintf("%s/v%s/snippets/?page=%s&size=%s", baseUrl_https, version, snippet.pageLast, snippet.size):undefined,
				next : snippet.pageNext!==undefined?sprintf("%s/v%s/snippets/?page=%s&size=%s", baseUrl_https, version, snippet.pageNext, snippet.size):undefined,
			},
			dataLinks : {
				self : function(snippet) {
					return sprintf("%s/v%s/snippets/%s", baseUrl_https, version, snippet.id);
				},
				user : function(snippet) {
					if ( snippet.user_id!="" ) {

jsonapi-serializer

A Node.js framework agnostic library for serializing your data to JSON API

MIT
Latest version published 1 year ago

Package Health Score

63 / 100
Full package analysis