mirror of
https://github.com/fooflington/selfdefined.git
synced 2025-12-14 16:29:04 +00:00
update
This commit is contained in:
8
node_modules/liquidjs/src/util/assert.js
generated
vendored
Normal file
8
node_modules/liquidjs/src/util/assert.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { AssertionError } from './error.js'
|
||||
|
||||
export default function (predicate, message) {
|
||||
if (!predicate) {
|
||||
message = message || `expect ${predicate} to be true`
|
||||
throw new AssertionError(message)
|
||||
}
|
||||
}
|
||||
100
node_modules/liquidjs/src/util/error.js
generated
vendored
Normal file
100
node_modules/liquidjs/src/util/error.js
generated
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
import * as _ from './underscore.js'
|
||||
|
||||
function initError () {
|
||||
this.name = this.constructor.name
|
||||
if (Error.captureStackTrace) {
|
||||
Error.captureStackTrace(this, this.constructor)
|
||||
}
|
||||
}
|
||||
|
||||
function initLiquidError (err, token) {
|
||||
initError.call(this)
|
||||
|
||||
this.input = token.input
|
||||
this.line = token.line
|
||||
this.file = token.file
|
||||
|
||||
const context = mkContext(token.input, token.line)
|
||||
this.message = mkMessage(err.message, token)
|
||||
this.stack = context +
|
||||
'\n' + (this.stack || this.message) +
|
||||
(err.stack ? '\nFrom ' + err.stack : '')
|
||||
}
|
||||
|
||||
export function TokenizationError (message, token) {
|
||||
initLiquidError.call(this, { message: message }, token)
|
||||
}
|
||||
TokenizationError.prototype = _.create(Error.prototype)
|
||||
TokenizationError.prototype.constructor = TokenizationError
|
||||
|
||||
export function ParseError (e, token) {
|
||||
_.assign(this, e)
|
||||
this.originalError = e
|
||||
|
||||
initLiquidError.call(this, e, token)
|
||||
}
|
||||
ParseError.prototype = _.create(Error.prototype)
|
||||
ParseError.prototype.constructor = ParseError
|
||||
|
||||
export function RenderError (e, tpl) {
|
||||
// return the original render error
|
||||
if (e instanceof RenderError) {
|
||||
return e
|
||||
}
|
||||
_.assign(this, e)
|
||||
this.originalError = e
|
||||
|
||||
initLiquidError.call(this, e, tpl.token)
|
||||
}
|
||||
RenderError.prototype = _.create(Error.prototype)
|
||||
RenderError.prototype.constructor = RenderError
|
||||
|
||||
export function RenderBreakError (message) {
|
||||
initError.call(this)
|
||||
this.message = message + ''
|
||||
}
|
||||
RenderBreakError.prototype = _.create(Error.prototype)
|
||||
RenderBreakError.prototype.constructor = RenderBreakError
|
||||
|
||||
export function AssertionError (message) {
|
||||
initError.call(this)
|
||||
this.message = message + ''
|
||||
}
|
||||
AssertionError.prototype = _.create(Error.prototype)
|
||||
AssertionError.prototype.constructor = AssertionError
|
||||
|
||||
function mkContext (input, line) {
|
||||
const lines = input.split('\n')
|
||||
const begin = Math.max(line - 2, 1)
|
||||
const end = Math.min(line + 3, lines.length)
|
||||
|
||||
const context = _
|
||||
.range(begin, end + 1)
|
||||
.map(l => [
|
||||
(l === line) ? '>> ' : ' ',
|
||||
align(l, end),
|
||||
'| ',
|
||||
lines[l - 1]
|
||||
].join(''))
|
||||
.join('\n')
|
||||
|
||||
return context
|
||||
}
|
||||
|
||||
function align (n, max) {
|
||||
const length = (max + '').length
|
||||
const str = n + ''
|
||||
const blank = Array(length - str.length).join(' ')
|
||||
return blank + str
|
||||
}
|
||||
|
||||
function mkMessage (msg, token) {
|
||||
msg = msg || ''
|
||||
if (token.file) {
|
||||
msg += ', file:' + token.file
|
||||
}
|
||||
if (token.line) {
|
||||
msg += ', line:' + token.line
|
||||
}
|
||||
return msg
|
||||
}
|
||||
30
node_modules/liquidjs/src/util/promise.js
generated
vendored
Normal file
30
node_modules/liquidjs/src/util/promise.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Call functions in serial until someone resolved.
|
||||
* @param {Array} iterable the array to iterate with.
|
||||
* @param {Array} iteratee returns a new promise.
|
||||
* The iteratee is invoked with three arguments: (value, index, iterable).
|
||||
*/
|
||||
export function anySeries (iterable, iteratee) {
|
||||
let ret = Promise.reject(new Error('init'))
|
||||
iterable.forEach(function (item, idx) {
|
||||
ret = ret.catch(e => iteratee(item, idx, iterable))
|
||||
})
|
||||
return ret
|
||||
}
|
||||
|
||||
/*
|
||||
* Call functions in serial until someone rejected.
|
||||
* @param {Array} iterable the array to iterate with.
|
||||
* @param {Array} iteratee returns a new promise.
|
||||
* The iteratee is invoked with three arguments: (value, index, iterable).
|
||||
*/
|
||||
export function mapSeries (iterable, iteratee) {
|
||||
let ret = Promise.resolve('init')
|
||||
const result = []
|
||||
iterable.forEach(function (item, idx) {
|
||||
ret = ret
|
||||
.then(() => iteratee(item, idx, iterable))
|
||||
.then(x => result.push(x))
|
||||
})
|
||||
return ret.then(() => result)
|
||||
}
|
||||
198
node_modules/liquidjs/src/util/strftime.js
generated
vendored
Normal file
198
node_modules/liquidjs/src/util/strftime.js
generated
vendored
Normal file
@@ -0,0 +1,198 @@
|
||||
const monthNames = [
|
||||
'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August',
|
||||
'September', 'October', 'November', 'December'
|
||||
]
|
||||
const dayNames = [
|
||||
'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'
|
||||
]
|
||||
const monthNamesShort = monthNames.map(abbr)
|
||||
const dayNamesShort = dayNames.map(abbr)
|
||||
const suffixes = {
|
||||
1: 'st',
|
||||
2: 'nd',
|
||||
3: 'rd',
|
||||
'default': 'th'
|
||||
}
|
||||
|
||||
function abbr (str) {
|
||||
return str.slice(0, 3)
|
||||
}
|
||||
|
||||
// prototype extensions
|
||||
const _date = {
|
||||
daysInMonth: function (d) {
|
||||
const feb = _date.isLeapYear(d) ? 29 : 28
|
||||
return [31, feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
||||
},
|
||||
|
||||
getDayOfYear: function (d) {
|
||||
let num = 0
|
||||
for (let i = 0; i < d.getMonth(); ++i) {
|
||||
num += _date.daysInMonth(d)[i]
|
||||
}
|
||||
return num + d.getDate()
|
||||
},
|
||||
|
||||
// Startday is an integer of which day to start the week measuring from
|
||||
// TODO: that comment was retarted. fix it.
|
||||
getWeekOfYear: function (d, startDay) {
|
||||
// Skip to startDay of this week
|
||||
const now = this.getDayOfYear(d) + (startDay - d.getDay())
|
||||
// Find the first startDay of the year
|
||||
const jan1 = new Date(d.getFullYear(), 0, 1)
|
||||
const then = (7 - jan1.getDay() + startDay)
|
||||
return _number.pad(Math.floor((now - then) / 7) + 1, 2)
|
||||
},
|
||||
|
||||
isLeapYear: function (d) {
|
||||
const year = d.getFullYear()
|
||||
return !!((year & 3) === 0 && (year % 100 || (year % 400 === 0 && year)))
|
||||
},
|
||||
|
||||
getSuffix: function (d) {
|
||||
const str = d.getDate().toString()
|
||||
const index = parseInt(str.slice(-1))
|
||||
return suffixes[index] || suffixes['default']
|
||||
},
|
||||
|
||||
century: function (d) {
|
||||
return parseInt(d.getFullYear().toString().substring(0, 2), 10)
|
||||
}
|
||||
}
|
||||
|
||||
const _number = {
|
||||
pad: function (value, size, ch) {
|
||||
if (!ch) ch = '0'
|
||||
let result = value.toString()
|
||||
let pad = size - result.length
|
||||
|
||||
while (pad-- > 0) {
|
||||
result = ch + result
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
const formatCodes = {
|
||||
a: function (d) {
|
||||
return dayNamesShort[d.getDay()]
|
||||
},
|
||||
A: function (d) {
|
||||
return dayNames[d.getDay()]
|
||||
},
|
||||
b: function (d) {
|
||||
return monthNamesShort[d.getMonth()]
|
||||
},
|
||||
B: function (d) {
|
||||
return monthNames[d.getMonth()]
|
||||
},
|
||||
c: function (d) {
|
||||
return d.toLocaleString()
|
||||
},
|
||||
C: function (d) {
|
||||
return _date.century(d)
|
||||
},
|
||||
d: function (d) {
|
||||
return _number.pad(d.getDate(), 2)
|
||||
},
|
||||
e: function (d) {
|
||||
return _number.pad(d.getDate(), 2, ' ')
|
||||
},
|
||||
H: function (d) {
|
||||
return _number.pad(d.getHours(), 2)
|
||||
},
|
||||
I: function (d) {
|
||||
return _number.pad(d.getHours() % 12 || 12, 2)
|
||||
},
|
||||
j: function (d) {
|
||||
return _number.pad(_date.getDayOfYear(d), 3)
|
||||
},
|
||||
k: function (d) {
|
||||
return _number.pad(d.getHours(), 2, ' ')
|
||||
},
|
||||
l: function (d) {
|
||||
return _number.pad(d.getHours() % 12 || 12, 2, ' ')
|
||||
},
|
||||
L: function (d) {
|
||||
return _number.pad(d.getMilliseconds(), 3)
|
||||
},
|
||||
m: function (d) {
|
||||
return _number.pad(d.getMonth() + 1, 2)
|
||||
},
|
||||
M: function (d) {
|
||||
return _number.pad(d.getMinutes(), 2)
|
||||
},
|
||||
p: function (d) {
|
||||
return (d.getHours() < 12 ? 'AM' : 'PM')
|
||||
},
|
||||
P: function (d) {
|
||||
return (d.getHours() < 12 ? 'am' : 'pm')
|
||||
},
|
||||
q: function (d) {
|
||||
return _date.getSuffix(d)
|
||||
},
|
||||
s: function (d) {
|
||||
return Math.round(d.valueOf() / 1000)
|
||||
},
|
||||
S: function (d) {
|
||||
return _number.pad(d.getSeconds(), 2)
|
||||
},
|
||||
u: function (d) {
|
||||
return d.getDay() || 7
|
||||
},
|
||||
U: function (d) {
|
||||
return _date.getWeekOfYear(d, 0)
|
||||
},
|
||||
w: function (d) {
|
||||
return d.getDay()
|
||||
},
|
||||
W: function (d) {
|
||||
return _date.getWeekOfYear(d, 1)
|
||||
},
|
||||
x: function (d) {
|
||||
return d.toLocaleDateString()
|
||||
},
|
||||
X: function (d) {
|
||||
return d.toLocaleTimeString()
|
||||
},
|
||||
y: function (d) {
|
||||
return d.getFullYear().toString().substring(2, 4)
|
||||
},
|
||||
Y: function (d) {
|
||||
return d.getFullYear()
|
||||
},
|
||||
z: function (d) {
|
||||
const tz = d.getTimezoneOffset() / 60 * 100
|
||||
return (tz > 0 ? '-' : '+') + _number.pad(Math.abs(tz), 4)
|
||||
},
|
||||
'%': function () {
|
||||
return '%'
|
||||
}
|
||||
}
|
||||
formatCodes.h = formatCodes.b
|
||||
formatCodes.N = formatCodes.L
|
||||
|
||||
export default function (d, format) {
|
||||
let output = ''
|
||||
let remaining = format
|
||||
|
||||
while (true) {
|
||||
const r = /%./g
|
||||
const results = r.exec(remaining)
|
||||
|
||||
// No more format codes. Add the remaining text and return
|
||||
if (!results) {
|
||||
return output + remaining
|
||||
}
|
||||
|
||||
// Add the preceding text
|
||||
output += remaining.slice(0, r.lastIndex - 2)
|
||||
remaining = remaining.slice(r.lastIndex)
|
||||
|
||||
// Add the format code
|
||||
const ch = results[0].charAt(1)
|
||||
const func = formatCodes[ch]
|
||||
output += func ? func.call(this, d) : '%' + ch
|
||||
}
|
||||
}
|
||||
154
node_modules/liquidjs/src/util/underscore.js
generated
vendored
Normal file
154
node_modules/liquidjs/src/util/underscore.js
generated
vendored
Normal file
@@ -0,0 +1,154 @@
|
||||
const toStr = Object.prototype.toString
|
||||
const arrToStr = Array.prototype.toString
|
||||
|
||||
/*
|
||||
* Checks if value is classified as a String primitive or object.
|
||||
* @param {any} value The value to check.
|
||||
* @return {Boolean} Returns true if value is a string, else false.
|
||||
*/
|
||||
export function isString (value) {
|
||||
return toStr.call(value) === '[object String]'
|
||||
}
|
||||
|
||||
export function isFunction (value) {
|
||||
return typeof value === 'function'
|
||||
}
|
||||
|
||||
export function promisify (fn) {
|
||||
return function () {
|
||||
return new Promise((resolve, reject) => {
|
||||
fn(...arguments, (err, result) => {
|
||||
err ? reject(err) : resolve(result)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export function stringify (value) {
|
||||
if (isNil(value)) return String(value)
|
||||
if (isFunction(value.to_liquid)) return stringify(value.to_liquid())
|
||||
if (isFunction(value.toLiquid)) return stringify(value.toLiquid())
|
||||
if (isFunction(value.to_s)) return value.to_s()
|
||||
if ([toStr, arrToStr].indexOf(value.toString) > -1) return defaultToString(value)
|
||||
if (isFunction(value.toString)) return value.toString()
|
||||
return toStr.call(value)
|
||||
}
|
||||
|
||||
function defaultToString (value) {
|
||||
const cache = []
|
||||
return JSON.stringify(value, (key, value) => {
|
||||
if (isObject(value)) {
|
||||
if (cache.indexOf(value) !== -1) {
|
||||
return
|
||||
}
|
||||
cache.push(value)
|
||||
}
|
||||
return value
|
||||
})
|
||||
}
|
||||
|
||||
export function create (proto) {
|
||||
return Object.create(proto)
|
||||
}
|
||||
|
||||
export function isNil (value) {
|
||||
return value === null || value === undefined
|
||||
}
|
||||
|
||||
export function isArray (value) {
|
||||
// be compatible with IE 8
|
||||
return toStr.call(value) === '[object Array]'
|
||||
}
|
||||
|
||||
export function isError (value) {
|
||||
const signature = toStr.call(value)
|
||||
// [object XXXError]
|
||||
return signature.substr(-6, 5) === 'Error' ||
|
||||
(typeof value.message === 'string' && typeof value.name === 'string')
|
||||
}
|
||||
|
||||
/*
|
||||
* Iterates over own enumerable string keyed properties of an object and invokes iteratee for each property.
|
||||
* The iteratee is invoked with three arguments: (value, key, object).
|
||||
* Iteratee functions may exit iteration early by explicitly returning false.
|
||||
* @param {Object} object The object to iterate over.
|
||||
* @param {Function} iteratee The function invoked per iteration.
|
||||
* @return {Object} Returns object.
|
||||
*/
|
||||
export function forOwn (object, iteratee) {
|
||||
object = object || {}
|
||||
for (const k in object) {
|
||||
if (object.hasOwnProperty(k)) {
|
||||
if (iteratee(object[k], k, object) === false) break
|
||||
}
|
||||
}
|
||||
return object
|
||||
}
|
||||
|
||||
/*
|
||||
* Assigns own enumerable string keyed properties of source objects to the destination object.
|
||||
* Source objects are applied from left to right.
|
||||
* Subsequent sources overwrite property assignments of previous sources.
|
||||
*
|
||||
* Note: This method mutates object and is loosely based on Object.assign.
|
||||
*
|
||||
* @param {Object} object The destination object.
|
||||
* @param {...Object} sources The source objects.
|
||||
* @return {Object} Returns object.
|
||||
*/
|
||||
export function assign (object) {
|
||||
object = isObject(object) ? object : {}
|
||||
const srcs = Array.prototype.slice.call(arguments, 1)
|
||||
srcs.forEach((src) => Object.assign(object, src))
|
||||
return object
|
||||
}
|
||||
|
||||
export function last (arr) {
|
||||
return arr[arr.length - 1]
|
||||
}
|
||||
|
||||
export function uniq (arr) {
|
||||
const u = {}
|
||||
const a = []
|
||||
for (let i = 0, l = arr.length; i < l; ++i) {
|
||||
if (u.hasOwnProperty(arr[i])) {
|
||||
continue
|
||||
}
|
||||
a.push(arr[i])
|
||||
u[arr[i]] = 1
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
/*
|
||||
* Checks if value is the language type of Object.
|
||||
* (e.g. arrays, functions, objects, regexes, new Number(0), and new String(''))
|
||||
* @param {any} value The value to check.
|
||||
* @return {Boolean} Returns true if value is an object, else false.
|
||||
*/
|
||||
export function isObject (value) {
|
||||
const type = typeof value
|
||||
return value !== null && (type === 'object' || type === 'function')
|
||||
}
|
||||
|
||||
/*
|
||||
* A function to create flexibly-numbered lists of integers,
|
||||
* handy for each and map loops. start, if omitted, defaults to 0; step defaults to 1.
|
||||
* Returns a list of integers from start (inclusive) to stop (exclusive),
|
||||
* incremented (or decremented) by step, exclusive.
|
||||
* Note that ranges that stop before they start are considered to be zero-length instead of
|
||||
* negative — if you'd like a negative range, use a negative step.
|
||||
*/
|
||||
export function range (start, stop, step) {
|
||||
if (arguments.length === 1) {
|
||||
stop = start
|
||||
start = 0
|
||||
}
|
||||
step = step || 1
|
||||
|
||||
const arr = []
|
||||
for (let i = start; i < stop; i += step) {
|
||||
arr.push(i)
|
||||
}
|
||||
return arr
|
||||
}
|
||||
Reference in New Issue
Block a user