Git Product home page Git Product logo

tequery's Introduction

tequery

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.

type process
typeof v === 'function' v($)
typeof v === 'string' v
typeof v === 'number' String(v)
typeof v === 'undefined' ""
v === null ""
Array.isArray(v) v.join("\n")
other String(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
func usage return
len len('aaa') 3
lineNum, ln ln('a\nb') 2
count count('aaa-a-', 'a') 4
pack pack('a\nb\n\nc\n\n\n') 'a\nb\nc\n'
shiftl shiftl('a-b-c-d', '-', 1) 'b-c-d'
shiftr shiftr('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
$tsv a\tb\tc ['a', 'b', 'c']
$csv a,b,c ['a', 'b', 'c']
$ls, $lines a\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
}

tequery's People

Contributors

elzup avatar renovate[bot] avatar renovate-bot avatar

Stargazers

Roman avatar  avatar

Watchers

 avatar  avatar

tequery's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • Update dependency @swc/core to v1.3.29
  • Update definitelyTyped (@types/jest, @types/react)
  • Update dependency jest to v29.4.1
  • Update linters (eslint, prettier)
  • Lock file maintenance

Detected dependencies

github-actions
.github/workflows/node.yml
  • actions/checkout v3
  • actions/setup-node v3
npm
package.json
  • @elzup/tsconfig 1.1.0
  • @swc/core 1.3.26
  • @swc/jest 0.2.24
  • @types/jest 29.2.5
  • @types/react 18.0.26
  • eslint 8.31.0
  • eslint-config-nzap 6.2.0
  • jest 29.3.1
  • prettier 2.8.2
  • typescript 4.9.4
  • node >=12

  • Check this box to trigger a request for Renovate to run again on this repository

Strict query

Why

current replacement is invalid.
ex. META char in string literall (query "hoge@$".replace(/[@$]/g, "_"))

What

  • remove prepare replacement
    • "call@" shorthand
      • if result type function bind $text
    • META char change to strict code variable char
      • from @ to $(, alias $t, $text) or t or _ or _t
      • from $ to $$ (, alias $l, $line)
  • using AST for replacement

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.