UNPKG

nornj

Version:

A powerful template engine that can works with React, JSX enhancement or alternative tools.

336 lines (261 loc) 8.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.arrayPush = arrayPush; exports.arraySlice = arraySlice; exports.isArray = isArray; exports.isObject = isObject; exports.isArrayLike = isArrayLike; exports.each = each; exports.trimRight = trimRight; exports.noop = noop; exports.throwIf = throwIf; exports.warn = warn; exports.error = error; exports.obj = obj; exports.clearQuot = clearQuot; exports.camelCase = camelCase; exports.upperFirst = upperFirst; exports.lowerFirst = lowerFirst; exports.capitalize = capitalize; exports.as = as; exports.assign = exports.isWeakSet = exports.isSet = exports.isWeakMap = exports.isMap = exports.isString = exports.isNumber = exports.defineProps = exports.defineProp = void 0; var _core = _interopRequireDefault(require("../core")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } var nativeArrayPush = Array.prototype.push, nativeArraySlice = Array.prototype.slice, hasOwnProperty = Object.prototype.hasOwnProperty, toString = Object.prototype.toString; var errorTitle = _core["default"].errorTitle; var defineProp = Object.defineProperty; exports.defineProp = defineProp; var defineProps = Object.defineProperties; // Internal function for creating a toString-based type tester. exports.defineProps = defineProps; function _tagTester(name) { return function (obj) { return toString.call(obj) === '[object ' + name + ']'; }; } //Reference by underscore var isNumber = _tagTester('Number'); exports.isNumber = isNumber; var isString = _tagTester('String'); exports.isString = isString; var isMap = _tagTester('Map'); exports.isMap = isMap; var isWeakMap = _tagTester('WeakMap'); exports.isWeakMap = isWeakMap; var isSet = _tagTester('Set'); exports.isSet = isSet; var isWeakSet = _tagTester('WeakSet'); //Push one by one to array exports.isWeakSet = isWeakSet; function arrayPush(arr1, arr2) { nativeArrayPush.apply(arr1, arr2); return arr1; } function arraySlice(arrLike, start, end) { return nativeArraySlice.call(arrLike, start, end); } function isArray(obj) { return Array.isArray(obj); } function isObject(obj) { var type = _typeof(obj); return !isArray(obj) && (type === 'function' || type === 'object' && !!obj); } function _getProperty(key) { return function (obj) { return obj == null ? void 0 : obj[key]; }; } var _getLength = _getProperty('length'); function isArrayLike(obj) { var length = _getLength(obj); return typeof length == 'number' && length >= 0; } function _iteratorLoop(obj, func, isMap) { var size = obj.size; var i = 0; var _iteratorNormalCompletion = true; var _didIteratorError = false; var _iteratorError = undefined; try { for (var _iterator = obj[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { var item = _step.value; var ret = void 0; if (isMap) { var _item = _slicedToArray(item, 2), k = _item[0], v = _item[1]; ret = func.call(obj, v, k, i, size); } else { ret = func.call(obj, item, i, size); } if (ret === false) { break; } i++; } } catch (err) { _didIteratorError = true; _iteratorError = err; } finally { try { if (!_iteratorNormalCompletion && _iterator["return"] != null) { _iterator["return"](); } } finally { if (_didIteratorError) { throw _iteratorError; } } } } function each(obj, func, isArr) { if (!obj) { return; } if (isArr == null) { isArr = isArrayLike(obj); } if (isArr) { for (var i = 0, l = obj.length; i < l; i++) { var ret = func.call(obj, obj[i], i, l); if (ret === false) { break; } } } else if (isSet(obj) || isWeakSet(obj)) { _iteratorLoop(obj, func); } else if (isMap(obj) || isWeakMap(obj)) { _iteratorLoop(obj, func, true); } else { var keys = Object.keys(obj), _l = keys.length; for (var _i2 = 0; _i2 < _l; _i2++) { var k = keys[_i2], _ret = func.call(obj, obj[k], k, _i2, _l); if (_ret === false) { break; } } } } var REGEX_TRIM_RIGHT = /(\n|\r)?[\s\xA0]+$/; function trimRight(str) { return str.replace(REGEX_TRIM_RIGHT, function (all, s1) { return s1 ? '\n' : ''; }); } function noop() {} function throwIf(val, msg, type) { if (!val) { switch (type) { case 'ex': throw Error(errorTitle + 'Extension tag "' + msg + '" is undefined, please check it has been registered.'); default: throw Error(errorTitle + (msg || val)); } } } function warn(msg, type) { switch (type) { case 'f': msg = 'A filter called "' + msg + '" is undefined.'; break; } console.warn(errorTitle + msg); } function error(msg) { console.error(errorTitle + msg); } //create light weight object function obj() { return Object.create(null); } var REGEX_QUOT_D = /["]+/g, REGEX_QUOT_S = /[']+/g; function clearQuot(value, clearDouble) { if (value == null) { return; } var regex; if (clearDouble == null) { var charF = value[0]; if (charF === "'") { regex = REGEX_QUOT_S; } else if (charF === '"') { regex = REGEX_QUOT_D; } } else if (clearDouble) { regex = REGEX_QUOT_D; } else { regex = REGEX_QUOT_S; } if (regex) { value = value.replace(regex, ''); } return value; } function camelCase(str) { if (str.indexOf('-') > -1) { str = str.replace(/-\w/g, function (letter) { return letter.substr(1).toUpperCase(); }); } return str; } //Reference by babel-external-helpers var assign = Object.assign || function (target) { for (var i = 1, args = arguments; i < args.length; i++) { var source = args[i]; for (var key in source) { if (hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; exports.assign = assign; function upperFirst(str) { return str[0].toUpperCase() + str.substr(1); } function lowerFirst(str) { return str[0].toLowerCase() + str.substr(1); } function capitalize(str) { return upperFirst(str); } function as(value) { return value; } assign(_core["default"], { defineProp: defineProp, defineProps: defineProps, arrayPush: arrayPush, arraySlice: arraySlice, isArray: isArray, isObject: isObject, isNumber: isNumber, isString: isString, isArrayLike: isArrayLike, isMap: isMap, isWeakMap: isWeakMap, isSet: isSet, isWeakSet: isWeakSet, each: each, noop: noop, throwIf: throwIf, warn: warn, obj: obj, camelCase: camelCase, assign: assign, upperFirst: upperFirst, lowerFirst: lowerFirst, capitalize: capitalize, as: as });