tequery
Version:
text transform query
43 lines • 1.31 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAttrsStr = exports.attrKeys = void 0;
const funcs_1 = require("../locals/funcs");
const suggests = [
{
key: 'multiline',
check: ({ lines }) => lines.length > 1,
},
{
key: 'csvLike',
check: ({ line1 }) => (0, funcs_1.count)(line1 !== null && line1 !== void 0 ? line1 : '', ',') >= 2,
},
{
key: 'tsvLike',
check: ({ line1 }) => (0, funcs_1.count)(line1 !== null && line1 !== void 0 ? line1 : '', '\t') >= 2,
},
{
key: 'cellLike',
check: ({ line1 }) => (0, funcs_1.count)(line1 !== null && line1 !== void 0 ? line1 : '', /[\t,. -]/g) >= 3,
},
];
exports.attrKeys = suggests.map((v) => v.key);
const initialAttrs = {
multiline: false,
csvLike: false,
tsvLike: false,
cellLike: false,
};
const getAttrsStr = (text) => {
var _a;
const attrs = initialAttrs;
if (typeof text !== 'string')
return attrs;
const lines = text.split('\n');
const line1 = (_a = lines[0]) !== null && _a !== void 0 ? _a : null;
suggests.forEach((s) => {
attrs[s.key] = s.check({ text, line1, lines });
});
return attrs;
};
exports.getAttrsStr = getAttrsStr;
//# sourceMappingURL=attrs.js.map
;