All Projects → wooorm → match-casing

wooorm / match-casing

Licence: MIT license
Match the case of `value` to that of `base`

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to match-casing

Cluedatasetsearch
搜索所有中文NLP数据集,附常用英文NLP数据集
Stars: ✭ 2,112 (+16146.15%)
Mutual labels:  match
html-comment-regex
Regular expression for matching HTML comments
Stars: ✭ 15 (+15.38%)
Mutual labels:  match
PragmaticSegmenterNet
Port of PragmaticSegmenter for sentence boundary detection
Stars: ✭ 25 (+92.31%)
Mutual labels:  sentence
triehash
Generator for order-preserving minimal perfect hash functions in C
Stars: ✭ 36 (+176.92%)
Mutual labels:  lowercase
lm-scorer
📃Language Model based sentences scoring library
Stars: ✭ 264 (+1930.77%)
Mutual labels:  sentence
es6-template-regex
Regular expression for matching es6 template delimiters in a string.
Stars: ✭ 15 (+15.38%)
Mutual labels:  match
mswjs.io
Official website and documentation for the Mock Service Worker library.
Stars: ✭ 77 (+492.31%)
Mutual labels:  match
is-match
Create a matching function from a glob pattern, regex, string, array or function.
Stars: ✭ 20 (+53.85%)
Mutual labels:  match
10000sentences
10,000 sentences: an Android app to help you learn new words in foreign languages
Stars: ✭ 116 (+792.31%)
Mutual labels:  sentence
Apex-Code-Conventions
Apex conventions and best practices for Salesforce Developers
Stars: ✭ 28 (+115.38%)
Mutual labels:  uppercase
pascalcase
Convert a string to pascal case (upper camel case). Used by more than 8.7 million projects on GitHub! Please follow this library's author: https://github.com/jonschlinkert
Stars: ✭ 35 (+169.23%)
Mutual labels:  case
glob
Pure Nim library for matching file paths against Unix style glob patterns.
Stars: ✭ 58 (+346.15%)
Mutual labels:  match
UPPERCASE
실시간성에 특화된 풀스택 프레임워크 ✨
Stars: ✭ 30 (+130.77%)
Mutual labels:  uppercase
route pattern generator
A Dart static code generator that produces matchers and builders from route uri patterns.
Stars: ✭ 31 (+138.46%)
Mutual labels:  match
nodejs-support
한국어 형태소 및 구문 분석기의 모음인, KoalaNLP의 Javascript(Node.js) 버전입니다.
Stars: ✭ 81 (+523.08%)
Mutual labels:  sentence
Diff Match Patch
Diff Match Patch is a high-performance library in multiple languages that manipulates plain text.
Stars: ✭ 4,910 (+37669.23%)
Mutual labels:  match
regXwild
⏱ Superfast ^Advanced wildcards++? | Unique algorithms that was implemented on native unmanaged C++ but easily accessible in .NET via Conari (with caching of 0x29 opcodes +optimizations) etc.
Stars: ✭ 20 (+53.85%)
Mutual labels:  match
glob-fs
file globbing for node.js. speedy and powerful alternative to node-glob. This library is experimental and does not work on windows!
Stars: ✭ 54 (+315.38%)
Mutual labels:  match
kunkka-match
高性能撮合引擎
Stars: ✭ 50 (+284.62%)
Mutual labels:  match
probabilistic nlg
Tensorflow Implementation of Stochastic Wasserstein Autoencoder for Probabilistic Sentence Generation (NAACL 2019).
Stars: ✭ 28 (+115.38%)
Mutual labels:  sentence

match-casing

Build Coverage Downloads Size

Match the case of value to that of base.

Contents

What is this?

This package matches the case (lowercase, uppercase, capitalized) of a string to that of another string.

When should I use this?

This package is useful if a user wrote some word, and you want to suggest a replacement, and want to make sure that the suggestion matches that of the original.

Install

This package is ESM only. In Node.js (version 12.20+, 14.14+, or 16.0+), install with npm:

npm install match-casing

In Deno with esm.sh:

import {matchCasing} from 'https://esm.sh/match-casing@2'

In browsers with esm.sh:

<script type="module">
  import {matchCasing} from 'https://esm.sh/match-casing@2?bundle'
</script>

Use

import {matchCasing} from 'match-casing'

matchCasing('foo', 'BAZ') // => 'FOO'
matchCasing('foo', 'Baz') // => 'Foo'
matchCasing('foo', 'baz') // => 'foo'
matchCasing('foo', 'BaZ') // => 'foo'

matchCasing('FOO', 'BAZ') // => 'FOO'
matchCasing('FOO', 'Baz') // => 'Foo'
matchCasing('FOO', 'baz') // => 'foo'
matchCasing('FOO', 'BaZ') // => 'FOO'

matchCasing('Foo', 'BAZ') // => 'FOO'
matchCasing('Foo', 'Baz') // => 'Foo'
matchCasing('Foo', 'baz') // => 'foo'
matchCasing('Foo', 'BaZ') // => 'Foo'

matchCasing('’90S', '’twas') // => '’90s'
matchCasing('’N’', 'a') // => '’n’'

API

This package exports the following identifier: matchCasing. There is no default export.

matchCasing(value, base)

Transform the case in value (string) to match that of base (string).

Types

This package is fully typed with TypeScript. There are no extra exported types.

Algorithm

  • If base is uppercase, value is uppercased
  • Else, if base is lowercase, value is lowercased
  • Else, if the first alphabetic character in base is uppercase, and the rest of base is lowercase, uppercase the first alphabetic character in value and lowercase the rest
  • Else, return value unmodified

The third case deals with initial non-alphabetical characters as expected.

Compatibility

This package is at least compatible with all maintained versions of Node.js. As of now, that is Node.js 12.20+, 14.14+, and 16.0+. It also works in Deno and modern browsers.

Security

This package is safe.

Related

Contribute

Yes please! See How to Contribute to Open Source.

License

MIT © Titus Wormer

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].