Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@zodash/format

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zodash/format - npm Package Compare versions

Comparing version 1.2.12 to 1.3.0

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

# [1.3.0](https://github.com/zcorky/zodash/compare/@zodash/format@1.2.12...@zodash/format@1.3.0) (2022-05-28)
### Features
* **format:** support default value and builtin url template (/users/:id/xxx) ([3982d99](https://github.com/zcorky/zodash/commit/3982d99ba86ec9bf20ac341301186954708db34a))
## [1.2.12](https://github.com/zcorky/zodash/compare/@zodash/format@1.2.11...@zodash/format@1.2.12) (2022-01-13)

@@ -8,0 +19,0 @@

7

lib/format.d.ts

@@ -5,2 +5,6 @@ export interface Seperator {

}
export interface FormatOptions {
seperator?: Seperator;
default?: string;
}
/**

@@ -17,2 +21,3 @@ * Format string

*/
export declare function format(text: string, mapOrFn: Record<string, any> | ((key: string, text: string) => any), seperator?: Seperator): string;
export declare function format(text: string, mapOrFn: Record<string, any> | ((key: string, text: string) => any), options?: FormatOptions): string;
export declare function formatUrl(urlTemplate: string, mapOrFn: Record<string, any> | ((key: string, text: string) => any)): string;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.format = void 0;
exports.formatUrl = exports.format = void 0;
const get_1 = require("@zodash/get");

@@ -20,3 +20,10 @@ const DEFAULT_SEPERATOR = {

*/
function format(text, mapOrFn, seperator = DEFAULT_SEPERATOR) {
function format(text, mapOrFn, options) {
var _a;
const seperator = (_a = options === null || options === void 0 ? void 0 : options.seperator) !== null && _a !== void 0 ? _a : DEFAULT_SEPERATOR;
const defaultValue = (options === null || options === void 0 ? void 0 : options.default) || '';
// /users/:id/profile
if (text.indexOf('/:') != -1) {
return formatUrl(text, mapOrFn);
}
const seperatorStart = seperator.start;

@@ -28,4 +35,11 @@ const SeperatorEnd = seperator.end;

}
return text.replace(pattern, (_, key) => get_1.get(mapOrFn, key, ''));
return text.replace(pattern, (_, key) => get_1.get(mapOrFn, key, defaultValue));
}
exports.format = format;
function formatUrl(urlTemplate, mapOrFn) {
if (typeof mapOrFn === 'function') {
return urlTemplate.replace(/:([^/]+)/g, (_, key) => mapOrFn(key, urlTemplate));
}
return urlTemplate.replace(/:([^/]+)/g, (_, key) => get_1.get(mapOrFn, key));
}
exports.formatUrl = formatUrl;

4

package.json
{
"name": "@zodash/format",
"version": "1.2.12",
"version": "1.3.0",
"description": "format string with object values",

@@ -69,3 +69,3 @@ "keywords": [

},
"gitHead": "8506a4be416c68bf066e94234fb1367010a0d716",
"gitHead": "2925ad7fa89bbc2de85c0c0a58964a6cbaa1507c",
"devDependencies": {

@@ -72,0 +72,0 @@ "@zodash/get": "^1.1.3"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc