twing
Version:
First-class Twig engine for Node.js
36 lines (35 loc) • 1.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createMarkup = exports.isAMarkup = void 0;
const iconv_1 = require("./helpers/iconv");
const isAMarkup = (candidate) => {
return candidate !== null
&& candidate !== undefined
&& candidate.charset !== undefined
&& candidate.content !== undefined
&& candidate.count !== undefined // todo: we should not test getter values but actual property existence
&& candidate.toJSON !== undefined
&& candidate.toString !== undefined;
};
exports.isAMarkup = isAMarkup;
const createMarkup = (content, charset = 'UTF-8') => {
return {
get content() {
return content;
},
get charset() {
return charset;
},
get count() {
const contentAsString = (0, iconv_1.iconv)(charset, 'utf-8', Buffer.from(content)).toString();
return contentAsString.length;
},
toString() {
return content.toString();
},
toJSON() {
return content.toString();
}
};
};
exports.createMarkup = createMarkup;