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

@graphy/content.ttl.write

Package Overview
Dependencies
Maintainers
2
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graphy/content.ttl.write - npm Package Compare versions

Comparing version 3.2.2 to 4.0.0

174

main.js

@@ -5,4 +5,5 @@

const factory = require('@graphy/core.data.factory');
const writable = require('@graphy/core.class.writable');
const Writable = require('@graphy/core.class.writable');
// eslint-disable-next-line no-misleading-character-class
const RT_PREFIXED_NAME_NAMESPACE_VALID = /^([A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\u{02ff}\u{0370}-\u{037d}\u{037f}-\u{1fff}\u{200c}-\u{200d}\u{2070}-\u{218f}\u{2c00}-\u{2fef}\u{3001}-\u{d7ff}\u{f900}-\u{fdcf}\u{fdf0}-\u{fffd}\u{10000}-\u{effff}]([A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\u{02ff}\u{0370}-\u{037d}\u{037f}-\u{1fff}\u{200c}-\u{200d}\u{2070}-\u{218f}\u{2c00}-\u{2fef}\u{3001}-\u{d7ff}\u{f900}-\u{fdcf}\u{fdf0}-\u{fffd}\u{10000}-\u{effff}_\-0-9\xb7\u{0300}-\u{036f}\u{203f}-\u{2040}.]*[A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\u{02ff}\u{0370}-\u{037d}\u{037f}-\u{1fff}\u{200c}-\u{200d}\u{2070}-\u{218f}\u{2c00}-\u{2fef}\u{3001}-\u{d7ff}\u{f900}-\u{fdcf}\u{fdf0}-\u{fffd}\u{10000}-\u{effff}_\-0-9\xb7\u{0300}-\u{036f}\u{203f}-\u{2040}])?)?$/u;

@@ -13,3 +14,3 @@ const N_MAX_STRING_BUFFER = 1 << 12;

