Skip to content

Commit e26ea21

Browse files
author
Alexander Belov
committed
Initial commit
Created with bitjson/typescript-starter@65f82a9
0 parents  commit e26ea21

21 files changed

+462
-0
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
end_of_line = lf
7+
indent_size = 2
8+
indent_style = space
9+
insert_final_newline = true
10+
max_line_length = 80
11+
trim_trailing_whitespace = true
12+
13+
[*.md]
14+
max_line_length = 0
15+
trim_trailing_whitespace = false

.github/CONTRIBUTING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Example Contributing Guidelines
2+
3+
This is an example of GitHub's contributing guidelines file. Check out GitHub's [CONTRIBUTING.md help center article](https://help.github.com/articles/setting-guidelines-for-repository-contributors/) for more information.

.github/ISSUE_TEMPLATE.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
* **I'm submitting a ...**
2+
[ ] bug report
3+
[ ] feature request
4+
[ ] question about the decisions made in the repository
5+
[ ] question about how to use this project
6+
7+
* **Summary**
8+
9+
10+
11+
* **Other information** (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
* **What kind of change does this PR introduce?** (Bug fix, feature, docs update, ...)
2+
3+
4+
5+
* **What is the current behavior?** (You can also link to an open issue here)
6+
7+
8+
9+
* **What is the new behavior (if this is a feature change)?**
10+
11+
12+
13+
* **Other information**:

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
node_modules
2+
build
3+
test
4+
src/**.js
5+
.idea/*
6+
7+
coverage
8+
.nyc_output
9+
*.log
10+
11+
package-lock.json

.npmignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
src
2+
test
3+
tsconfig.json
4+
tsconfig.module.json
5+
tslint.json
6+
.travis.yml
7+
.github
8+
.prettierignore
9+
.vscode
10+
build/docs
11+
**/*.spec.*
12+
coverage
13+
.nyc_output
14+
*.log

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# package.json is formatted by package managers, so we ignore it here
2+
package.json

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Alexander Belov
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# @algo-js/segment-tree
2+
3+
Segment Tree implementation in TypeScript

package.json

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
{
2+
"name": "@algo-js/segment-tree",
3+
"version": "1.0.0",
4+
"description": "Segment Tree implementation in TypeScript",
5+
"main": "build/main/index.js",
6+
"typings": "build/main/index.d.ts",
7+
"module": "build/module/index.js",
8+
"repository": "https://github.com/YOUR_GITHUB_USER_NAME/@algo-js/segment-tree",
9+
"license": "MIT",
10+
"keywords": [],
11+
"scripts": {
12+
"describe": "npm-scripts-info",
13+
"build": "run-s clean && run-p build:*",
14+
"build:main": "tsc -p tsconfig.json",
15+
"build:module": "tsc -p tsconfig.module.json",
16+
"fix": "run-s fix:*",
17+
"fix:prettier": "prettier \"src/**/*.ts\" --write",
18+
"fix:tslint": "tslint --fix --project .",
19+
"test": "run-s build test:*",
20+
"test:lint": "tslint --project . && prettier \"src/**/*.ts\" --list-different",
21+
"test:unit": "nyc --silent ava",
22+
"watch": "run-s clean build:main && run-p \"build:main -- -w\" \"test:unit -- --watch\"",
23+
"cov": "run-s build test:unit cov:html && open-cli coverage/index.html",
24+
"cov:html": "nyc report --reporter=html",
25+
"cov:send": "nyc report --reporter=lcov && codecov",
26+
"cov:check": "nyc report && nyc check-coverage --lines 100 --functions 100 --branches 100",
27+
"doc": "run-s doc:html && open-cli build/docs/index.html",
28+
"doc:html": "typedoc src/ --exclude **/*.spec.ts --target ES6 --mode file --out build/docs",
29+
"doc:json": "typedoc src/ --exclude **/*.spec.ts --target ES6 --mode file --json build/docs/typedoc.json",
30+
"doc:publish": "gh-pages -m \"[ci skip] Updates\" -d build/docs",
31+
"version": "standard-version",
32+
"reset": "git clean -dfx && git reset --hard && npm i",
33+
"clean": "trash build test",
34+
"prepare-release": "run-s reset test cov:check doc:html version doc:publish",
35+
"preinstall": "node -e \"if(process.env.npm_execpath.indexOf('yarn') === -1) throw new Error('@algo-js/segment-tree must be installed with Yarn: https://yarnpkg.com/')\""
36+
},
37+
"scripts-info": {
38+
"info": "Display information about the package scripts",
39+
"build": "Clean and rebuild the project",
40+
"fix": "Try to automatically fix any linting problems",
41+
"test": "Lint and unit test the project",
42+
"watch": "Watch and rebuild the project on save, then rerun relevant tests",
43+
"cov": "Rebuild, run tests, then create and open the coverage report",
44+
"doc": "Generate HTML API documentation and open it in a browser",
45+
"doc:json": "Generate API documentation in typedoc JSON format",
46+
"version": "Bump package.json version, update CHANGELOG.md, tag release",
47+
"reset": "Delete all untracked files and reset the repo to the last commit",
48+
"prepare-release": "One-step: clean, build, test, publish docs, and prep a release"
49+
},
50+
"engines": {
51+
"node": ">=8.9"
52+
},
53+
"dependencies": {
54+
"sha.js": "^2.4.11"
55+
},
56+
"devDependencies": {
57+
"ava": "2.2.0",
58+
"codecov": "^3.5.0",
59+
"cz-conventional-changelog": "^2.1.0",
60+
"gh-pages": "^2.0.1",
61+
"npm-run-all": "^4.1.5",
62+
"@bitjson/npm-scripts-info": "^1.0.0",
63+
"nyc": "^14.1.1",
64+
"prettier": "^1.18.2",
65+
"standard-version": "^6.0.1",
66+
"trash-cli": "^3.0.0",
67+
"tslint": "^5.18.0",
68+
"tslint-config-prettier": "^1.18.0",
69+
"tslint-immutable": "^6.0.1",
70+
"typescript": "^3.5.3"
71+
},
72+
"ava": {
73+
"failFast": true,
74+
"files": [
75+
"build/main/**/*.spec.js"
76+
],
77+
"sources": [
78+
"build/main/**/*.js"
79+
]
80+
},
81+
"config": {
82+
"commitizen": {
83+
"path": "cz-conventional-changelog"
84+
}
85+
},
86+
"prettier": {
87+
"singleQuote": true
88+
},
89+
"nyc": {
90+
"extends": "@istanbuljs/nyc-config-typescript",
91+
"exclude": [
92+
"**/*.spec.js"
93+
]
94+
}
95+
}

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from './lib/async';
2+
export * from './lib/hash';
3+
export * from './lib/number';

src/lib/async.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// tslint:disable:no-expression-statement
2+
import test from 'ava';
3+
import { asyncABC } from './async';
4+
5+
test('getABC', async t => {
6+
t.deepEqual(await asyncABC(), ['a', 'b', 'c']);
7+
});

src/lib/async.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* A sample async function (to demo Typescript's es7 async/await downleveling).
3+
*
4+
* ### Example (es imports)
5+
* ```js
6+
* import { asyncABC } from 'typescript-starter'
7+
* console.log(await asyncABC())
8+
* // => ['a','b','c']
9+
* ```
10+
*
11+
* ### Example (commonjs)
12+
* ```js
13+
* var double = require('typescript-starter').asyncABC;
14+
* asyncABC().then(console.log);
15+
* // => ['a','b','c']
16+
* ```
17+
*
18+
* @returns a Promise which should contain `['a','b','c']`
19+
*/
20+
export async function asyncABC(): Promise<ReadonlyArray<string>> {
21+
function somethingSlow(index: 0 | 1 | 2): Promise<string> {
22+
const storage = 'abc'.charAt(index);
23+
return new Promise<string>(resolve =>
24+
// later...
25+
resolve(storage)
26+
);
27+
}
28+
const a = await somethingSlow(0);
29+
const b = await somethingSlow(1);
30+
const c = await somethingSlow(2);
31+
return [a, b, c];
32+
}

src/lib/hash.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// tslint:disable:no-expression-statement no-object-mutation
2+
import test from 'ava';
3+
import { sha256, sha256Native } from './hash';
4+
5+
test(
6+
'sha256',
7+
(t, input: string, expected: string) => {
8+
t.is(sha256(input), expected);
9+
t.is(sha256Native(input), expected);
10+
},
11+
'test',
12+
'9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08'
13+
);

src/lib/hash.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { createHash } from 'crypto';
2+
import shaJs from 'sha.js';
3+
4+
/**
5+
* Calculate the sha256 digest of a string.
6+
*
7+
* ### Example (es imports)
8+
* ```js
9+
* import { sha256 } from 'typescript-starter'
10+
* sha256('test')
11+
* // => '9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08'
12+
* ```
13+
*
14+
* @returns sha256 message digest
15+
*/
16+
export function sha256(message: string): string {
17+
return shaJs('sha256')
18+
.update(message)
19+
.digest('hex');
20+
}
21+
22+
/**
23+
* A faster implementation of [[sha256]] which requires the native Node.js module. Browser consumers should use [[sha256]], instead.
24+
*
25+
* ### Example (es imports)
26+
* ```js
27+
* import { sha256Native as sha256 } from 'typescript-starter'
28+
* sha256('test')
29+
* // => '9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08'
30+
* ```
31+
*
32+
* @returns sha256 message digest
33+
*/
34+
export function sha256Native(message: string): string {
35+
return createHash('sha256')
36+
.update(message)
37+
.digest('hex');
38+
}

src/lib/number.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// tslint:disable:no-expression-statement
2+
import test from 'ava';
3+
import { double, power } from './number';
4+
5+
test('double', t => {
6+
t.is(double(2), 4);
7+
});
8+
9+
test('power', t => {
10+
t.is(power(2, 4), 16);
11+
});

src/lib/number.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* Multiplies a value by 2. (Also a full example of Typedoc's functionality.)
3+
*
4+
* ### Example (es module)
5+
* ```js
6+
* import { double } from 'typescript-starter'
7+
* console.log(double(4))
8+
* // => 8
9+
* ```
10+
*
11+
* ### Example (commonjs)
12+
* ```js
13+
* var double = require('typescript-starter').double;
14+
* console.log(double(4))
15+
* // => 8
16+
* ```
17+
*
18+
* @param value Comment describing the `value` parameter.
19+
* @returns Comment describing the return type.
20+
* @anotherNote Some other value.
21+
*/
22+
export function double(value: number): number {
23+
return value * 2;
24+
}
25+
26+
/**
27+
* Raise the value of the first parameter to the power of the second using the es7 `**` operator.
28+
*
29+
* ### Example (es module)
30+
* ```js
31+
* import { power } from 'typescript-starter'
32+
* console.log(power(2,3))
33+
* // => 8
34+
* ```
35+
*
36+
* ### Example (commonjs)
37+
* ```js
38+
* var power = require('typescript-starter').power;
39+
* console.log(power(2,3))
40+
* // => 8
41+
* ```
42+
*/
43+
export function power(base: number, exponent: number): number {
44+
// This is a proposed es7 operator, which should be transpiled by Typescript
45+
return base ** exponent;
46+
}

src/types/example.d.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* If you import a dependency which does not include its own type definitions,
3+
* TypeScript will try to find a definition for it by following the `typeRoots`
4+
* compiler option in tsconfig.json. For this project, we've configured it to
5+
* fall back to this folder if nothing is found in node_modules/@types.
6+
*
7+
* Often, you can install the DefinitelyTyped
8+
* (https://github.com/DefinitelyTyped/DefinitelyTyped) type definition for the
9+
* dependency in question. However, if no one has yet contributed definitions
10+
* for the package, you may want to declare your own. (If you're using the
11+
* `noImplicitAny` compiler options, you'll be required to declare it.)
12+
*
13+
* This is an example type definition for the `sha.js` package, used in hash.ts.
14+
*
15+
* (This definition was primarily extracted from:
16+
* https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/v8/index.d.ts
17+
*/
18+
declare module 'sha.js' {
19+
export default function shaJs(algorithm: string): Hash;
20+
21+
type Utf8AsciiLatin1Encoding = 'utf8' | 'ascii' | 'latin1';
22+
type HexBase64Latin1Encoding = 'latin1' | 'hex' | 'base64';
23+
24+
export interface Hash extends NodeJS.ReadWriteStream {
25+
// tslint:disable:no-method-signature
26+
update(
27+
data: string | Buffer | DataView,
28+
inputEncoding?: Utf8AsciiLatin1Encoding
29+
): Hash;
30+
digest(): Buffer;
31+
digest(encoding: HexBase64Latin1Encoding): string;
32+
// tslint:enable:no-method-signature
33+
}
34+
}

0 commit comments

Comments
 (0)