@bscotch/utility
Advanced tools
Comparing version 0.13.0 to 0.14.0
@@ -0,2 +1,5 @@ | ||
export declare class BscotchUtilError extends Error { | ||
constructor(message: string); | ||
} | ||
export declare function assert(claim: any, message: string): asserts claim; | ||
//# sourceMappingURL=errors.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.assert = void 0; | ||
exports.assert = exports.BscotchUtilError = void 0; | ||
class BscotchUtilError extends Error { | ||
constructor(message) { | ||
super(message); | ||
this.name = "BscotchUtilError"; | ||
this.name = 'BscotchUtilError'; | ||
Error.captureStackTrace(this, this.constructor); | ||
} | ||
} | ||
exports.BscotchUtilError = BscotchUtilError; | ||
function assert(claim, message) { | ||
@@ -12,0 +13,0 @@ if (!claim) { |
@@ -29,3 +29,5 @@ export interface ListPathOptions { | ||
*/ | ||
export declare function removeEmptyDirsSync(startDir: string): void; | ||
export declare function removeEmptyDirsSync(startDir: string, options?: { | ||
excludeRoot?: boolean; | ||
}): void; | ||
export declare const files: { | ||
@@ -32,0 +34,0 @@ listFilesByExtensionSync: typeof listFilesByExtensionSync; |
@@ -75,4 +75,7 @@ "use strict"; | ||
*/ | ||
function removeEmptyDirsSync(startDir) { | ||
const folders = [startDir, ...listFoldersSync(startDir, true)]; | ||
function removeEmptyDirsSync(startDir, options) { | ||
const folders = listFoldersSync(startDir, true); | ||
if (!(options === null || options === void 0 ? void 0 : options.excludeRoot)) { | ||
folders.unshift(startDir); | ||
} | ||
folders.reverse(); | ||
@@ -79,0 +82,0 @@ for (const folder of folders) { |
@@ -0,1 +1,2 @@ | ||
/// <reference types="node" /> | ||
/** | ||
@@ -14,7 +15,35 @@ * Shift all lines left by the *smallest* indentation level, | ||
export declare function oneline(strings: TemplateStringsArray, ...interps: any[]): string; | ||
export declare function encodeToBase64(content: string | Buffer): string; | ||
export declare function decodeFromBase64(base64: string): string; | ||
export declare function decodeFromBase64JsonString(string: string): any; | ||
export declare function encodeToBase64JsonString(something: any): string; | ||
export declare function capitalize(string: string): string; | ||
/** | ||
* Explode a string using a separator. | ||
*/ | ||
export declare function explode(string?: string, options?: { | ||
/** Only return first `limit` results (returns all by default) */ | ||
limit?: number | null; | ||
/** Separator to explode on */ | ||
sep?: string | RegExp; | ||
/** Nullstrings are skipped unless this is set to `true` */ | ||
keepEmpty?: boolean; | ||
/** If `true`, only unique values returned (order not guaranteed) */ | ||
unique?: boolean; | ||
/** By default the original string and all values are trimmed. | ||
* Set to `true` to prevent this behavior. | ||
*/ | ||
noTrim?: boolean; | ||
}): string[]; | ||
export declare const strings: { | ||
capitalize: typeof capitalize; | ||
decodeFromBase64: typeof decodeFromBase64; | ||
decodeFromBase64JsonString: typeof decodeFromBase64JsonString; | ||
encodeToBase64: typeof encodeToBase64; | ||
encodeToBase64JsonString: typeof encodeToBase64JsonString; | ||
explode: typeof explode; | ||
nodent: typeof nodent; | ||
oneline: typeof oneline; | ||
undent: typeof undent; | ||
oneline: typeof oneline; | ||
nodent: typeof nodent; | ||
}; | ||
//# sourceMappingURL=strings.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.strings = exports.oneline = exports.nodent = exports.undent = void 0; | ||
exports.strings = exports.explode = exports.capitalize = exports.encodeToBase64JsonString = exports.decodeFromBase64JsonString = exports.decodeFromBase64 = exports.encodeToBase64 = exports.oneline = exports.nodent = exports.undent = void 0; | ||
const errors_1 = require("./errors"); | ||
function populateTemplate(strings, ...interps) { | ||
@@ -56,7 +57,60 @@ let string = ''; | ||
exports.oneline = oneline; | ||
function encodeToBase64(content) { | ||
return (Buffer.isBuffer(content) ? content : Buffer.from(content)).toString('base64'); | ||
} | ||
exports.encodeToBase64 = encodeToBase64; | ||
function decodeFromBase64(base64) { | ||
return Buffer.from(base64, 'base64').toString(); | ||
} | ||
exports.decodeFromBase64 = decodeFromBase64; | ||
function decodeFromBase64JsonString(string) { | ||
try { | ||
return JSON.parse(decodeFromBase64(string)); | ||
} | ||
catch { | ||
throw new errors_1.BscotchUtilError('Object is not JSON parseable'); | ||
} | ||
} | ||
exports.decodeFromBase64JsonString = decodeFromBase64JsonString; | ||
function encodeToBase64JsonString(something) { | ||
try { | ||
return encodeToBase64(JSON.stringify(something)); | ||
} | ||
catch { | ||
throw new errors_1.BscotchUtilError('Object is not JSON stringifiable'); | ||
} | ||
} | ||
exports.encodeToBase64JsonString = encodeToBase64JsonString; | ||
function capitalize(string) { | ||
return `${string}`.charAt(0).toLocaleUpperCase() + `${string}`.slice(1); | ||
} | ||
exports.capitalize = capitalize; | ||
/** | ||
* Explode a string using a separator. | ||
*/ | ||
function explode(string, options) { | ||
options || (options = {}); | ||
options.sep = typeof options.sep == 'undefined' ? /\s*,\s*/ : options.sep; | ||
if (!string || typeof string != 'string' || options.limit === 0) { | ||
return []; | ||
} | ||
let entries = string[(options === null || options === void 0 ? void 0 : options.noTrim) ? 'toString' : 'trim']() | ||
.split(options.sep) | ||
.map((entry) => ((options === null || options === void 0 ? void 0 : options.noTrim) ? entry : entry.trim())) | ||
.filter((entry) => entry || (options === null || options === void 0 ? void 0 : options.keepEmpty)); | ||
entries = entries.slice(0, options.limit || entries.length); | ||
return options.unique ? [...new Set(entries)] : entries; | ||
} | ||
exports.explode = explode; | ||
exports.strings = { | ||
capitalize, | ||
decodeFromBase64, | ||
decodeFromBase64JsonString, | ||
encodeToBase64, | ||
encodeToBase64JsonString, | ||
explode, | ||
nodent, | ||
oneline, | ||
undent, | ||
oneline, | ||
nodent, | ||
}; | ||
//# sourceMappingURL=strings.js.map |
@@ -6,2 +6,3 @@ /** Get a promise that resolves in some number of milliseconds. */ | ||
export declare function resolveInNextTick(): Promise<unknown>; | ||
export declare function wait(millis: number): Promise<unknown>; | ||
export declare const waits: { | ||
@@ -8,0 +9,0 @@ resolveInMillis: typeof resolveInMillis; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.waits = exports.resolveInNextTick = exports.resolveInSeconds = exports.resolveInMillis = void 0; | ||
exports.waits = exports.wait = exports.resolveInNextTick = exports.resolveInSeconds = exports.resolveInMillis = void 0; | ||
/** Get a promise that resolves in some number of milliseconds. */ | ||
@@ -18,2 +18,6 @@ function resolveInMillis(millis) { | ||
exports.resolveInNextTick = resolveInNextTick; | ||
function wait(millis) { | ||
return resolveInMillis(millis); | ||
} | ||
exports.wait = wait; | ||
exports.waits = { | ||
@@ -20,0 +24,0 @@ resolveInMillis, |
@@ -0,1 +1,13 @@ | ||
# [0.14.0](https://github.com/bscotch/node-util/compare/v0.13.0...v0.14.0) (2021-02-26) | ||
### Features | ||
* Add an option to the removeEmptyDirsSync function to exclude the root directory. ([73a6671](https://github.com/bscotch/node-util/commit/73a6671850ae8008a022eb7033fb27aee73ab1a0)) | ||
* Add capitalize function. ([e8cba5e](https://github.com/bscotch/node-util/commit/e8cba5e37ebe3f0e744bd46f8e620cca8ad61fe1)) | ||
* Add explode string function. ([a379dd5](https://github.com/bscotch/node-util/commit/a379dd55fd5160c6ebf8d0a6948047d02ba84e2e)) | ||
* Add string functions related to converting strings and objects back and forth, including via Base64-encoded string intermediates. ([a051091](https://github.com/bscotch/node-util/commit/a0510911a7ab1b2b2551f5843d03c9f59a3383fa)) | ||
# [0.13.0](https://github.com/bscotch/node-util/compare/v0.12.0...v0.13.0) (2021-02-26) | ||
@@ -2,0 +14,0 @@ |
{ | ||
"name": "@bscotch/utility", | ||
"version": "0.13.0", | ||
"version": "0.14.0", | ||
"description": "Bscotch Utilities: Methods for common Node.js needs.", | ||
@@ -15,3 +15,3 @@ "engines": { | ||
"scripts": { | ||
"test": "mocha --inspect --require source-map-support/register --bail ./build/test/index.js", | ||
"test": "mocha --inspect --require source-map-support/register --bail ./build/test/", | ||
"build": "rm -rf build && npx tsc", | ||
@@ -18,0 +18,0 @@ "preversion": "git checkout develop && npm run build && npm test", |
@@ -58,5 +58,11 @@ # Bscotch Utilities | ||
import { | ||
capitalize, | ||
decodeFromBase64, | ||
encodeToBase64, | ||
decodeFromBase64JsonString, | ||
encodeToBase64JsonString, | ||
explode, | ||
nodent, | ||
oneline, | ||
undent, | ||
oneline, | ||
nodent, | ||
} from '@bscotch/utility'; | ||
@@ -142,3 +148,3 @@ | ||
## Files | ||
### Files | ||
@@ -164,3 +170,3 @@ ```ts | ||
## Waits | ||
### Waits | ||
@@ -184,3 +190,3 @@ ```ts | ||
## Objects | ||
### Objects | ||
@@ -232,3 +238,3 @@ ```ts | ||
## Crypto | ||
### Crypto | ||
@@ -254,3 +260,3 @@ ```ts | ||
## Dates | ||
### Dates | ||
@@ -273,3 +279,3 @@ ```ts | ||
## Arrays | ||
### Arrays | ||
@@ -293,2 +299,2 @@ ```ts | ||
selfOrFirstItem(["hello","goodbye"]); // => "hello" | ||
``` | ||
```git |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
81949
1003
292