Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

blueflag-record

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

blueflag-record - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

98

lib/__tests__/Record-test.js

@@ -7,2 +7,12 @@ "use strict";

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _clear = _interopRequireDefault(require("unmutable/lib/clear"));

@@ -34,9 +44,9 @@

var _Record = _interopRequireDefault(require("../Record"));
var _Record2 = _interopRequireDefault(require("../Record"));
var FooRecord = (0, _Record.default)({
var FooRecord = (0, _Record2.default)({
foo: 'bar',
baz: undefined
});
var DateRecord = (0, _Record.default)({
var DateRecord = (0, _Record2.default)({
start: {

@@ -52,2 +62,43 @@ notSetValue: '2000-01-01',

});
var DerivedFieldsRecord = (0, _Record2.default)({
name: undefined,
nameLowercase: {
get: function get(value, data) {
return data.name.toLowerCase();
}
},
dateOfBirth: {
get: function get(value) {
return new Date(value);
},
set: function set(value) {
return value.getFullYear();
}
},
dateOfBirthRaw: {
get: function get(value, data) {
return data.dateOfBirth;
}
}
});
var ConstructedFieldsRecord =
/*#__PURE__*/
function (_Record) {
(0, _inherits2.default)(ConstructedFieldsRecord, _Record);
function ConstructedFieldsRecord(data) {
(0, _classCallCheck2.default)(this, ConstructedFieldsRecord);
return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(ConstructedFieldsRecord).call(this, (0, _objectSpread2.default)({}, data, {
bar: data.foo + data.foo
})));
}
return ConstructedFieldsRecord;
}((0, _Record2.default)({
foo: undefined,
bar: undefined
}));
;
describe('constructing', function () {

@@ -116,10 +167,17 @@ it('it will throw for foriegn keys', function () {

it('supports the toObject function', function () {
var foo = new FooRecord({
var foo = (0, _pipeWith.default)(new FooRecord({
foo: 'radical'
});
var data = (0, _pipeWith.default)(foo, (0, _toObject.default)());
expect(data).toEqual({
}), (0, _toObject.default)());
expect(foo).toEqual({
foo: 'radical',
baz: undefined
});
var derivedFields = (0, _pipeWith.default)(new DerivedFieldsRecord({
name: 'Mildred',
dateOfBirth: '2000-01-01'
}), (0, _toObject.default)());
expect(derivedFields).toEqual({
name: 'Mildred',
dateOfBirth: '2000-01-01'
});
});

@@ -139,2 +197,16 @@ it('will not apply getters to toObject', function () {

});
it('passes the data object as the getters second parameter', function () {
var date = new DerivedFieldsRecord({
name: 'Mildred'
});
expect(date.nameLowercase).toBe('mildred');
});
it('passes the data object without passing it through getters', function () {
var date = new DerivedFieldsRecord({
name: 'Mildred',
dateOfBirth: '2000-01-01'
});
expect(date.dateOfBirth).toEqual(new Date('2000-01-01'));
expect(date.dateOfBirthRaw).toBe('2000-01-01');
});
});

@@ -224,2 +296,14 @@ describe('setters', function () {

});
});
describe('constructed fields', function () {
it('will set field values during construction', function () {
var record = new ConstructedFieldsRecord({
foo: 'hello'
});
expect(record.foo).toBe('hello');
expect(record.bar).toBe('hellohello');
var recordAfterSet = record.set('foo', 'hi');
expect(recordAfterSet.foo).toBe('hi');
expect(recordAfterSet.bar).toBe('hihi');
});
});

26

lib/Record.js

@@ -42,3 +42,3 @@ "use strict";

var indentity = function indentity(x) {
var identity = function identity(x) {
return x;

@@ -61,13 +61,8 @@ };

var notSetValues = (0, _map.default)(function (vv) {
return vv && vv.notSetValue || vv;
if ((0, _typeof2.default)(vv) !== 'object') {
return vv;
}
return (0, _get.default)('notSetValue')(vv);
})(config);
var setter = function setter(key, value) {
return ((keyConfig[key] || {}).set || indentity)(value);
};
var getter = function getter(key, value) {
return ((keyConfig[key] || {}).get || indentity)(value);
};
return (

@@ -81,2 +76,11 @@ /*#__PURE__*/

(0, _classCallCheck2.default)(this, Record);
var setter = function setter(key, value) {
return ((keyConfig[key] || {}).set || identity)(value);
};
var getter = function getter(key, value) {
return ((keyConfig[key] || {}).get || identity)(value, _this._data);
};
Object.defineProperties(this, {

@@ -83,0 +87,0 @@ // Private values

{
"main": "lib/index.js",
"name": "blueflag-record",
"version": "0.3.0",
"version": "0.4.0",
"description": "An Unmutable compatible record",

@@ -6,0 +6,0 @@ "license": "MIT",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc