0.2.2 • Published 11 months ago

submarin-converter v0.2.2

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

submarin-converter

いい感じの型が付いた TypeScript 製文字変換ライブラリ

Example

import { Converter, Plugin } from "submarin-converter"
import type { ConvertFunction } from "submarin-converter"

const upperCase: ConvertFunction = ({ input }) => input.toUpperCase()
const x4: ConvertFunction<{ target: `${string}` }> = ({
  input,
  option = {
    target: "O",
  },
}) => input.replace(new RegExp(option.target, "g"), Array(4).fill(option.target).join(""))
const amazingProcessing: ConvertFunction = ({ input }) =>
  new Promise<void>((r) => setTimeout(() => r(), 1000)).then(() => `${input.length}`)

const converter = new Converter({
  plugins: {
    upperCase: new Plugin({ convertFunction: [upperCase] }),
    x4: new Plugin({ convertFunction: [x4] }),
    amazingProcessing: new Plugin({ convertFunction: [amazingProcessing] }),
  } as const,
})

const input = "subway"

const [output, details] = await converter.convert(input, [
  { id: "upperCase" },
  {
    id: "x4",
    option: {
      target: "A",
    },
  },
  { id: "amazingProcessing" },
] as const)

console.log(output) // "9"
console.log(details)
/*
[
  {
    id: "upperCase",
    ok: true,
    output: "SUBWAY",
    args: {
      input: "subway",
    },
    error: [],
  },
  {
    id: "x4",
    ok: true,
    output: "SUBWAAAAY",
    args: {
      input: "SUBWAY",
      option: {
        target: "A",
      },
    },
    error: [],
  },
  {
    id: "amazingProcessing",
    ok: true,
    output: "9",
    args: {
      input: "SUBWAAAAY",
    },
    error: [],
  },
]
*/

Installation

npm install submarin-converter
# or yarn add submarin-converter
# or pnpm add submarin-converter

Docs

Development

git clone https://github.com/souhait0614/submarin-converter.git
cd submarin-converter
pnpm i
pnpm test
0.2.1

11 months ago

0.2.0

11 months ago

0.1.1

11 months ago

0.2.2

11 months ago

1.2.3

3 years ago

1.2.0

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.1.3

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.1.2

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago