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

datom

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

datom - npm Package Compare versions

Comparing version 6.0.0 to 6.1.0

84

lib/main.js

@@ -170,3 +170,2 @@ (function() {

this.new_datom = function($key, $value, ...other) {
var R;
/* When `other` contains a key `$`, it is treated as a hint to copy

@@ -178,2 +177,8 @@ system-level attributes; if the value of key `$` is a POD that has itself a

validate.datom_key($key);
return this._new_datom($key, $value, ...other);
};
//-----------------------------------------------------------------------------------------------------------
this._new_datom = function($key, $value, ...other) {
var R;
if ($value != null) {

@@ -217,20 +222,24 @@ if ((!this.settings.merge_values) || (!isa.object($value))) {

//-----------------------------------------------------------------------------------------------------------
this.new_single_datom = function($key, $value, ...other) {
return this.new_datom(`^${$key}`, $value, ...other);
this.new_single_datom = function(name, ...P) {
validate.datom_name(name);
return this._new_datom(`^${name}`, ...P);
};
this.new_open_datom = function($key, $value, ...other) {
return this.new_datom(`<${$key}`, $value, ...other);
this.new_open_datom = function(name, ...P) {
validate.datom_name(name);
return this.new_datom(`<${name}`, ...P);
};
this.new_close_datom = function($key, $value, ...other) {
return this.new_datom(`>${$key}`, $value, ...other);
this.new_close_datom = function(name, ...P) {
validate.datom_name(name);
return this.new_datom(`>${name}`, ...P);
};
this.new_system_datom = function($key, $value, ...other) {
return this.new_datom(`~${$key}`, $value, ...other);
this.new_system_datom = function(name, ...P) {
validate.datom_name(name);
return this.new_datom(`~${name}`, ...P);
};
this.new_text_datom = function($value, ...other) {
return this.new_single_datom('text', $value, ...other);
this.new_text_datom = function(...P) {
return this.new_single_datom('text', ...P);
};

@@ -326,11 +335,51 @@

cram(name, ...content) {
var d1, d2;
if (!(content.length > 0)) {
return super.cram(this.settings.DATOM.new_datom(`^${name}`));
var $key, attributes, d1, d2, has_attributes, i, idx, len, part, template;
if ((isa.text(name)) && (content.length === 0)) {
return super.cram(this.settings.DATOM.new_single_datom(name));
}
has_attributes = false;
template = null;
if (this.settings.absorb) {
if (isa.object(name)) {
[name, template] = [null, name];
}
attributes = {};
for (idx = i = 0, len = content.length; i < len; idx = ++i) {
part = content[idx];
if (!isa.object(part)) {
continue;
}
has_attributes = true;
Object.assign(attributes, part);
content.splice(idx, 1);
}
}
if (name === null) {
return super.cram(...content);
if ((!has_attributes) && (template == null)) {
return super.cram(...content);
}
if (template != null) {
if (content.length > 0) {
throw new Error(`^datom/cupofjoe@3412^ cannot have template and content, got ${rpr({template, content})}`);
}
template = Object.assign({}, template, attributes);
if (($key = template.$key) == null) {
throw new Error(`^datom/cupofjoe@3442^ cannot have template without $key, got ${rpr({template})}`);
}
delete template.$key;
return super.cram(this.settings.DATOM.new_datom($key, template));
}
} else if (content.length === 0) {
if (has_attributes) {
return super.cram(this.settings.DATOM.new_single_datom(name, attributes));
}
return super.cram(this.settings.DATOM.new_single_datom(name));
} else {
if (has_attributes) {
d1 = this.settings.DATOM.new_open_datom(name, attributes);
} else {
d1 = this.settings.DATOM.new_open_datom(name);
}
}
d1 = this.settings.DATOM.new_datom(`<${name}`);
d2 = this.settings.DATOM.new_datom(`>${name}`);
d2 = this.settings.DATOM.new_close_datom(name);
return super.cram(d1, ...content, d2);

@@ -357,2 +406,3 @@ }

flatten: true,
absorb: true,
DATOM: null

@@ -359,0 +409,0 @@ };

@@ -1,2 +0,1 @@

// Generated by CoffeeScript 2.5.1
(function() {

@@ -90,5 +89,8 @@ 'use strict';

tests: {
"x is a nonempty text": function(x) {
return this.isa.nonempty_text(x);
"x is a text": function(x) {
return this.isa.text(x);
},
"x has at least 2 chrs": function(x) {
return x.length > 1;
},
"x has sigil": function(x) {

@@ -101,2 +103,11 @@ return this.isa.datom_sigil(x[0]);

//-----------------------------------------------------------------------------------------------------------
this.declare('datom_name', {
tests: {
"x is a nonempty text": function(x) {
return this.isa.nonempty_text(x);
}
}
});
//-----------------------------------------------------------------------------------------------------------
this.declare('datom_datom', {

@@ -146,2 +157,2 @@ tests: {

//# sourceMappingURL=types.js.map
//# sourceMappingURL=types.js.map
{
"name": "datom",
"version": "6.0.0",
"version": "6.1.0",
"description": "standardized immutable objects in the spirit of datomic, especially suited for use in data pipelines",

@@ -5,0 +5,0 @@ "main": "lib/main.js",

@@ -30,2 +30,3 @@

- [Vectorial NumbeRs (VNRs)](#vectorial-numbers-vnrs)
- [Cup Of Datom](#cup-of-datom)
- [To Do](#to-do)

@@ -402,3 +403,72 @@

# Cup Of Datom
Class `Cupofdatom` is a derivative of [`Cupofjoe`](https://github.com/loveencounterflow/cupofjoe) that is
geared towards easy declarative generation of nested sequences of datoms with a
[teacup](https://github.com/goodeggs/teacup)-like syntax:
```coffee
c = new DATOM.Cupofdatom()
c.cram 'helo', 'world'
c.cram 'foo', ->
c.cram 'bold', ->
c.cram null, 'content'
ds = c.expand()
# `ds` is now a list of datoms:
[
{ $key: '<helo' },
{ $key: '^text', text: 'world' },
{ $key: '>helo' },
{ $key: '<foo' },
{ $key: '<bold' },
{ $key: '^text', text: 'content' },
{ $key: '>bold' },
{ $key: '>foo' } ]
```
* First argument to `cram()` becomes key of datom
* therefore, must be a valid datom name
* sigil will be `^` if called with no further arguments
* or else two datoms with sigils `<` and `>` will be generated that surround their contents
* text arguments will be turned into `^text` datoms
* as with `Cupofjoe`, functions will be called, may either call `cram()` method or return value
* also possible to provide objects whose members will become attributes of the respective datom:
```coffee
c = new DATOM.Cupofdatom { absorb: true, } # default value; Note: turn attributes off with { absorb: false, }
c.cram 'greeting', 'helo', 'world'
c.cram 'greeting', '早安', { lang: 'zh_CN', }
c.cram { $key: '^greeting', lang: 'zh_CN', 问候: '早安', time_of_day: 'morning', }
c.cram { $key: '^text', lang: 'hi', text: 'नमस्ते', }
c.cram 'greeting', ->
c.cram 'language', { $value: 'Japanese', }
c.cram 'time_of_day', { $value: 'morning', }
c.cram null, 'お早うございます'
```
gives
```
{ $key: '<greeting' }
{ $key: '^text', text: 'helo', }
{ $key: '^text', text: 'world', }
{ $key: '>greeting' }
{ $key: '<greeting', lang: 'zh_CN', }
{ $key: '^text', text: '早安', }
{ $key: '>greeting' }
{ $key: '^greeting', lang: 'zh_CN', '问候': '早安', time_of_day: 'morning', }
{ $key: '^text', text: 'नमस्ते', lang: 'hi', }
{ $key: '<greeting' }
{ $key: '^language', $value: 'Japanese', }
{ $key: '^time_of_day', $value: 'morning', }
{ $key: '^text', text: 'お早うございます', }
{ $key: '>greeting' }
```
* if first argument is an object, it is taken as 'template' for the datom
* this is only available when `Cupofdatom` has been instantiated with `{ absorb: true, }` (the default)
* no content may appear together with a template in the same `cram()` call
* the template *must* have a valid datom `$key` attribute
# To Do

@@ -405,0 +475,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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