flow like the river

This commit is contained in:
root 2025-11-07 00:06:12 +01:00
commit 013fe673f3
42435 changed files with 5764238 additions and 0 deletions

View file

@ -0,0 +1,90 @@
/*
* @copyright 2015- commenthol
* @license MIT
*/
'use strict'
var KEY = /^[a-zA-Z$_][a-zA-Z$_0-9]*$/
/**
* handle references
* @constructor
* @param {Object} references
*/
function Ref (references) {
this.keys = []
this.refs = []
this.key = []
this.references = references || []
}
/**
* wrap an object key
* @api private
* @param {String} key - objects key
* @return {String} wrapped key in quotes if necessary
*/
Ref.wrapkey = function (key) {
return (KEY.test(key) ? key : '"' + key.replace(/"/g, '\\"') + '"')
}
Ref.prototype = {
/**
* push `key` to interal array
* @param {String} key
*/
push: function (key) {
this.key.push(key)
},
/**
* remove the last key from internal array
*/
pop: function () {
this.key.pop()
},
/**
* join the keys
*/
join: function (key) {
var out = ''
key = key || this.key
if (typeof key === 'string') {
key = [key]
}
key.forEach(function (k) {
if (KEY.test(k)) {
out += '.' + k
} else {
out += '[' + Ref.wrapkey(k) + ']'
}
})
return out
},
/**
* check if object `source` has an already known reference.
* If so then origin and source are stored in `opts.reference`
* @param {Object} source - object to compare
* @return {Boolean}
*/
hasReference: function (source) {
var idx
if (~(idx = this.refs.indexOf(source))) {
this.references.push([this.join(), this.keys[idx]])
return true
} else {
this.refs.push(source)
this.keys.push(this.join())
}
},
/**
* get the references array
* @return {Array} references array
*/
getReferences: function () {
return this.references
}
}
module.exports = Ref

View file

@ -0,0 +1,109 @@
/* eslint
no-new-func: 0
*/
'use strict'
var UNSAFE_CHARS_REGEXP = /[\\\r\n\t<>\u2028\u2029"/]/g
var CHARS_REGEXP = /[\\\r\n\t"]/g
var UNICODE_CHARS = {
'"': '\\"',
'\n': '\\n',
'\r': '\\r',
'\t': '\\t',
'\\': '\\\\',
'<': '\\u003C',
'>': '\\u003E',
'/': '\\u002F',
'\u2028': '\\u2028',
'\u2029': '\\u2029'
}
function safeString (str) {
str = str.replace(UNSAFE_CHARS_REGEXP, function (unsafeChar) {
return UNICODE_CHARS[unsafeChar]
})
return str
}
exports.safeString = safeString
function unsafeString (str) {
str = str.replace(CHARS_REGEXP, function (unsafeChar) {
return UNICODE_CHARS[unsafeChar]
})
return str
}
exports.unsafeString = unsafeString
var isArray = exports.isArray = Array.isArray
exports.isArray = isArray
function isString (arg) {
return typeof arg === 'string'
}
exports.isString = isString
function isNull (arg) {
return arg === null
}
exports.isNull = isNull
function isRegExp (re) {
return isObject(re) && objectToString(re) === '[object RegExp]'
}
exports.isRegExp = isRegExp
function isObject (arg) {
return typeof arg === 'object' && arg !== null
}
exports.isObject = isObject
function isDate (d) {
return isObject(d) && objectToString(d) === '[object Date]'
}
exports.isDate = isDate
function isError (e) {
return isObject(e) &&
(objectToString(e) === '[object Error]' || e instanceof Error)
}
exports.isError = isError
function isFunction (arg) {
return typeof arg === 'function'
}
exports.isFunction = isFunction
function isBuffer (arg) {
return arg instanceof Buffer
}
exports.isBuffer = isBuffer
var TYPED_ARRAYS = [
'Int8Array',
'Uint8Array',
'Uint8ClampedArray',
'Int16Array',
'Uint16Array',
'Int32Array',
'Uint32Array',
'Float32Array',
'Float64Array'
]
function isTypedArray (arg) {
var type = toType(arg)
if (TYPED_ARRAYS.indexOf(type) !== -1) {
return type
}
}
exports.isTypedArray = isTypedArray
function objectToString (o) {
return Object.prototype.toString.call(o)
}
function toType (o) {
return objectToString(o).replace(/^\[object (.*)\]$/, '$1')
}