UNPKG

@alicd/templateparser

Version:

walle template parser

65 lines (50 loc) 5.79 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /** * @license * Copyright Alibaba Group and its affiliates. All Rights Reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var _config = require('../config'); var _config2 = _interopRequireDefault(_config); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } // output type reg. var outputTag = new RegExp('^\\' + _config2.default.expressStartTag + '(.+?)\\' + _config2.default.expressEndTag + '$'); var jsonTag = new RegExp('^\\{(.+?)\\}$'); var spreadAttribute = _config2.default.spreadAttribute; var Express = function () { function Express() { _classCallCheck(this, Express); } _createClass(Express, [{ key: 'test', value: function test() { var str = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; var isOutput = outputTag.test(str); var isExpress = jsonTag.test(str); var isSpreadAttribute = spreadAttribute.test(str); return isOutput || isExpress || isSpreadAttribute; } }, { key: 'filter', value: function filter() { var str = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; if (str.match(spreadAttribute)) { return str.match(spreadAttribute)[1]; } else if (str.match(outputTag)) { return str.match(outputTag)[1]; } else if (str.match(jsonTag)) { return str.match(jsonTag)[1]; } else { return str; } } }]); return Express; }(); exports.default = new Express();