gpu.createKernel(function(a) { const pixel = a[this.thread.y][this.thread.x]; return pixel.b * 255; }, { output: [image.width, image.height], precision: 'unsigned', argumentTypes: { a: 'HTMLImage' }, })
t('dynamic multi row insert', async() => { await sql`create table test (a int, b text)` const x = { a: 42, b: 'the answer' } return [ 'the answer', (await sql`insert into test ${ sql([x, x]) } returning *`)[1].b, await sql`drop table test` ] })
test('supports leading bracket notation (double quote)', async ({ is }) => { const stream = sink() const instance = pino({ redact: ['["a.a"].b'] }, stream) const obj = { 'a.a': { b: 'c' } } instance.info(obj) const o = await once(stream, 'data') is(o['a.a'].b, '[Redacted]') })
/** * Calculates brightness on a scale of 0-255. * * @param color See colorStringToRgb for supported formats. */ function colorBrightness( color ) { if( typeof color === 'string' ) color = colorToRgb( color ); if( color ) { return ( color.r * 299 + color.g * 587 + color.b * 114 ) / 1000; } return null; }
function k(a){function d(e){var b=e.charCodeAt(0);if(92!==b)return b;var a=e.charAt(1);return(b=W[a])?b:"0"<=a&&"7">=a?parseInt(e.substring(1),8):"u"===a||"x"===a?parseInt(e.substring(2),16):e.charCodeAt(1)}function f(e){if(32>e)return(16>e?"\\x0":"\\x")+e.toString(16);e=String.fromCharCode(e);return"\\"===e||"-"=== e||"]"===e||"^"===e?"\\"+e:e}function b(e){var b=e.substring(1,e.length-1).match(/\\u[0-9A-Fa-f]{4}|\\x[0-9A-Fa-f]{2}|\\[0-3][0-7]{0,2}|\\[0-7]{1,2}|\\[\s\S]|-|[^-\\]/g);e=[];var a="^"===b[0],c=["["];a&&c.push("^");for(var a=a?1:0,h=b.length;a<h;++a){var l=b[a];if(/\\[bdsw]/i.test(l))c.push(l);else{var l=d(l),n;a+2<h&&"-"===b[a+1]?(n=d(b[a+2]),a+=2):n=l;e.push([l,n]);65>n||122<l||(65>n||90<l||e.push([Math.max(65,l)|32,Math.min(n,90)|32]),97>n||122<l||e.push([Math.max(97,l)&-33,Math.min(n,122)&-33]))}}e.sort(function(e, a){return e[0]-a[0]||a[1]-e[1]});b=[];h=[];for(a=0;a<e.length;++a)l=e[a],l[0]<=h[1]+1?h[1]=Math.max(h[1],l[1]):b.push(h=l);for(a=0;a<b.length;++a)l=b[a],c.push(f(l[0])),l[1]>l[0]&&(l[1]+1>l[0]&&c.push("-"),c.push(f(l[1])));c.push("]");return c.join("")}function g(e){for(var a=e.source.match(/(?:\[(?:[^\x5C\x5D]|\\[\s\S])*\]|\\u[A-Fa-f0-9]{4}|\\x[A-Fa-f0-9]{2}|\\[0-9]+|\\[^ux0-9]|\(\?[:!=]|[\(\)\^]|[^\x5B\x5C\(\)\^]+)/g),c=a.length,d=[],h=0,l=0;h<c;++h){var n=a[h];"("===n?++l:"\\"===n.charAt(0)&&(n= +n.substring(1))&&(n<=l?d[n]=-1:a[h]=f(n))}for(h=1;h<d.length;++h)-1===d[h]&&(d[h]=++k);for(l=h=0;h<c;++h)n=a[h],"("===n?(++l,d[l]||(a[h]="(?:")):"\\"===n.charAt(0)&&(n=+n.substring(1))&&n<=l&&(a[h]="\\"+d[n]);for(h=0;h<c;++h)"^"===a[h]&&"^"!==a[h+1]&&(a[h]="");if(e.ignoreCase&&I)for(h=0;h<c;++h)n=a[h],e=n.charAt(0),2<=n.length&&"["===e?a[h]=b(n):"\\"!==e&&(a[h]=n.replace(/[a-zA-Z]/g,function(a){a=a.charCodeAt(0);return"["+String.fromCharCode(a&-33,a|32)+"]"}));return a.join("")}for(var k=0,I=!1, m=!1,J=0,c=a.length;J<c;++J){var r=a[J];if(r.ignoreCase)m=!0;else if(/[a-z]/i.test(r.source.replace(/\\u[0-9a-f]{4}|\\x[0-9a-f]{2}|\\[^ux]/gi,""))){I=!0;m=!1;break}}for(var W={b:8,t:9,n:10,v:11,f:12,r:13},u=[],J=0,c=a.length;J<c;++J){r=a[J];if(r.global||r.multiline)throw Error(""+r);u.push("(?:"+g(r)+")")}return new RegExp(u.join("|"),m?"gi":"g")}
div(ctx) { let a = Number(ctx.params.a); let b = Number(ctx.params.b); if (b != 0) return a / b; else throw new Error("Divide by zero!"); }
add(ctx) { return { node: this.broker.nodeID, result: Number(ctx.params.a) + Number(ctx.params.b) }; }
gpu.createKernel(function(v) { const pixel = v[this.thread.y][this.thread.x]; this.color(0, 0, pixel.b / 255, 255); }, { output: [width, height], graphical: true, argumentTypes: { v: 'Array2D(4)' } })
t('dynamic select array', async() => { await sql`create table test (a int, b text)` await sql`insert into test (a, b) values (42, 'yay')` return ['yay', (await sql`select ${ sql(['a', 'b']) } from test`)[0].b, await sql`drop table test`] })
test('supports leading bracket notation (backtick quote)', async ({ is }) => { const stream = sink() const instance = pino({ redact: ['[`a.a`].b'] }, stream) const obj = { 'a.a': { b: 'c' } } instance.info(obj) const o = await once(stream, 'data') is(o['a.a'].b, '[Redacted]') })
t('dynamic select args', async() => { await sql`create table test (a int, b text)` await sql`insert into test (a, b) values (42, 'yay')` return ['yay', (await sql`select ${ sql('a', 'b') } from test`)[0].b, await sql`drop table test`] })
test('supports leading bracket notation (single quote)', async ({ is }) => { const stream = sink() const instance = pino({ redact: ['[\'a.a\'].b'] }, stream) const obj = { 'a.a': { b: 'c' } } instance.info(obj) const o = await once(stream, 'data') is(o['a.a'].b, '[Redacted]') })
t('dynamic update', async() => { await sql`create table test (a int, b text)` await sql`insert into test (a, b) values (17, 'wrong')` return [ 'the answer', (await sql`update test set ${ sql({ a: 42, b: 'the answer' }) } returning *`)[0].b, await sql`drop table test` ] })