/** * Determine if the given buffer is utf8. * @param {Buffer} buffer */ export default function isBufferUtf8Representable(buffer) { const utfEncodedBuffer = buffer.toString('utf8'); const reconstructedBuffer = Buffer.from(utfEncodedBuffer, 'utf8'); return reconstructedBuffer.equals(buffer); }
/** * * @param {String|Function} source * @param {IFunctionSettings} [settings] * @returns {IGPUFunction} */ functionToIGPUFunction(source, settings = {}) { if (typeof source !== 'string' && typeof source !== 'function') throw new Error('source not a string or function'); const sourceString = typeof source === 'string' ? source : source.toString(); let argumentTypes = []; if (Array.isArray(settings.argumentTypes)) { argumentTypes = settings.argumentTypes; } else if (typeof settings.argumentTypes === 'object') { argumentTypes = utils.getArgumentNamesFromString(sourceString) .map(name => settings.argumentTypes[name]) || []; } else { argumentTypes = settings.argumentTypes || []; } return { name: utils.getFunctionNameFromString(sourceString) || null, source: sourceString, argumentTypes, returnType: settings.returnType || null, }; }
if (typeof taskName === 'function') { fn = taskName; taskName = fn.toString();
"var SUPPORT_WORKER = true;" ) + "(" + _worker.toString() + ")()" ],{ "type": "text/javascript"
export function getObjectClass(obj: Object) { if (!obj) { return; } let constructor = obj.constructor; if (!constructor) { return; } if (constructor.name) { return constructor.name; } let str = constructor.toString(); if (!str) { return; } let arr = null; if (str.charAt(0) === '[') { arr = str.match(/\[\w+\s*(\w+)\]/); } else { arr = str.match(/function\s*(\w+)/); } if (arr && arr.length === 2) { return arr[1]; } }
test('noop does nothing', t => { t.is(typeof noop, 'function'); t.is(noop(), undefined); /** * Check that function actually does nothing, for everyone. * https://github.com/sindresorhus/noop3/issues/10 */ // Check that noop function is a function that functions like a function. t.is(noop.toString, Function.prototype.toString); // Ensure the preciseness of the no operation. t.is(noop.toString(), EXAMPLE_NOOP_FUNCTION_3); });
function(a,b,c){function d(a,b,c){return"function"==typeof b&&(c=b,b=e(c).replace(/_$/,"")),j(a,b,{configurable:!0,writable:!0,value:c})}function e(a){return"function"!=typeof a?"":"_name"in a?a._name:"name"in a?a.name:k.call(a).match(n)[1]}function f(a,b){ // Undo the name-stripping that UglifyJS does return b._name=a,b}function g(a){function b(b,e){return e||2===arguments.length?d.set(b,e):(e=d.get(b),e===c&&(e=a(b),d.set(b,e))),e}var d=new p;return a||(a=q),b}var h=Object.getOwnPropertyNames,i="object"==typeof window?Object.getOwnPropertyNames(window):[],j=Object.defineProperty,k=Function.prototype.toString,l=Object.create,m=Object.prototype.hasOwnProperty,n=/^\n?function\s?(\w*)?_?\(/,o=function(){function a(){var a=g(),c={};this.unlock=function(d){var e=n(d);if(m.call(e,a))return e[a](c);var f=l(null,b);return j(e,a,{value:function(a){return a===c?f:void 0}}),f}}var b={value:{writable:!0,value:c}},e=l(null),g=function(){var a=Math.random().toString(36).slice(2);return a in e?g():e[a]=a},k=g(),n=function(a){if(m.call(a,k))return a[k];if(!Object.isExtensible(a))throw new TypeError("Object must be extensible");var b=l(null);return j(a,k,{value:b}),b}; // common per-object storage area made visible by patching getOwnPropertyNames' return d(Object,f("getOwnPropertyNames",function(a){ // gh-43 var b,c=Object(a);if("[object Window]"===c.toString())try{b=h(a)}catch(d){b=i}else b=h(a);return m.call(a,k)&&b.splice(b.indexOf(k),1),b})),d(a.prototype,f("get",function(a){return this.unlock(a).value})),d(a.prototype,f("set",function(a,b){this.unlock(a).value=b})),a}(),p=function(g){function h(b){return this===a||null==this||this===h.prototype?new h(b):(p(this,new o),void r(this,b))}function i(a){n(a);var d=q(this).get(a);return d===b?c:d}function j(a,d){n(a), // store a token for explicit undefined so that "has" works correctly q(this).set(a,d===c?b:d)}function k(a){return n(a),q(this).get(a)!==c}function l(a){n(a);var b=q(this),d=b.get(a)!==c;return b.set(a,c),d}function m(){return q(this),"[object WeakMap]"}var n=function(a){if(null==a||"object"!=typeof a&&"function"!=typeof a)throw new TypeError("Invalid WeakMap key")},p=function(a,b){var c=g.unlock(a);if(c.value)throw new TypeError("Object is already a WeakMap");c.value=b},q=function(a){var b=g.unlock(a).value;if(!b)throw new TypeError("WeakMap is not generic");return b},r=function(a,b){null!==b&&"object"==typeof b&&"function"==typeof b.forEach&&b.forEach(function(c,d){c instanceof Array&&2===c.length&&j.call(a,b[d][0],b[d][1])})}; // Undo the function-name stripping that UglifyJS does i._name="get",j._name="set",k._name="has",m._name="toString";var s=(""+Object).split("Object"),t=f("toString",function(){return s[0]+e(this)+s[1]});d(t,t);var u={__proto__:[]}instanceof Array?function(a){a.__proto__=t}:function(a){d(a,t)};return u(h),[m,i,j,k,l].forEach(function(a){d(h.prototype,a),u(a)}),h}(new o),q=Object.create?function(){return Object.create(null)}:function(){return{}};"undefined"!=typeof module?module.exports=p:"undefined"!=typeof exports?exports.WeakMap=p:"WeakMap"in a||(a.WeakMap=p),p.createStorage=g,a.WeakMap&&(a.WeakMap.createStorage=g)}(function(){return this}())
function reflectFunction(func: Function) { // https://stackoverflow.com/questions/6921588/is-it-possible-to-reflect-the-arguments-of-a-javascript-function const ARGS = func.toString() .replace (/[\r\n\s]+/g, ' ') .match (/(?:function\s*\w*)?\s*(?:\((.*?)\)|([^\s]+))/) .slice (1, 3) .join('') .split (/\s*,\s*/); return { arguments: ARGS, }; }
function extractArgs(fn) { var fnText = Function.prototype.toString.call(fn).replace(STRIP_COMMENTS, ''), args = fnText.match(ARROW_ARG) || fnText.match(FN_ARGS); return args; }
it('should be instantiable', function(){ function nameOf(fn) { return Function.prototype.toString.call(fn).match(/function\s*([^\s]*)\s*\(/)[1]; } proclaim.equal(nameOf(WeakSet), 'WeakSet'); proclaim.isTypeOf(new WeakSet, 'object'); });
/** * * @param func {Function} * @returns {Array} */ function getParamNames (func) { let func_str = func.toString() let func_def = func_str.slice(func_str.indexOf('(') + 1, func_str.indexOf(')')) return func_def.match(/([^\s,]+)/g) }
const isClass = (f) => { return ( (_isFunction(f)) && (/^class\s/.test(Function.prototype.toString.call(f))) ) }
/** * Determine if the given buffer is utf8. * @param {Buffer} buffer */ export default function isBufferUtf8Representable(buffer) { const utfEncodedBuffer = buffer.toString('utf8'); const reconstructedBuffer = Buffer.from(utfEncodedBuffer, 'utf8'); return reconstructedBuffer.equals(buffer); }
export function getObjectClass(obj: Object) { if (!obj) { return; } let constructor = obj.constructor; if (!constructor) { return; } if (constructor.name) { return constructor.name; } let str = constructor.toString(); if (!str) { return; } let arr = null; if (str.charAt(0) === '[') { arr = str.match(/\[\w+\s*(\w+)\]/); } else { arr = str.match(/function\s*(\w+)/); } if (arr && arr.length === 2) { return arr[1]; } }