Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New version #1

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .babelrc

This file was deleted.

9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
184 changes: 0 additions & 184 deletions .eslintrc

This file was deleted.

1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
registry = "https://registry.npmjs.com/"
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: node_js
node_js:
- '12'
- '11'
- '10'
- '8'
- '6'
3 changes: 3 additions & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This list of authors is based on the git history of this repo.

Siarhei Bautrukevich <[email protected]>
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]

[Unreleased]: https://github.com/uploadcare/uploadcare-upload-client/compare/v1.0.0...HEAD

## [1.0.0]

### Changed

* Project was moved to TypeScript.
* Optional params (`debug`, `remove`) was removed.

### Added

* Changelog

[1.0.0]: https://github.com/uploadcare/uploadcare-upload-client/compare/v1.0.0-alpha.1...v1.0.0-alpha.2
5 changes: 2 additions & 3 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)
MIT License

Copyright (c) 2015 Krasimir Tsonev
Copyright (c) 2017-2019 Siarhei Bautrukevich

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

59 changes: 35 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,57 @@
# semplate (simple template || string template)
# Semplate

A tiny template pure function
Tiny template library.

## Installation
[![NPM version][npm-img]][npm-url]
[![GitHub release][badge-release-img]][badge-release-url]&nbsp;

You can use this function simply add `dist/semplate.min.js` file on the page.
<!-- toc -->

Or you can install as npm module
* [Install](#install)
* [Usage](#usage)
* [Feedback](#feedback)
* [License](#license)

```
yarn add semplate
<!-- tocstop -->

## Install

```bash
npm install semplate --save
```

## Usage

```js
import semplate from 'semplate';
```javascript
import semplate from 'semplate'

semplate('Hello, {{who}}!', { who: 'JavaScript' });
semplate('Hello, {{who}}!', { who: 'JavaScript' })
// "Hello, JavaScript!"

semplate('Hello, {{ who }}!', { who: 'JavaScript' });
semplate('Hello, {{ who }}!', { who: 'JavaScript' })
// "Hello, JavaScript!"

semplate('Hello, {{ WHO }}!', { who: 'JavaScript' });
semplate('Hello, {{ WHO }}!', { who: 'JavaScript' })
// "Hello, JavaScript!"

// Variable can have @ to avoid conflict with another template engines (as an example, Blade).
// More prefer to use function like this:
semplate('Hello, {{ @who }}!', { who: 'JavaScript' });
semplate('Hello, {{ @who }}!', { who: 'JavaScript' })
// "Hello, JavaScript!"
```

// You can pass other optional arguments: remove (default: true) and debug (default: true)
semplate('Hello, {{ @who }}!', { what: 'JavaScript' }, true, true);
// "what" property was not found in string.
// "Hello, !"
## Feedback

// You can pass other optional arguments: remove (default: true) and debug (default: true)
semplate('Hello, {{ @who }}!', { what: 'JavaScript' }, true, false);
// "Hello, !"
Issues and PRs are welcome. You can provide your feedback or drop me a support
request at [[email protected]][email-hello].

// You can pass other optional arguments: remove (default: true) and debug (default: true)
semplate('Hello, {{ @who }}!', { what: 'JavaScript' }, false, false);
// "Hello, {{ @who }}!"
```
[email-hello]: mailto:[email protected]
[github-releases]: https://github.com/bautrukevich/semplate/releases
[github-contributors]: https://github.com/bautrukevich/semplate/graphs/contributors
[badge-release-img]: https://img.shields.io/github/release/bautrukevich/semplate.svg
[badge-release-url]: https://github.com/bautrukevich/semplate/releases
[npm-img]: http://img.shields.io/npm/v/semplate.svg
[npm-url]: https://www.npmjs.org/package/semplate

## License
[MIT](./LICENSE)
31 changes: 31 additions & 0 deletions dist/semplate.cjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

/**
* A tiny template function.
* @param {string} string
* @param {object} object
* @returns {string}
* @example
* semplate('Hello, {{ @who }}!', { who: 'world' })
* // Hello, world!
*/
function semplate(string, object) {
var result = string;
var regExpNotFound = new RegExp('{{\\s?@?\\w+\\s?}}', 'ig');
for (var property in object) {
if (object.hasOwnProperty(property)) {
var regExp = new RegExp("{{\\s?@?" + property + "\\s?}}", 'ig');
if (regExp.test(string)) {
// @ts-ignore
result = result.replace(regExp, object[property]);
}
else {
throw new Error("\"" + property + "\" was not found in \"" + string + "\".");
}
}
}
result = result.replace(regExpNotFound, '');
return result;
}

module.exports = semplate;
29 changes: 29 additions & 0 deletions dist/semplate.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* A tiny template function.
* @param {string} string
* @param {object} object
* @returns {string}
* @example
* semplate('Hello, {{ @who }}!', { who: 'world' })
* // Hello, world!
*/
function semplate(string, object) {
var result = string;
var regExpNotFound = new RegExp('{{\\s?@?\\w+\\s?}}', 'ig');
for (var property in object) {
if (object.hasOwnProperty(property)) {
var regExp = new RegExp("{{\\s?@?" + property + "\\s?}}", 'ig');
if (regExp.test(string)) {
// @ts-ignore
result = result.replace(regExp, object[property]);
}
else {
throw new Error("\"" + property + "\" was not found in \"" + string + "\".");
}
}
}
result = result.replace(regExpNotFound, '');
return result;
}

export default semplate;
2 changes: 0 additions & 2 deletions dist/semplate.min.js

This file was deleted.

Loading