@stamp/named
Advanced tools
@@ -9,3 +9,3 @@ var compose = require('@stamp/compose'); | ||
| it('default name is "Stamp"', function () { | ||
| const S = compose(); | ||
| var S = compose(); | ||
| expect(S.name).toBe('Stamp'); | ||
@@ -15,3 +15,3 @@ }); | ||
| it('setName sets the name', function () { | ||
| const S = compose(Named).setName('foo'); | ||
| var S = compose(Named).setName('foo'); | ||
| expect(S.name).toBe('foo'); | ||
@@ -21,5 +21,11 @@ }); | ||
| it('setName overwrites existing name', function () { | ||
| const S = compose(Named).setName('foo'); | ||
| var S = compose(Named).setName('foo'); | ||
| expect(S.setName('bar').name).toBe('bar'); | ||
| }); | ||
| it('can be used as a standalone function', function () { | ||
| var setName = Named.setName; | ||
| var S = setName('foo'); | ||
| expect(S.name).toBe('foo'); | ||
| }); | ||
| }); |
+6
-2
| var compose = require('@stamp/compose'); | ||
| module.exports = compose({ | ||
| var Named = compose({ | ||
| staticProperties: { | ||
| setName: function (name) { | ||
| return this.compose({ | ||
| 'use strict'; | ||
| var Stamp = this && this.compose ? this : Named; | ||
| return Stamp.compose({ | ||
| staticPropertyDescriptors: { | ||
@@ -16,1 +18,3 @@ name: { | ||
| }); | ||
| module.exports = Named; |
+1
-1
| { | ||
| "name": "@stamp/named", | ||
| "version": "1.0.0", | ||
| "version": "1.0.1", | ||
| "description": "(Re)Name a stamp factory function", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
+10
-0
@@ -22,2 +22,12 @@ # @stamp/named | ||
| const MyNamedStamp = MyRegularStamp.compose(Named).setName('MyNamedStamp'); | ||
| ``` | ||
| Or if you don't want to import the stamp you can import only the method: | ||
| ```js | ||
| import {setName} from '@stamp/named'; | ||
| const MyNamedStamp = MyRegularStamp.compose(setName('MyNamedStamp')); | ||
| ``` | ||
| Then stamp receives a different name instead of the default "Stamp": | ||
| ```js | ||
| console.log(MyNamedStamp.name); // 'MyNamedStamp' | ||
@@ -24,0 +34,0 @@ ``` |
2979
21.2%41
24.24%45
28.57%