@tellescope/utilities 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintrc.js ADDED
@@ -0,0 +1,25 @@
1
+ module.exports = {
2
+ "env": {
3
+ "browser": true,
4
+ "es6": true,
5
+ "node": true
6
+ },
7
+ "extends": [
8
+ "eslint:recommended",
9
+ "plugin:@typescript-eslint/eslint-recommended"
10
+ ],
11
+ "globals": {
12
+ "Atomics": "readonly",
13
+ "SharedArrayBuffer": "readonly"
14
+ },
15
+ "parser": "@typescript-eslint/parser",
16
+ "parserOptions": {
17
+ "ecmaVersion": 2018,
18
+ "sourceType": "module"
19
+ },
20
+ "plugins": [
21
+ "@typescript-eslint"
22
+ ],
23
+ "rules": {
24
+ }
25
+ };
package/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2021 Immuto, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 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.
@@ -0,0 +1,10 @@
1
+ import "@tellescope/types";
2
+ import { ObjectId } from "mongodb";
3
+ export declare const first_letter_capitalized: (s?: string) => string;
4
+ export declare const first_letter_lowercase: (s?: string) => string;
5
+ export declare const object_is_empty: (o: object) => boolean;
6
+ export declare const is_object: (obj: any) => obj is Indexable<any>;
7
+ export declare const matching_fields: (fields: string[], o1: Indexable, o2: Indexable) => Indexable<any>;
8
+ export declare const is_whitespace: (s?: string) => boolean;
9
+ export declare const url_safe_path: (p?: string) => string;
10
+ export declare const to_object_id: (s?: string) => ObjectId;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.to_object_id = exports.url_safe_path = exports.is_whitespace = exports.matching_fields = exports.is_object = exports.object_is_empty = exports.first_letter_lowercase = exports.first_letter_capitalized = void 0;
4
+ require("@tellescope/types");
5
+ var mongodb_1 = require("mongodb");
6
+ var first_letter_capitalized = function (s) {
7
+ if (s === void 0) { s = ''; }
8
+ return s.charAt(0).toUpperCase() + s.slice(1);
9
+ };
10
+ exports.first_letter_capitalized = first_letter_capitalized;
11
+ var first_letter_lowercase = function (s) {
12
+ if (s === void 0) { s = ''; }
13
+ return s.charAt(0).toUpperCase() + s.slice(1);
14
+ };
15
+ exports.first_letter_lowercase = first_letter_lowercase;
16
+ var object_is_empty = function (o) { return Object.keys(o).length === 0 && o.constructor === Object; };
17
+ exports.object_is_empty = object_is_empty;
18
+ var is_object = function (obj) { return typeof obj === "object" && obj !== null; };
19
+ exports.is_object = is_object;
20
+ // fields that are defined and match by equality
21
+ var matching_fields = function (fields, o1, o2) {
22
+ var matches = {};
23
+ for (var _i = 0, fields_1 = fields; _i < fields_1.length; _i++) {
24
+ var k = fields_1[_i];
25
+ if (o1[k] && o1[k] === o2[k]) { // may need deeper equality check for objects
26
+ matches[k] = o1[k];
27
+ }
28
+ }
29
+ return matches;
30
+ };
31
+ exports.matching_fields = matching_fields;
32
+ var WHITE_SPACE_EXP = /^\s*$/;
33
+ var is_whitespace = function (s) {
34
+ if (s === void 0) { s = ''; }
35
+ return WHITE_SPACE_EXP.test(s);
36
+ };
37
+ exports.is_whitespace = is_whitespace;
38
+ var url_safe_path = function (p) {
39
+ if (p === void 0) { p = ''; }
40
+ return p.replace(/_/g, '-');
41
+ };
42
+ exports.url_safe_path = url_safe_path;
43
+ var to_object_id = function (s) {
44
+ if (s === void 0) { s = ''; }
45
+ return new mongodb_1.ObjectId(s);
46
+ };
47
+ exports.to_object_id = to_object_id;
48
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;AAAA,6BAA0B;AAC1B,mCAAkC;AAE3B,IAAM,wBAAwB,GAAG,UAAC,CAAI;IAAJ,kBAAA,EAAA,MAAI;IAAK,OAAA,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;AAAtC,CAAsC,CAAA;AAA3E,QAAA,wBAAwB,4BAAmD;AACjF,IAAM,sBAAsB,GAAG,UAAC,CAAI;IAAJ,kBAAA,EAAA,MAAI;IAAK,OAAA,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;AAAtC,CAAsC,CAAA;AAAzE,QAAA,sBAAsB,0BAAmD;AAE/E,IAAM,eAAe,GAAG,UAAC,CAAU,IAAK,OAAA,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC,WAAW,KAAK,MAAM,EAAvD,CAAuD,CAAA;AAAzF,QAAA,eAAe,mBAA0E;AAC/F,IAAM,SAAS,GAAG,UAAC,GAAQ,IAAuB,OAAA,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAvC,CAAuC,CAAA;AAAnF,QAAA,SAAS,aAA0E;AAEhG,gDAAgD;AACzC,IAAM,eAAe,GAAG,UAAC,MAAgB,EAAE,EAAa,EAAE,EAAa;IAC5E,IAAM,OAAO,GAAG,EAAe,CAAA;IAC/B,KAAgB,UAAM,EAAN,iBAAM,EAAN,oBAAM,EAAN,IAAM,EAAE;QAAnB,IAAM,CAAC,eAAA;QACV,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,6CAA6C;YAC3E,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAA;SACnB;KACF;IACD,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AARY,QAAA,eAAe,mBAQ3B;AAED,IAAM,eAAe,GAAG,OAAO,CAAA;AACxB,IAAM,aAAa,GAAG,UAAC,CAAI;IAAJ,kBAAA,EAAA,MAAI;IAAK,OAAA,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC;AAAvB,CAAuB,CAAA;AAAjD,QAAA,aAAa,iBAAoC;AAEvD,IAAM,aAAa,GAAG,UAAC,CAAI;IAAJ,kBAAA,EAAA,MAAI;IAAK,OAAA,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC;AAApB,CAAoB,CAAA;AAA9C,QAAA,aAAa,iBAAiC;AAEpD,IAAM,YAAY,GAAG,UAAC,CAAI;IAAJ,kBAAA,EAAA,MAAI;IAAK,OAAA,IAAI,kBAAQ,CAAC,CAAC,CAAC;AAAf,CAAe,CAAA;AAAxC,QAAA,YAAY,gBAA4B"}
@@ -0,0 +1,10 @@
1
+ import "@tellescope/types";
2
+ import { ObjectId } from "mongodb";
3
+ export declare const first_letter_capitalized: (s?: string) => string;
4
+ export declare const first_letter_lowercase: (s?: string) => string;
5
+ export declare const object_is_empty: (o: object) => boolean;
6
+ export declare const is_object: (obj: any) => obj is Indexable<any>;
7
+ export declare const matching_fields: (fields: string[], o1: Indexable, o2: Indexable) => Indexable<any>;
8
+ export declare const is_whitespace: (s?: string) => boolean;
9
+ export declare const url_safe_path: (p?: string) => string;
10
+ export declare const to_object_id: (s?: string) => ObjectId;
@@ -0,0 +1,37 @@
1
+ import "@tellescope/types";
2
+ import { ObjectId } from "mongodb";
3
+ export var first_letter_capitalized = function (s) {
4
+ if (s === void 0) { s = ''; }
5
+ return s.charAt(0).toUpperCase() + s.slice(1);
6
+ };
7
+ export var first_letter_lowercase = function (s) {
8
+ if (s === void 0) { s = ''; }
9
+ return s.charAt(0).toUpperCase() + s.slice(1);
10
+ };
11
+ export var object_is_empty = function (o) { return Object.keys(o).length === 0 && o.constructor === Object; };
12
+ export var is_object = function (obj) { return typeof obj === "object" && obj !== null; };
13
+ // fields that are defined and match by equality
14
+ export var matching_fields = function (fields, o1, o2) {
15
+ var matches = {};
16
+ for (var _i = 0, fields_1 = fields; _i < fields_1.length; _i++) {
17
+ var k = fields_1[_i];
18
+ if (o1[k] && o1[k] === o2[k]) { // may need deeper equality check for objects
19
+ matches[k] = o1[k];
20
+ }
21
+ }
22
+ return matches;
23
+ };
24
+ var WHITE_SPACE_EXP = /^\s*$/;
25
+ export var is_whitespace = function (s) {
26
+ if (s === void 0) { s = ''; }
27
+ return WHITE_SPACE_EXP.test(s);
28
+ };
29
+ export var url_safe_path = function (p) {
30
+ if (p === void 0) { p = ''; }
31
+ return p.replace(/_/g, '-');
32
+ };
33
+ export var to_object_id = function (s) {
34
+ if (s === void 0) { s = ''; }
35
+ return new ObjectId(s);
36
+ };
37
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,mBAAmB,CAAA;AAC1B,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAElC,MAAM,CAAC,IAAM,wBAAwB,GAAG,UAAC,CAAI;IAAJ,kBAAA,EAAA,MAAI;IAAK,OAAA,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,KAAK,CA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IAAJ,kBAAA,EAAA,MAAI;IAAK,OAAA,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC;AAApB,CAAoB,CAAA;AAE3D,MAAM,CAAC,IAAM,YAAY,GAAG,UAAC,CAAI;IAAJ,kBAAA,EAAA,MAAI;IAAK,OAAA,IAAI,QAAQ,CAAC,CAAC,CAAC;AAAf,CAAe,CAAA"}
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@tellescope/utilities",
3
+ "version": "0.0.2",
4
+ "description": "Shared JS code for common actions across API and browser",
5
+ "main": "./lib/cjs/utils.js",
6
+ "module": "./lib/esm/utils.js",
7
+ "types": "./lib/esm/utils.d.ts",
8
+ "scripts": {
9
+ "test": "echo \"Error: no test specified\" && exit 1",
10
+ "build": "npm run-script build:esm && npm run-script build:cjs",
11
+ "build:esm": "tsc",
12
+ "build:cjs": "tsc --module commonjs --outDir lib/cjs",
13
+ "watch": "nodemon --ignore lib --ext ts --exec npm run-script build"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/tellescope-os/tellescope.git"
18
+ },
19
+ "author": "Sebastian Coates",
20
+ "license": "MIT",
21
+ "bugs": {
22
+ "url": "https://github.com/tellescope-os/tellescope/issues"
23
+ },
24
+ "homepage": "https://github.com/tellescope-os/tellescope#readme",
25
+ "dependencies": {
26
+ "@tellescope/types": "^0.0.2",
27
+ "mongodb": "^4.1.2"
28
+ },
29
+ "devDependencies": {
30
+ "@typescript-eslint/eslint-plugin": "^4.33.0",
31
+ "@typescript-eslint/parser": "^4.33.0",
32
+ "eslint": "^7.32.0",
33
+ "nodemon": "^2.0.13",
34
+ "typescript": "^4.4.3"
35
+ },
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "gitHead": "337d86bfe4092222289f2af7825af09b6b57ad46"
40
+ }
package/src/utils.ts ADDED
@@ -0,0 +1,26 @@
1
+ import "@tellescope/types"
2
+ import { ObjectId } from "mongodb"
3
+
4
+ export const first_letter_capitalized = (s='') => s.charAt(0).toUpperCase() + s.slice(1)
5
+ export const first_letter_lowercase = (s='') => s.charAt(0).toUpperCase() + s.slice(1)
6
+
7
+ export const object_is_empty = (o : object) => Object.keys(o).length === 0 && o.constructor === Object
8
+ export const is_object = (obj: any): obj is Indexable => typeof obj === "object" && obj !== null
9
+
10
+ // fields that are defined and match by equality
11
+ export const matching_fields = (fields: string[], o1: Indexable, o2: Indexable) => {
12
+ const matches = {} as Indexable
13
+ for (const k of fields) {
14
+ if (o1[k] && o1[k] === o2[k]) { // may need deeper equality check for objects
15
+ matches[k] = o1[k]
16
+ }
17
+ }
18
+ return matches
19
+ }
20
+
21
+ const WHITE_SPACE_EXP = /^\s*$/
22
+ export const is_whitespace = (s='') => WHITE_SPACE_EXP.test(s)
23
+
24
+ export const url_safe_path = (p='') => p.replace(/_/g, '-')
25
+
26
+ export const to_object_id = (s='') => new ObjectId(s)
package/tsconfig.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "compilerOptions": {
3
+ "outDir": "lib/esm",
4
+ "module": "esnext",
5
+ "esModuleInterop": true,
6
+ "target": "es5",
7
+ "declaration": true,
8
+ "moduleResolution": "node",
9
+ "sourceMap": true,
10
+ "noImplicitAny": true,
11
+ "lib": ["es6", "dom", "es2016", "es2017"],
12
+ "jsx": "react",
13
+ "strict": true
14
+ },
15
+ "exclude": ["node_modules", "lib"],
16
+ "include": ["src"]
17
+ }