Socket
Socket
Sign inDemoInstall

intertext

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

intertext - npm Package Compare versions

Comparing version 3.0.0 to 4.0.0

181

lib/cupofhtml.js
(function() {
'use strict';
var CND, DATOM, MAIN, Multimix, _defaults, alert, badge, cast, debug, echo, help, info, isa, log, ref, ref1, rpr, type_of, types, urge, validate, warn, whisper,
boundMethodCheck = function(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new Error('Bound instance method accessed before binding'); } };
boundMethodCheck = function(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new Error('Bound instance method accessed before binding'); } },
indexOf = [].indexOf;

@@ -43,6 +44,7 @@ //###########################################################################################################

//...........................................................................................................
_defaults = Object.freeze({
_defaults = {
flatten: true,
DATOM: null
});
DATOM: null,
newlines: true
};

@@ -977,5 +979,142 @@ //===========================================================================================================

//###########################################################################################################
//###########################################################################################################
//###########################################################################################################
//###########################################################################################################
//###########################################################################################################
//###########################################################################################################
//===========================================================================================================
//-----------------------------------------------------------------------------------------------------------
this._escape_text = function(x) {
var R;
R = x;
R = R.replace(/&/g, '&');
R = R.replace(/</g, '&lt;');
R = R.replace(/>/g, '&gt;');
return R;
};
//-----------------------------------------------------------------------------------------------------------
this._as_attribute_literal = function(x) {
var R, must_quote;
R = isa.text(x) ? x : JSON.stringify(x);
must_quote = !isa._intertext_html_naked_attribute_text(R);
R = this._escape_text(R);
R = R.replace(/'/g, '&#39;');
R = R.replace(/\n/g, '&#10;');
if (must_quote) {
R = "'" + R + "'";
}
return R;
};
//-----------------------------------------------------------------------------------------------------------
this.$html_from_datoms = function() {
var $;
({$} = (require('steampipes')).export());
return $((d, send) => {
var ds, i, len;
ds = (isa.list(d)) ? d : [d];
for (i = 0, len = ds.length; i < len; i++) {
d = ds[i];
send(this._html_from_datom({
newlines: false
}, d));
}
return null;
});
};
//-----------------------------------------------------------------------------------------------------------
this._html_from_datom = function(settings, d) {
var atxt, bnl, i, is_block_tag, is_empty_tag, key, len, ref2, ref3, ref4, ref5, ref6, sigil, slash, src, tagname, value, x_key, x_sys_key, xnl;
if (isa.text(d)) {
return this._html_from_datom((this.text(d))[0]);
}
/* TAINT ??? */ DATOM.types.validate.datom_datom(d);
atxt = '';
sigil = d.$key[0];
tagname = d.$key.slice(1);
is_empty_tag = isa._intertext_html_empty_element_tagname(tagname);
x_key = null;
is_block_tag = (ref2 = d.$blk) != null ? ref2 : false;
if (settings.newlines) {
bnl = is_block_tag ? '\n\n' : '';
xnl = '\n';
} else {
bnl = '';
xnl = '';
}
//.........................................................................................................
/* TAINT simplistic solution; namespace might already be taken? */
if (indexOf.call('[~]', sigil) >= 0) {
switch (sigil) {
case '[':
sigil = '<';
break;
case '~':
sigil = '^';
break;
case ']':
sigil = '>';
}
[x_key, tagname] = [tagname, 'x-sys'];
}
if ((sigil === '^') && (tagname === 'text')) {
//.........................................................................................................
return this._escape_text((ref3 = d.text) != null ? ref3 : '');
}
if ((sigil === '^') && (tagname === 'raw')) {
return (ref4 = d.text) != null ? ref4 : '';
}
if ((sigil === '^') && (tagname === 'doctype')) {
return `<!DOCTYPE ${(ref5 = d.$value) != null ? ref5 : 'html'}>${xnl}`;
}
if (sigil === '>') {
return `</${tagname}>${bnl}`;
}
//.........................................................................................................
/* NOTE sorting atxt by keys to make result predictable: */
if (isa.object(d.$value)) {
src = d.$value;
} else {
src = d;
}
if (x_key != null) {
atxt += ` x-key=${this._as_attribute_literal(x_key)}`;
}
ref6 = (Object.keys(src)).sort();
for (i = 0, len = ref6.length; i < len; i++) {
key = ref6[i];
if (key.startsWith('$')) {
continue;
}
if ((value = src[key]) === true) {
atxt += ` ${key}`;
} else {
atxt += ` ${key}=${this._as_attribute_literal(value)}`;
}
}
//.........................................................................................................
/* TAINT make self-closing elements configurable, depend on HTML5 type */
slash = (sigil === '<') || is_empty_tag ? '' : `</${tagname}>${bnl}`;
x_sys_key = x_key != null ? `<x-sys-key>${x_key}</x-sys-key>` : '';
if (atxt === '') {
return `<${tagname}>${slash}${x_sys_key}`;
}
return `<${tagname}${atxt}>${x_sys_key}${slash}`;
};
//###########################################################################################################
//###########################################################################################################
//###########################################################################################################
//###########################################################################################################
//###########################################################################################################
//###########################################################################################################
//===========================================================================================================
//-----------------------------------------------------------------------------------------------------------
this.Cupofhtml = (function() {

@@ -986,4 +1125,2 @@ class Cupofhtml extends DATOM.Cupofdatom {

super({..._defaults, ...settings});
// @tag = @constructor.get_keymethod_proxy @, tag
// @tags =
this.H = new MAIN._Tags(this);

@@ -995,2 +1132,17 @@ this.S = new MAIN._Specials(this);

//---------------------------------------------------------------------------------------------------------
expand() {
return this.last_expansion = super.expand();
}
//---------------------------------------------------------------------------------------------------------
new_tag(name, attributes) {
var f;
f = function(...P) {
return this._.tag(name, attributes, ...P);
};
this.H[name] = f.bind(this.H);
return null;
}
//---------------------------------------------------------------------------------------------------------
tag(name, ...content) {

@@ -1003,2 +1155,17 @@ if (name !== null) {

//---------------------------------------------------------------------------------------------------------
as_html() {
var d;
return ((function() {
var i, len, ref2, results;
ref2 = this.expand();
results = [];
for (i = 0, len = ref2.length; i < len; i++) {
d = ref2[i];
results.push(MAIN._html_from_datom(this.settings, d));
}
return results;
}).call(this)).join('');
}
};

@@ -1010,2 +1177,4 @@

Cupofhtml.prototype.last_expansion = null;
return Cupofhtml;

@@ -1012,0 +1181,0 @@

400

lib/html.js
(function() {
'use strict';
var CND, Cupofjoe, DATOM, alert, assign, badge, debug, echo, excluded_content_parts, freeze, help, info, is_frozen, isa, jr, lets, log, new_datom, rpr, select, thaw, type_of, types, urge, validate, warn, whisper,
indexOf = [].indexOf;
var CND, Cupofjoe, DATOM, alert, assign, badge, debug, echo, excluded_content_parts, freeze, help, info, is_frozen, isa, jr, lets, log, new_datom, rpr, select, thaw, type_of, types, urge, validate, warn, whisper;

@@ -60,273 +59,144 @@ //###########################################################################################################

//-----------------------------------------------------------------------------------------------------------
this._escape_text = function(x) {
var R;
R = x;
R = R.replace(/&/g, '&amp;');
R = R.replace(/</g, '&lt;');
R = R.replace(/>/g, '&gt;');
return R;
};
// #-----------------------------------------------------------------------------------------------------------
// @_escape_text = ( x ) ->
// R = x
// R = R.replace /&/g, '&amp;'
// R = R.replace /</g, '&lt;'
// R = R.replace />/g, '&gt;'
// return R
//-----------------------------------------------------------------------------------------------------------
this._as_attribute_literal = function(x) {
var R, must_quote;
R = isa.text(x) ? x : JSON.stringify(x);
must_quote = !isa._intertext_html_naked_attribute_text(R);
R = this._escape_text(R);
R = R.replace(/'/g, '&#39;');
R = R.replace(/\n/g, '&#10;');
if (must_quote) {
R = "'" + R + "'";
}
return R;
};
// #-----------------------------------------------------------------------------------------------------------
// @_as_attribute_literal = ( x ) ->
// R = if isa.text x then x else JSON.stringify x
// must_quote = not isa._intertext_html_naked_attribute_text R
// R = @_escape_text R
// R = R.replace /'/g, '&#39;'
// R = R.replace /\n/g, '&#10;'
// R = "'" + R + "'" if must_quote
// return R
/*
#-----------------------------------------------------------------------------------------------------------
@_parse_compact_tagname = ( compact_tagname ) ->
{ tagname
attributes } = ( compact_tagname.match /^(?<tagname>[^#.]*)(?<attributes>.*)$/ ).groups
R = {}
R.tagname = tagname unless tagname is ''
return R if attributes is ''
for attribute in attributes.split /([#.][^#.]*)/
continue if attribute is ''
avalue = attribute[ 1 .. ]
unless avalue.length > 0
throw new Error "^intertext/_parse_compact_tagname@1234^ illegal compact tag syntax in #{rpr compact_tagname}"
if attribute[ 0 ] is '#' then R.id = avalue
else ( R.class ?= [] ).push avalue
R.class = R.class.join ' ' if R.class?
return R
//-----------------------------------------------------------------------------------------------------------
this._parse_compact_tagname = function(compact_tagname) {
var R, attribute, attributes, avalue, i, len, ref, tagname;
({tagname, attributes} = (compact_tagname.match(/^(?<tagname>[^#.]*)(?<attributes>.*)$/)).groups);
R = {};
if (tagname !== '') {
R.tagname = tagname;
}
if (attributes === '') {
return R;
}
ref = attributes.split(/([#.][^#.]*)/);
for (i = 0, len = ref.length; i < len; i++) {
attribute = ref[i];
if (attribute === '') {
continue;
}
avalue = attribute.slice(1);
if (!(avalue.length > 0)) {
throw new Error(`^intertext/_parse_compact_tagname@1234^ illegal compact tag syntax in ${rpr(compact_tagname)}`);
}
if (attribute[0] === '#') {
R.id = avalue;
} else {
(R.class != null ? R.class : R.class = []).push(avalue);
}
}
if (R.class != null) {
R.class = R.class.join(' ');
}
return R;
};
#-----------------------------------------------------------------------------------------------------------
@tag = ( compact_tagname, attributes, content... ) ->
{ start, content, end, } = @_tag compact_tagname, attributes, content
return [ start, content..., end, ] if end?
return [ start, content..., ]
//-----------------------------------------------------------------------------------------------------------
this.tag = function(compact_tagname, attributes, ...content) {
var end, start;
({start, content, end} = this._tag(compact_tagname, attributes, content));
if (end != null) {
return [start, ...content, end];
}
return [start, ...content];
};
#-----------------------------------------------------------------------------------------------------------
@_tag = ( compact_tagname, attributes, content, settings ) ->
validate.nonempty_text compact_tagname
{ tagname, id, class: clasz, } = @_parse_compact_tagname compact_tagname
validate.intertext_html_tagname tagname
use_attributes = false
processed_content = []
call_functions = settings?.call_functions ? true
content = thaw content if ( Object.isFrozen content )
#.........................................................................................................
if attributes?
if isa.object attributes then use_attributes = true
else content.unshift attributes
#.........................................................................................................
if content.length is 0
sigil = '^'
end_tag = null
#.........................................................................................................
else
sigil = '<'
end_tag = new_datom ">#{tagname}"
for part in content
continue if part in excluded_content_parts
switch type_of part
when 'text' then processed_content.push new_datom '^text', { text: part, }
when 'function'
if call_functions then processed_content.push x unless ( x = part() ) in excluded_content_parts
else processed_content.push part
else processed_content.push part
#.........................................................................................................
if id? or clasz?
idclass = {}
idclass.id = id if id?
idclass.class = clasz if clasz?
if use_attributes
attributes = assign idclass, attributes
else
use_attributes = true
attributes = idclass
#.........................................................................................................
if use_attributes then start_tag = new_datom "#{sigil}#{tagname}", attributes
else start_tag = new_datom "#{sigil}#{tagname}"
#.........................................................................................................
processed_content = processed_content.flat Infinity
return { start: start_tag, content: processed_content, end: end_tag, } if end_tag?
return { start: start_tag, content: processed_content, }
*/
// #-----------------------------------------------------------------------------------------------------------
// @html_from_datoms = ( ds, settings ) -> return ( @_html_from_datom d for d in ds.flat Infinity ).join ''
//-----------------------------------------------------------------------------------------------------------
this._tag = function(compact_tagname, attributes, content, settings) {
var call_functions, clasz, end_tag, i, id, idclass, len, part, processed_content, ref, ref1, sigil, start_tag, tagname, use_attributes, x;
validate.nonempty_text(compact_tagname);
({
tagname,
id,
class: clasz
} = this._parse_compact_tagname(compact_tagname));
validate.intertext_html_tagname(tagname);
use_attributes = false;
processed_content = [];
call_functions = (ref = settings != null ? settings.call_functions : void 0) != null ? ref : true;
if (Object.isFrozen(content)) {
content = thaw(content);
}
//.........................................................................................................
if (attributes != null) {
if (isa.object(attributes)) {
use_attributes = true;
} else {
content.unshift(attributes);
}
}
//.........................................................................................................
if (content.length === 0) {
sigil = '^';
end_tag = null;
} else {
//.........................................................................................................
sigil = '<';
end_tag = new_datom(`>${tagname}`);
for (i = 0, len = content.length; i < len; i++) {
part = content[i];
if (indexOf.call(excluded_content_parts, part) >= 0) {
continue;
}
switch (type_of(part)) {
case 'text':
processed_content.push(new_datom('^text', {
text: part
}));
break;
case 'function':
if (call_functions) {
if (ref1 = (x = part()), indexOf.call(excluded_content_parts, ref1) < 0) {
processed_content.push(x);
}
} else {
processed_content.push(part);
}
break;
default:
processed_content.push(part);
}
}
}
//.........................................................................................................
if ((id != null) || (clasz != null)) {
idclass = {};
if (id != null) {
idclass.id = id;
}
if (clasz != null) {
idclass.class = clasz;
}
if (use_attributes) {
attributes = assign(idclass, attributes);
} else {
use_attributes = true;
attributes = idclass;
}
}
//.........................................................................................................
if (use_attributes) {
start_tag = new_datom(`${sigil}${tagname}`, attributes);
} else {
start_tag = new_datom(`${sigil}${tagname}`);
}
//.........................................................................................................
processed_content = processed_content.flat(2e308);
if (end_tag != null) {
return {
start: start_tag,
content: processed_content,
end: end_tag
};
}
return {
start: start_tag,
content: processed_content
};
};
// #-----------------------------------------------------------------------------------------------------------
// @$html_from_datoms = ->
// { $, } = ( require 'steampipes' ).export()
// return $ ( d, send ) =>
// return send @_html_from_datom d unless isa.list d
// send x for x in @html_from_datoms d...
// return null
//-----------------------------------------------------------------------------------------------------------
this.html_from_datoms = function(...ds) {
var d;
return ((function() {
var i, len, ref, results;
ref = ds.flat(2e308);
results = [];
for (i = 0, len = ref.length; i < len; i++) {
d = ref[i];
results.push(this._html_from_datom(d));
}
return results;
}).call(this)).join('');
};
// #-----------------------------------------------------------------------------------------------------------
// @_html_from_datom = ( d ) ->
// return @_html_from_datom ( @text d )[ 0 ] if isa.text d ### TAINT ??? ###
// DATOM.types.validate.datom_datom d
// atxt = ''
// sigil = d.$key[ 0 ]
// tagname = d.$key[ 1 .. ]
// is_empty_tag = isa._intertext_html_empty_element_tagname tagname
// x_key = null
// is_block_tag = d.$blk ? false
// bnl = if is_block_tag then '\n\n' else '' ### TAINT make configurable ###
// xnl = '\n' ### TAINT make configurable ###
// #.........................................................................................................
// ### TAINT simplistic solution; namespace might already be taken? ###
// if sigil in '[~]'
// switch sigil
// when '[' then sigil = '<'
// when '~' then sigil = '^'
// when ']' then sigil = '>'
// [ x_key, tagname, ] = [ tagname, 'x-sys', ]
// #.........................................................................................................
// return ( @_escape_text d.text ? '' ) if ( sigil is '^' ) and ( tagname is 'text' )
// return ( d.text ? '' ) if ( sigil is '^' ) and ( tagname is 'raw' )
// return "<!DOCTYPE #{d.$value ? 'html'}>#{xnl}" if ( sigil is '^' ) and ( tagname is 'doctype' )
// return "</#{tagname}>#{bnl}" if sigil is '>'
// #.........................................................................................................
// ### NOTE sorting atxt by keys to make result predictable: ###
// if isa.object d.$value then src = d.$value
// else src = d
// atxt += " x-key=#{@_as_attribute_literal x_key}" if x_key?
// for key in ( Object.keys src ).sort()
// continue if key.startsWith '$'
// if ( value = src[ key ] ) is true then atxt += " #{key}"
// else atxt += " #{key}=#{@_as_attribute_literal value}"
// #.........................................................................................................
// ### TAINT make self-closing elements configurable, depend on HTML5 type ###
// slash = if ( sigil is '<' ) or is_empty_tag then '' else "</#{tagname}>#{bnl}"
// x_sys_key = if x_key? then "<x-sys-key>#{x_key}</x-sys-key>" else ''
// return "<#{tagname}>#{slash}#{x_sys_key}" if atxt is ''
// return "<#{tagname}#{atxt}>#{x_sys_key}#{slash}"
//-----------------------------------------------------------------------------------------------------------
this.$html_from_datoms = function() {
var $;
({$} = (require('steampipes')).export());
return $((d, send) => {
var i, len, ref, x;
if (!isa.list(d)) {
return send(this._html_from_datom(d));
}
ref = this.html_from_datoms(...d);
for (i = 0, len = ref.length; i < len; i++) {
x = ref[i];
send(x);
}
return null;
});
};
//-----------------------------------------------------------------------------------------------------------
this._html_from_datom = function(d) {
var atxt, bnl, i, is_block_tag, is_empty_tag, key, len, ref, ref1, ref2, ref3, ref4, sigil, slash, src, tagname, value, x_key, x_sys_key, xnl;
if (isa.text(d)) {
return this._html_from_datom((this.text(d))[0]);
}
/* TAINT ??? */ DATOM.types.validate.datom_datom(d);
atxt = '';
sigil = d.$key[0];
tagname = d.$key.slice(1);
is_empty_tag = isa._intertext_html_empty_element_tagname(tagname);
x_key = null;
is_block_tag = (ref = d.$blk) != null ? ref : false;
bnl = is_block_tag ? '\n\n' : ''/* TAINT make configurable */
xnl = '\n'/* TAINT make configurable */
//.........................................................................................................
/* TAINT simplistic solution; namespace might already be taken? */
if (indexOf.call('[~]', sigil) >= 0) {
switch (sigil) {
case '[':
sigil = '<';
break;
case '~':
sigil = '^';
break;
case ']':
sigil = '>';
}
[x_key, tagname] = [tagname, 'x-sys'];
}
if ((sigil === '^') && (tagname === 'text')) {
//.........................................................................................................
return this._escape_text((ref1 = d.text) != null ? ref1 : '');
}
if ((sigil === '^') && (tagname === 'raw')) {
return (ref2 = d.text) != null ? ref2 : '';
}
if ((sigil === '^') && (tagname === 'doctype')) {
return `<!DOCTYPE ${(ref3 = d.$value) != null ? ref3 : 'html'}>${xnl}`;
}
if (sigil === '>') {
return `</${tagname}>${bnl}`;
}
//.........................................................................................................
/* NOTE sorting atxt by keys to make result predictable: */
if (isa.object(d.$value)) {
src = d.$value;
} else {
src = d;
}
if (x_key != null) {
atxt += ` x-key=${this._as_attribute_literal(x_key)}`;
}
ref4 = (Object.keys(src)).sort();
for (i = 0, len = ref4.length; i < len; i++) {
key = ref4[i];
if (key.startsWith('$')) {
continue;
}
if ((value = src[key]) === true) {
atxt += ` ${key}`;
} else {
atxt += ` ${key}=${this._as_attribute_literal(value)}`;
}
}
//.........................................................................................................
/* TAINT make self-closing elements configurable, depend on HTML5 type */
slash = (sigil === '<') || is_empty_tag ? '' : `</${tagname}>${bnl}`;
x_sys_key = x_key != null ? `<x-sys-key>${x_key}</x-sys-key>` : '';
if (atxt === '') {
return `<${tagname}>${slash}${x_sys_key}`;
}
return `<${tagname}${atxt}>${x_sys_key}${slash}`;
};
}).call(this);
//# sourceMappingURL=html.js.map
{
"name": "intertext",
"version": "3.0.0",
"version": "4.0.0",
"description": "Services for Recurrent Text-related Tasks",

@@ -35,3 +35,3 @@ "main": "lib/main.js",

"cupofjoe": "^0.1.1",
"datom": "^7.0.0",
"datom": "^7.0.1",
"hyphenopoly": "^4.5.0",

@@ -38,0 +38,0 @@ "intertype": "^7.0.2",

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