class Turtle_Writer extends writable {
class Turtle_Writer extends Writable {
constructor(gc_writer={}) {

@@ -20,24 +21,33 @@ super(gc_writer);

prefixes: h_prefixes={},
indent: s_indent='\t',
tokens: gc_tokens=null,
collections: gc_collections=null,
lists: gc_lists=null,
debug: b_debug=false,
style: gc_style=null,
} = gc_writer;
Object.assign(this, {
indent: s_indent,
debug: b_debug,
_b_debug: b_debug,
_s_indent: '\t',
_b_simplify_default_graph: false,
});
// style config
if(gc_style) {
// indent
if(gc_style.indent) {
this._s_indent = gc_style.indent.replace(/[^\s]/g, '');
}
}
// custom collection keys
if(gc_collections) {
// serialize collection object
this.collection_object = function(a_collection, n_nest_level) {
// transcode collection object
let hc2_transcoded = this.transcode_collection(a_collection);
// custom list keys
if(gc_lists) {
// serialize list object
this._serialize_list_object = function(a_list, n_nest_level) {
// transcode list object
let hc2_transcoded = this._transcode_list(a_list);
// serialize object
return this.objects(hc2_transcoded, n_nest_level);
return this._encode_objects(hc2_transcoded, n_nest_level);
};

@@ -72,9 +82,12 @@ }

// serialize prefixes
serialize_prefixes(h_prefixes) {
_serialize_prefixes(h_prefixes) {
// build prefixes string
let s_prefixes = (2 === this.state)? '\n\n': '';
let s_prefixes = (2 === this._xc_state)? '\n\n': '';
// update state
this.state = 0;
this._xc_state = 0;
// clone prefixes
this._h_prefixes = {...this._h_prefixes};
// each user-defined prefix

@@ -91,5 +104,8 @@ for(let s_prefix_id in h_prefixes) {

// set prefix
this.prefixes[s_prefix_id] = h_prefixes[s_prefix_id];
this._h_prefixes[s_prefix_id] = h_prefixes[s_prefix_id];
}
// recache
factory.cache_prefixes(this._h_prefixes);
// return prefix string

@@ -101,23 +117,31 @@ return s_prefixes;

// serialize c3 hash
serialize_c3(hc3_triples) {
// serialize c3 hash
_serialize_c3(hc3_triples) {
let {
prefixes: h_prefixes,
indent: s_indent,
_h_prefixes: h_prefixes,
_s_indent: s_indent,
} = this;
// break line if non-data state
let s_write = 2 !== this.state? '\n': '';
// update state
this.state = 2;
// break line if non-data state
let s_write = 2 !== this._xc_state? '\n': '';
// update state
this._xc_state = 2;
// triple delimiter
// triple delimiter
let s_delim_triples = '';
// subject exit listener
let f_exit_subject = null;
// each subject
for(let sc1_subject in hc3_triples) {
// directive
// directive
if('`' === sc1_subject[0]) {
s_write += s_delim_triples+this.directive(sc1_subject, hc3_triples[sc1_subject]);
// do not break next line
s_delim_triples = '';
let g_apply = this._apply_directive(sc1_subject, hc3_triples[sc1_subject]);
// write data
if(g_apply.write) {
s_write += s_delim_triples+g_apply.write;
// do not break next line
s_delim_triples = '';
}
// save exit listener
if(g_apply.exit) f_exit_subject = g_apply.exit;
continue;

@@ -138,14 +162,21 @@ }

let b_empty = true;
// predicate exit listener
let f_exit_predicate = null;
// each predicate
for(let sc1_predicate in hc2_pairs) {
// directive
// directive
if('`' === sc1_predicate[0]) {
// apply directive
let g_apply = this._apply_directive(sc1_predicate, hc2_pairs[sc1_predicate]);
// write data
if(g_apply.write) {
// break line
s_write += (s_indent_pairs? s_term_pairs: '\n')+s_indent;
// serialize directive
s_write += this.directive(sc1_predicate, hc2_pairs[sc1_predicate]);
// pair already terminated
s_term_pairs = '';
// indent next pair
s_indent_pairs = s_indent;
s_write += (s_indent_pairs? s_term_pairs: '\n')+s_indent+g_apply.write;
// pair already terminated
s_term_pairs = '';
// indent next pair
s_indent_pairs = s_indent;
}
// save exit listener
if(g_apply.exit) f_exit_predicate = g_apply.exit;
continue;

@@ -156,3 +187,3 @@ }

// serialize objects
let st_objects = this.objects(z_objects);
let st_objects = this._encode_objects(z_objects);
// no objects; skip pair

@@ -173,4 +204,4 @@ if(!st_objects) continue;

// update state
this.state = 2;
// // string buffer became too large
this._xc_state = 2;
// // string buffer became too large
// if(s_write.length >= N_MAX_STRING_BUFFER) {

@@ -183,2 +214,4 @@ // debugger;

s_indent_pairs = s_indent;
// call exit predicate listener
if(f_exit_predicate) f_exit_predicate();
}

@@ -194,6 +227,7 @@ // empty triples; cut out

s_write += `${s_term_pairs? ' ': s_indent_pairs}.\n`; //
// call exit subject listener
if(f_exit_subject) f_exit_subject();
}
s_write += '\n';
return s_write;

@@ -203,8 +237,8 @@ }

// write objects
objects(z_objects, n_nest_level=1) {
// write objects
_encode_objects(z_objects, n_nest_level=1) {
let {
prefixes: h_prefixes,
indent: s_indent,
coercions: hm_coercions,
_h_prefixes: h_prefixes,
_s_indent: s_indent,
_hm_coercions: hm_coercions,
} = this;

@@ -237,5 +271,5 @@

for(let z_item of z_objects) {
// item is an array; write RDF collection
// item is an array; serialize list
if(Array.isArray(z_item)) {
s_write += s_term_object + this.collection_object(z_item, n_nest_level);
s_write += s_term_object + this._serialize_list_object(z_item, n_nest_level);
}

@@ -245,3 +279,3 @@ // non-array

// recurse on item
s_write += s_term_object + this.objects(z_item, n_nest_level);
s_write += s_term_object + this._encode_objects(z_item, n_nest_level);
}

@@ -263,2 +297,5 @@

// object exit listener
let f_exit_object = null;
// each pair

@@ -274,3 +311,9 @@ for(let sc1_predicate in z_objects) {

if('`' === sc1_predicate[0]) {
s_write += this.directive(sc1_predicate, z_objects[sc1_predicate]);
let g_apply = this._apply_directive(sc1_predicate, z_objects[sc1_predicate]);
// write data
if(g_apply.write) s_write += g_apply.write;
// save exit listener
if(g_apply.exit) f_exit_object = g_apply.exit;
continue;

@@ -281,3 +324,3 @@ }

s_write += factory.c1(sc1_predicate, h_prefixes).terse(h_prefixes) + ' '
+ this.objects(z_objects[sc1_predicate], n_nest_level+1) +' ;';
+ this._encode_objects(z_objects[sc1_predicate], n_nest_level+1) +' ;';
}

@@ -288,2 +331,5 @@

// call exit object listener
if(f_exit_object) f_exit_object();
// serialize current predicate to blank node

@@ -318,4 +364,4 @@ return s_write;

// serialize collection object
collection_object(a_collection, n_nest_level) {
let s_indent = this.indent;
_serialize_collection_object(a_collection, n_nest_level) {
let s_indent = this._s_indent;

@@ -331,7 +377,7 @@ // open collection block

if(Array.isArray(z_item)) {
s_objects = this.collection_object(z_item, n_nest_level+1);
s_objects = this._serialize_collection_object(z_item, n_nest_level+1);
}
// non-array item
else {
s_objects = this.objects(z_item, n_nest_level+1);
s_objects = this._encode_objects(z_item, n_nest_level+1);
}

@@ -353,4 +399,4 @@

// rdfjs quad
serialize_quad(g_quad) {
let h_prefixes = this.prefixes;
_serialize_quad(g_quad) {
let h_prefixes = this._h_prefixes;
let kq_quad = factory.from.quad(g_quad);

@@ -360,3 +406,3 @@

// serialize quad
let s_write = (2 !== this.state? '\n': '')
this._s_push += (2 !== this._xc_state? '\n': '')
+kq_quad.subject.terse(h_prefixes)+' '

@@ -368,5 +414,3 @@ +kq_quad.predicate.terse(h_prefixes)+' '

// update state
this.state = 2;
return s_write;
this._xc_state = 2;
}

@@ -377,2 +421,6 @@ }

anonymous_blank_nodes: true,
_serialize_c3r: Turtle_Writer.prototype._serialize_c3,
_serialize_c4r: Turtle_Writer.prototype._serialize_c4,
_serialize_comment: Writable.prototype._serialize_hash_comment,
_serialize_list_object: Turtle_Writer.prototype._serialize_collection_object,
});

@@ -379,0 +427,0 @@

{
"name": "@graphy/content.ttl.write",
"version": "3.2.2",
"description": "RDF Turtle content writer",
"version": "4.0.0",
"description": "RDF Turtle content writer for dynamic and stylized output",
"keywords": [

@@ -26,5 +26,5 @@ "linked-data",

"dependencies": {
"@graphy/core.class.writable": "^3.2.2",
"@graphy/core.data.factory": "^3.2.2",
"big-integer": "^1.6.41"
"@graphy/core.class.writable": "^4.0.0",
"@graphy/core.data.factory": "^4.0.0",
"big-integer": "^1.6.48"
},

@@ -34,2 +34,2 @@ "engines": {

}
}
}
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