2.6.0 • Published 1 year ago

tequery v2.6.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

tequery

npm.io

text transform query

Install

$ npm install tequery

Usage

basic $

Basic text transform query. $ is text body variable.

import { tequery as tq } from 'tequery'

tq(' hoge ', '$.trim()').result
// => 'hoge'
// equaliy shorthand
tq(' hoge ', '.trim()').result

tq('https://example.com', `.replace('https://', '')`).result
// => 'example.com'

line-run $$

const text = ` line1
   line2
 line3`

tq(text, '$$.trim()').result
// => 'line1\n'
// + 'line2\n'
// + 'line3'

finalize

final process to string from returned value type.

typeprocess
typeof v === 'function'v($)
typeof v === 'string'v
typeof v === 'number'String(v)
typeof v === 'undefined'""
v === null""
Array.isArray(v)v.join("\n")
otherString(v)
typeof v === 'object'JSON.stringify

built-in funcs

util functions in running scope.

tq('', `len('abc')`).result
// => '3'
tq('abcde', 'len($)').result
// => '5'

// equaliy shorthand
tq('abcde', 'len').result
funcusagereturn
lenlen('aaa')3
lineNum, lnln('a\nb')2
countcount('aaa-a-', 'a')4
packpack('a\nb\n\nc\n\n\n')'a\nb\nc\n'
shiftlshiftl('a-b-c-d', '-', 1)'b-c-d'
shiftrshiftr('a-b-c-d', '-', 1)'a-b-c'

built-in vars

util vars in running scope.

tq('a,b,c', `$csv.join(':')`).result
// => 'a:b:c'
expect(tq('', `$tsv.join(':')`).result).toBe()
expect(tq('a+b+c', `$sp('+').join(':')`).result).toBe('a:b:c')
vars$=is
$tsva\tb\tc['a', 'b', 'c']
$csva,b,c['a', 'b', 'c']
$ls, $linesa\nb\nc['a', 'b', 'c']
$sp('+')a+b+c['a', 'b', 'c']

more example

vars with line-run

const txt = `a,b,c
d,e,f`

tq(text, `$$csv.join(':')`).result
// => 'a:b:c\n'
//  + 'd:e:f'

result object

type Result = {
  status: 'ok' | 'ng' // is changed
  result: string
  resultRaw: unknown
  evalQuery: string // compiled query
  errorText: string
  returnType: string
  comps: Complements // is shorthund enabled
}
2.6.0

1 year ago

2.5.0

2 years ago

2.5.1

2 years ago

2.4.0

2 years ago

2.3.0

2 years ago

2.3.1

2 years ago

2.2.0

2 years ago

2.1.0

2 years ago

2.0.0

2 years ago

1.0.0

2 years ago

0.6.2

2 years ago

0.6.1

2 years ago

0.6.0

2 years ago

0.5.0

2 years ago

0.4.0

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago

0.0.0

2 years ago