Skip to content
This repository has been archived by the owner on Jan 16, 2025. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
- web unit tests are not working yet
  • Loading branch information
ehoogerbeets committed Aug 30, 2023
1 parent cb3de4d commit bbaa92c
Show file tree
Hide file tree
Showing 21 changed files with 1,607 additions and 1 deletion.
11 changes: 11 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"presets": [[
"@babel/preset-env", {
"targets": {
"node": "current",
"browsers": "cover 99.5%"
}
}
]],
"plugins": ["add-module-exports"]
}
38 changes: 38 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
version: 2.1
jobs:
test:
parameters:
docker_image:
type: string
default: cimg/node:current
docker:
- image: << parameters.docker_image >>
steps:
- checkout
- run:
name: Setup
command: |
rm -rf node_modules package-lock.json
npm install
- run:
name: Running all unit tests
command: |
node -v
npm -v
npm run test
workflows:
version: 2
test-all-node-versions:
jobs:
- test:
docker_image: circleci/node:10-browsers
- test:
docker_image: cimg/node:12.13
- test:
docker_image: cimg/node:14.21
- test:
docker_image: cimg/node:16.19
- test:
docker_image: cimg/node:18.15
- test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,4 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
/lib/
17 changes: 17 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ilib-casemapper</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>
</projectDescription>
77 changes: 77 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* Gruntfile.js - build this project
*
* @license
* Copyright © 2021-2022, JEDLSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*/

module.exports = function(grunt) {
require('load-grunt-tasks')(grunt);

var debug = grunt.option('mode') === 'dev';

// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
build: {
src: 'src/*.js',
dest: 'lib/'
}
},
babel: {
options: {
sourceMap: true,
presets: [[
'@babel/preset-env',
{
targets: {
node: "10",
browsers: "cover 99.5%"
}
}
]],
plugins: [
"add-module-exports"
],
minified: !debug,
comments: false
},
dist: {
files: [{
expand: true,
cwd: 'src',
src: ['*.js'],
dest: 'lib/',
ext: '.js'
}]
}
},
clean: {
dist: ['lib']
}
});

// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-uglify');

// Default task(s).
grunt.registerTask('default', ['babel']);
if (!debug) grunt.registerTask('uglify', ['uglify']);
};
85 changes: 84 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,85 @@
# ilib-casemapper
Map a string to upper- or lower-case locale-sensitively

Map a string to upper- or lower-case locale-sensitively.

Many people don't realize that case mapping is a locale-sensitive
operation. The fact is, what the upper-case version of a particular letter
is depends on who you ask!

## Installation

```
npm install ilib-casemapper
or
yarn add ilib-casemapper
```

## Upper- or Lower-casing a Letter

To map the case of a letter, you first create an instance of the CaseMapper
class. By default, this will use the mappings for English.

Here is how you would map a letter using the Turkish rules:

```javascript
ES2015:

var CaseMapper = require("ilib-casemapper");
var cm = new CaseMapper({locale: "tr-TR"});

var upper = cm.map('i'); // "upper" should now contain "İ"

ES6:

import CaseMapper from "ilib-casemapper";
const cm = new CaseMapper({locale: "tr-TR"});

const upper = cm.map('i'); // "upper" should now contain "İ"
```

In general, you should be able to use the case mapper in older Javascript
engines by requiring it, or in modern Javascript engines by
importing it. The package was built to be able to support both. From here
on, we will only give modern JS examples.

Here is how you use the case mapper to lower:

```javascript
import CaseMapper from "ilib-casemapper";
const cm = new CaseMapper({
locale: "tr-TR",
direction: "lower"
});

const upper = cm.map('İ'); // "upper" should now contain "i"
```

Full documentation: [CaseMapper class](./docs/CaseMapper.md)


# License

Copyright © 2023, JEDLSoft

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and
limitations under the License.

# Release Notes

### v1.0.0

- Code taken from ilib 14.19.0 and converted to an ES6 module.
- Use babel to transpile it back to ES2015 so it can be used in either ES215 or
ES6 code
66 changes: 66 additions & 0 deletions docs/CaseMapper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<a name="CaseMapper"></a>

## CaseMapper
A class that can map strings to upper and lower case in a
locale-sensitive manner.

**Kind**: global class

* [CaseMapper](#CaseMapper)
* [new CaseMapper([options])](#new_CaseMapper_new)
* [.getLocale()](#CaseMapper+getLocale) ⇒ <code>Locale</code>
* [.map(string)](#CaseMapper+map) ⇒ <code>string</code> \| <code>undefined</code>


* * *

<a name="new_CaseMapper_new"></a>

### new CaseMapper([options])
Create a new string case mapper instance that maps strings to upper or
lower case. This mapping will work for any string as characters
that have no case will be returned unchanged.<p>

The options may contain any of the following properties:

<ul>
<li><i>locale</i> - locale to use when loading the mapper. Some maps are
locale-dependent, and this locale selects the right one. Default if this is
not specified is the current locale.

<li><i>direction</i> - "toupper" for upper-casing, or "tolower" for lower-casing.
Default if not specified is "toupper".
</ul>


| Param | Type | Description |
| --- | --- | --- |
| [options] | <code>Object</code> | options to initialize this mapper |


* * *

<a name="CaseMapper+getLocale"></a>

### caseMapper.getLocale() ⇒ <code>Locale</code>
Return the locale that this mapper was constructed with.

**Kind**: instance method of [<code>CaseMapper</code>](#CaseMapper)
**Returns**: <code>Locale</code> - the locale that this mapper was constructed with

* * *

<a name="CaseMapper+map"></a>

### caseMapper.map(string) ⇒ <code>string</code> \| <code>undefined</code>
Map a string to lower case in a locale-sensitive manner.

**Kind**: instance method of [<code>CaseMapper</code>](#CaseMapper)

| Param | Type |
| --- | --- |
| string | <code>string</code> \| <code>undefined</code> |


* * *

19 changes: 19 additions & 0 deletions jsdoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"tags": {
"allowUnknownTags": true,
"dictionaries": ["jsdoc", "closure"]
},
"copyright": "Copyright (c) 2022 JEDLSoft",
"linenums": true,
"sort": true,
"search": true,
"opts": {
"template": "node_modules/docdash",
"encoding": "utf8",
"destination": "docs",
"recurse": true
},
"source": {
"include": ["src"]
}
}
Loading

0 comments on commit bbaa92c

Please sign in to comment.