melody-runtime
Advanced tools
Comparing version 1.2.0-commit.39a4cc79 to 1.2.0-commit.3de5e8de
@@ -762,2 +762,33 @@ import _isString from 'lodash/isString'; | ||
function trim(str, charList) { | ||
var side = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'both'; | ||
if (charList === undefined && side === 'both') { | ||
// Use String.prototype.trim() for efficiency | ||
return String(str).trim(); | ||
} | ||
if (side !== 'both' && side !== 'left' && side !== 'right') { | ||
throw new Error('Filter "trim". Invalid value ' + side + ' for parameter "side". Valid values are "both", "left", "right".'); | ||
} | ||
var strLen = str.length; | ||
var trimStart = 0; | ||
if (side === 'both' || side === 'left') { | ||
while (trimStart < strLen && charList.indexOf(str[trimStart]) !== -1) { | ||
trimStart++; | ||
} | ||
} | ||
var trimEnd = strLen; | ||
if (side === 'both' || side === 'right') { | ||
while (trimEnd > 0 && charList.indexOf(str[trimEnd - 1]) !== -1) { | ||
trimEnd--; | ||
} | ||
} | ||
return str.substr(trimStart, trimEnd - trimStart); | ||
} | ||
var MAX_SAFE_INTEGER = 'MAX_SAFE_INTEGER' in Number ? Number.MAX_SAFE_INTEGER : 9007199254740991; | ||
@@ -879,2 +910,2 @@ | ||
export { createSubContext, batch, attrs, styles, classes, merge, replace, reverse, round, striptags, number_format, format, title, url_encode, strtotime, random, min, max, cycle, attribute, isEmpty, inheritBlocks }; | ||
export { createSubContext, batch, attrs, styles, classes, merge, replace, reverse, round, striptags, number_format, format, title, url_encode, strtotime, trim, random, min, max, cycle, attribute, isEmpty, inheritBlocks }; |
@@ -768,2 +768,33 @@ 'use strict'; | ||
function trim(str, charList) { | ||
var side = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'both'; | ||
if (charList === undefined && side === 'both') { | ||
// Use String.prototype.trim() for efficiency | ||
return String(str).trim(); | ||
} | ||
if (side !== 'both' && side !== 'left' && side !== 'right') { | ||
throw new Error('Filter "trim". Invalid value ' + side + ' for parameter "side". Valid values are "both", "left", "right".'); | ||
} | ||
var strLen = str.length; | ||
var trimStart = 0; | ||
if (side === 'both' || side === 'left') { | ||
while (trimStart < strLen && charList.indexOf(str[trimStart]) !== -1) { | ||
trimStart++; | ||
} | ||
} | ||
var trimEnd = strLen; | ||
if (side === 'both' || side === 'right') { | ||
while (trimEnd > 0 && charList.indexOf(str[trimEnd - 1]) !== -1) { | ||
trimEnd--; | ||
} | ||
} | ||
return str.substr(trimStart, trimEnd - trimStart); | ||
} | ||
var MAX_SAFE_INTEGER = 'MAX_SAFE_INTEGER' in Number ? Number.MAX_SAFE_INTEGER : 9007199254740991; | ||
@@ -900,2 +931,3 @@ | ||
exports.strtotime = strtotime; | ||
exports.trim = trim; | ||
exports.random = random; | ||
@@ -902,0 +934,0 @@ exports.min = min; |
{ | ||
"name": "melody-runtime", | ||
"version": "1.2.0-commit.39a4cc79", | ||
"version": "1.2.0-commit.3de5e8de", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -964,1 +964,34 @@ /** | ||
} | ||
export function trim(str, charList, side = 'both') { | ||
if (charList === undefined && side === 'both') { | ||
// Use String.prototype.trim() for efficiency | ||
return String(str).trim(); | ||
} | ||
if (side !== 'both' && side !== 'left' && side !== 'right') { | ||
throw new Error( | ||
'Filter "trim". Invalid value ' + | ||
side + | ||
' for parameter "side". Valid values are "both", "left", "right".' | ||
); | ||
} | ||
const strLen = str.length; | ||
let trimStart = 0; | ||
if (side === 'both' || side === 'left') { | ||
while (trimStart < strLen && charList.indexOf(str[trimStart]) !== -1) { | ||
trimStart++; | ||
} | ||
} | ||
let trimEnd = strLen; | ||
if (side === 'both' || side === 'right') { | ||
while (trimEnd > 0 && charList.indexOf(str[trimEnd - 1]) !== -1) { | ||
trimEnd--; | ||
} | ||
} | ||
return str.substr(trimStart, trimEnd - trimStart); | ||
} |
@@ -32,4 +32,5 @@ /** | ||
strtotime, | ||
trim, | ||
} from './filters'; | ||
export { random, min, max, cycle, attribute } from './functions'; | ||
export { isEmpty, inheritBlocks } from './helpers'; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
104042
2763